forked from sefakilic/goodreads
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfetchdata.py
47 lines (36 loc) · 1.46 KB
/
fetchdata.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
import configparser
from goodreads import client
from goodreads import collectdata
from datetime import datetime, timedelta
import logging
import logging.config
from pathlib import Path
import time
# Setting up logger, Logger properties are defined in logging.ini file
logging.config.fileConfig(f"{Path(__file__).parents[0]}/logging.ini")
logger = logging.getLogger(__name__)
# Reading configurations
config = configparser.ConfigParser()
config.read_file(open('config.cfg'))
def main():
logging.debug("Creating good reads client.")
grclient = client.GoodreadsClient(config['GOODREADKEYS']['KEY'], config['GOODREADKEYS']['SECRET'])
grcollector = collectdata.GoodreadsCollect(grclient, config['DATA_DIR_PATH']['PATH'])
end_after = int(config['TIMEPARAM']['END_TIME'])
wait_time = int(config['TIMEPARAM']['WAIT_TIME'])
logging.debug(f"Execution started at {datetime.now()}")
end_time = datetime.now() + timedelta(seconds=end_after)
logging.debug(f"Execution will end at : {end_time}")
while(datetime.now() < end_time):
logging.debug("Fetching data...........")
try:
grcollector.fetch_data()
except Exception as e:
logging.exception("Some exception occured : ", e)
continue
logging.debug(f"Waiting for {config['TIMEPARAM']['WAIT_TIME']} seconds")
time.sleep(wait_time)
logging.debug("Execution ended.")
if __name__ == "__main__":
main()
logging.debug("Exiting.")