Skip to content

Commit

Permalink
Add format and linting process to keep the code cleaner
Browse files Browse the repository at this point in the history
  • Loading branch information
humrochagf committed Nov 5, 2020
1 parent e08c68d commit 6435149
Show file tree
Hide file tree
Showing 7 changed files with 603 additions and 266 deletions.
4 changes: 4 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[settings]
include_trailing_comma = True
known_third_party = i18n
multi_line_output = 3
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,30 @@ cp kindle.conf_sample kindle.conf
```
python3 pdftokindlebot.py
```

# Contribute

To contribute install the development dependencies.

```
# pip3 install -r requirements.txt
```

Or use Pipenv to install.

```
# pip3 install pipenv
# pipenv install -r requirements.txt
```

Before sending your pull request, make sure you ran the linter.

```
# make lint
```

And the auto format.

```
# make format
```
16 changes: 9 additions & 7 deletions create_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@
import logging.handlers
import sqlite3

if __name__ == '__main__':
if __name__ == "__main__":
config = configparser.ConfigParser()
config.sections()
BOT_CONFIG_FILE = 'kindle.conf'
BOT_CONFIG_FILE = "kindle.conf"
config.read(BOT_CONFIG_FILE)
log_file = config['DEFAULT']['logfile']
db = config['SQLITE3']['data_base']
log_file = config["DEFAULT"]["logfile"]
db = config["SQLITE3"]["data_base"]

LOG_INFO_FILE = log_file
logger_info = logging.getLogger('InfoLogger')
logger_info = logging.getLogger("InfoLogger")
logger_info.setLevel(logging.DEBUG)
handler_info = logging.handlers.RotatingFileHandler(LOG_INFO_FILE,maxBytes=10240,backupCount=5,encoding='utf-8')
handler_info = logging.handlers.RotatingFileHandler(
LOG_INFO_FILE, maxBytes=10240, backupCount=5, encoding="utf-8"
)
logger_info.addHandler(handler_info)

conn = sqlite3.connect(db)
conn.close()

logger_info.info(str(datetime.datetime.now()) + ' Banco de dados criado')
logger_info.info(str(datetime.datetime.now()) + " Banco de dados criado")
36 changes: 16 additions & 20 deletions create_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,29 @@
import logging.handlers
import sqlite3

if __name__ == '__main__':
if __name__ == "__main__":
config = configparser.ConfigParser()
config.sections()
BOT_CONFIG_FILE = 'kindle.conf'
BOT_CONFIG_FILE = "kindle.conf"
config.read(BOT_CONFIG_FILE)
log_file = config['DEFAULT']['logfile']
db = config['SQLITE3']['data_base']
table = config['SQLITE3']['table']
log_file = config["DEFAULT"]["logfile"]
db = config["SQLITE3"]["data_base"]
table = config["SQLITE3"]["table"]

LOG_INFO_FILE = log_file
logger_info = logging.getLogger('InfoLogger')
logger_info = logging.getLogger("InfoLogger")
logger_info.setLevel(logging.DEBUG)
handler_info = logging.handlers.RotatingFileHandler(LOG_INFO_FILE,maxBytes=10240,backupCount=5,encoding='utf-8')
handler_info = logging.handlers.RotatingFileHandler(
LOG_INFO_FILE, maxBytes=10240, backupCount=5, encoding="utf-8"
)
logger_info.addHandler(handler_info)

conn = sqlite3.connect(db)

cursor = conn.cursor()

aux = ('''CREATE TABLE {} (
aux = (
"""CREATE TABLE {} (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
chatid TEXT NOT NULL,
remetente TEXT,
Expand All @@ -32,29 +35,22 @@
usado DATE,
idioma TEXT,
arquivo TEXT);
''').format(table)
"""
).format(table)

aux2 = ('''SELECT * FROM "{}"''').format(table)
# print(aux)

try:
cursor.execute(aux)
logger_info.info(str(datetime.datetime.now()) + ' Tabela usuarios criada')
logger_info.info(
str(datetime.datetime.now()) + " Tabela usuarios criada"
)
except:
cursor.execute(aux2)
usuarios = cursor.fetchall()
for user in usuarios:
print(user)
pass

# aux = ('''INSERT INTO {} (chatid, remetente, destinatario, criacao, usado)
# VALUES ('9083328', 'remetente@gabrf.com', 'destinatario@gabrf.com',
# '{}', '{}')''').format(table,
# str(datetime.datetime.now()), str(datetime.datetime.now()))

# cursor.execute(aux)

conn.commit()

conn.close()

26 changes: 26 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.PHONY: install
install: # system-wide standard python installation
pip install -r requirements.txt

.PHONY: install.hack
install.hack: # install development requirements
pip install -r requirements.dev.txt

.PHONY: lint
lint: # lint code
flake8 .

.PHONY: format
format:
isort .
black -l 79 .

.PHONY: clean
clean: # remove temporary files and artifacts
rm -rf site/
rm -rf *.egg-info dist build
find . -name '*.pyc' -exec rm -f {} +
find . -name '*.pyo' -exec rm -f {} +
find . -name '*~' -exec rm -f {} +
find . -name '.coverage' -exec rm -f {} +
find . -name '__pycache__' -exec rmdir {} +
Loading

0 comments on commit 6435149

Please sign in to comment.