This repository has been archived by the owner on Sep 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
85 lines (63 loc) · 1.77 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import logging
import logging.handlers
import sqlite3
import pendulum
import yaml
LOGGER = logging.getLogger('pso2_news')
LOGGER.setLevel(logging.DEBUG)
FH = logging.handlers.RotatingFileHandler(
'news.log',
maxBytes=4096,
backupCount=5,
)
FH.setLevel(logging.DEBUG)
CH = logging.StreamHandler()
CH.setLevel(logging.INFO)
FH.setFormatter(
logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
)
CH.setFormatter(
logging.Formatter(
'%(levelname)s - %(message)s'
)
)
LOGGER.addHandler(FH)
LOGGER.addHandler(CH)
TODAY = pendulum.today()
NOW = pendulum.now()
DB = sqlite3.Connection('news.db')
CURSOR = DB.cursor()
SCHEMA = {
'UQ': '(DATE TEXT UNIQUE, NAME TEXT, TITLE TEXT, URL TEXT)'
}
for table, schema in SCHEMA.items():
CURSOR.execute('CREATE TABLE IF NOT EXISTS {0} {1}'.format(table, schema))
DB.commit()
CURSOR.execute('SELECT * FROM UQ')
RESULTS = sorted(CURSOR.fetchall(), reverse=True)
try:
with open('main.yaml', 'r') as f:
yaml.safe_load(f)['FIRST_RUN']
FIRST_RUN = False
except (FileNotFoundError, KeyError, TypeError):
FIRST_RUN = True
LOGGER.info(
'This is a first run. '
'A first run will make subtle changes to the year of UQs.'
)
with open('blacklist.yaml', 'r') as f:
BLACKLIST = yaml.safe_load(f)
try:
UQ_BLACKLIST = BLACKLIST['uq']
except (KeyError, TypeError):
UQ_BLACKLIST = []
LOGGER.warning('The blacklist is malformed. Please download a new copy.')
def write_main() -> None:
"""Write main configuration yaml.
Currently, main.yaml should only include a "FIRST_RUN" element.
"""
if FIRST_RUN:
with open('main.yaml', 'w') as f:
yaml.safe_dump({'FIRST_RUN': False})