1
0
Fork 0
NewsGrabber/run.py

70 lines
2.2 KiB
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 21:49:16 +00:00
from sources.Engadget import Engadget
from sources.FinancialTimes import FinancialTimes
2020-01-18 20:05:17 +00:00
from sources.ForbesBusiness import ForbesBusiness
2020-01-18 22:44:43 +00:00
from sources.ForbesFinance import ForbesFinance
2020-01-18 20:05:17 +00:00
from sources.ForbesTechnology import ForbesTechnology
2020-01-18 21:20:48 +00:00
from sources.HuffingtonPostBusiness import HuffingtonPostBusiness
from sources.HuffingtonPostTechnology import HuffingtonPostTechnology
2020-01-18 21:49:16 +00:00
from sources.MacWorld import MacWorld
from sources.NYTBusiness import NYTBusiness
from sources.NYTTechnology import NYTTechnology
from sources.ReutersBusiness import ReutersBusiness
from sources.ReutersTechnology import ReutersTechnology
2020-01-18 22:30:26 +00:00
from sources.TheEconomistBusiness import TheEconomistBusiness
from sources.TheEconomistFinance import TheEconomistFinance
from sources.TheEconomistTechnology import TheEconomistTechnology
2020-01-18 21:49:16 +00:00
from sources.Wired import Wired
2020-01-18 15:34:40 +00:00
DATABASE_PATH = Path("storage.db")
2020-01-18 23:01:23 +00:00
GRAB_FREQUENCY = 60
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 21:49:16 +00:00
Engadget(db),
FinancialTimes(db),
2020-01-18 20:05:17 +00:00
ForbesBusiness(db),
2020-01-18 22:44:43 +00:00
ForbesFinance(db),
2020-01-18 20:05:17 +00:00
ForbesTechnology(db),
2020-01-18 21:20:48 +00:00
HuffingtonPostBusiness(db),
HuffingtonPostTechnology(db),
2020-01-18 21:49:16 +00:00
MacWorld(db),
NYTBusiness(db),
NYTTechnology(db),
ReutersBusiness(db),
ReutersTechnology(db),
2020-01-18 22:30:26 +00:00
TheEconomistBusiness(db),
TheEconomistFinance(db),
TheEconomistTechnology(db),
2020-01-18 21:49:16 +00:00
Wired(db),
2020-01-18 18:36:33 +00:00
]
2020-01-18 15:34:40 +00:00
2020-01-18 18:36:33 +00:00
while True:
for grabber in grabbers:
grabber.grab()
2020-01-18 23:01:23 +00:00
time.sleep(GRAB_FREQUENCY/len(grabbers))
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()