-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
66 lines (45 loc) · 1.64 KB
/
Copy pathmain.py
File metadata and controls
66 lines (45 loc) · 1.64 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import logging
import time
from config import *
from data_scraping import web_scraper, xml_processing
from database import *
from datetime import datetime, timezone, timedelta
logging.basicConfig(level=logging.DEBUG)
def initialize():
check_database(db_name)
if download_past_data:
logging.info(f"Scraping past data from {download_start_date} to {download_end_date}")
web_scraper.download_period(download_start_date, download_end_date)
logging.info("Download of past data completed")
xml_processing.process_input_data()
def run_loop(max_iterations=None):
# Current date in utc timezone
date_utc = datetime.now(timezone.utc).date()
counter = 0
while True:
date_new = datetime.now(timezone.utc).date()
if date_new > date_utc:
logging.info("New day, clearing temp buffer")
print(len(xml_processing.inserted_files))
xml_processing.inserted_files.clear()
print(len(xml_processing.inserted_files))
date_utc = date_new
web_scraper.download_date(date_utc)
xml_processing.process_input_data()
counter += 1
if max_iterations and counter >= max_iterations:
break
time.sleep(600)
if __name__ == "__main__":
initialize()
run_loop()
# date_utc = datetime.now(timezone.utc).date() - timedelta(days=1)
# counter = 0
# counter += 1
#
# if counter > 5:
# # get the new date
# date_new = datetime.now(timezone.utc).date()
# else:
# date_new = date_utc
# if the date switched, clear the list of inserted files and update the date