1
0
Fork 0
NewsGrabber/run.py

39 lines
931 B
Python
Raw Normal View History

2020-01-18 15:34:40 +00:00
import logging
import sqlite3
2020-01-18 18:36:33 +00:00
import time
2020-01-18 15:34:40 +00:00
from pathlib import Path
from sources.ArsTechnica import ArsTechnica
from sources.BBCBusiness import BBCBusiness
2020-01-18 18:36:33 +00:00
from sources.BBCTechnology import BBCTechnology
2020-01-18 15:34:40 +00:00
DATABASE_PATH = Path("storage.db")
2020-01-18 18:36:33 +00:00
GRAB_FREQUENCY = 15
GRAB_INTERVAL = 5
2020-01-18 15:34:40 +00:00
2020-01-18 18:36:33 +00:00
def main():
try:
db = sqlite3.connect(DATABASE_PATH)
if not db:
raise sqlite3.DatabaseError
2020-01-18 15:34:40 +00:00
2020-01-18 18:36:33 +00:00
grabbers = [
ArsTechnica(db),
BBCBusiness(db),
BBCTechnology(db),
]
2020-01-18 15:34:40 +00:00
2020-01-18 18:36:33 +00:00
while True:
for grabber in grabbers:
grabber.grab()
time.sleep(GRAB_FREQUENCY/GRAB_INTERVAL)
2020-01-18 15:34:40 +00:00
2020-01-18 18:36:33 +00:00
except sqlite3.Error:
logging.error("Could not connect to database.")
exit(-1)
2020-01-18 15:34:40 +00:00
if __name__ == "__main__":
2020-01-18 18:36:33 +00:00
logging.basicConfig(level=logging.INFO,format="%(asctime)s %(levelname)-8s %(message)s",datefmt="%Y-%m-%d %H:%M:%S")
2020-01-18 15:34:40 +00:00
main()