-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (33 loc) · 1.75 KB
/
Copy pathmain.py
File metadata and controls
47 lines (33 loc) · 1.75 KB
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
import logging
from os.path import exists
from time import sleep, strftime
from check_time import is_time_between
from init_config_variables import vars_init
from collect_games_data import matches_parse, check_internet_connection
from interact_database import table_init, table_update
def main():
logging.basicConfig(filename='D:\\Pets\\parser_with_timer\\logs\\main.log', level=logging.INFO, filemode='a')
while True:
if is_time_between([5, 00], [6, 00]) and check_internet_connection():
logging.info(strftime('%Y-%m-%d %H:%M:%S') + ' - Started collecting')
if exists('D:/Pets/parser_with_timer/configs/config.ini'):
# Initialise main variables
project_dir, date_for_parsing, formatted_date_for_parsing = \
vars_init(path=r'D:\Pets\parser_with_timer\configs\config.ini')
# Parse new matches data
matches = matches_parse(date_for_parsing)
logging.info(strftime('%Y-%m-%d %H:%M:%S') + ' - Collected new matches')
if not exists(project_dir + '/databases/' + formatted_date_for_parsing + '.db'):
# Initialise a matches table if not exists
table_init(project_dir, formatted_date_for_parsing)
# Update matches table with the matches
table_update(project_dir, formatted_date_for_parsing, matches)
logging.info(strftime('%Y-%m-%d %H:%M:%S') + ' - Updated a matches table')
logging.info(strftime('%Y-%m-%d %H:%M:%S') + ' - Took a break')
# Break for 20 hours
sleep(72000)
else:
# Break for 5 minutes
sleep(300)
if __name__ == '__main__':
main()