From d68783dddaae3efe8d0f8ac08a8710f065a22854 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Wed, 25 Oct 2023 07:41:47 -0700 Subject: [PATCH] Add script for updating news data on a daily basis --- news/Dockerfile | 7 +++++++ news/update_news.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 news/Dockerfile create mode 100644 news/update_news.py diff --git a/news/Dockerfile b/news/Dockerfile new file mode 100644 index 0000000..bb80840 --- /dev/null +++ b/news/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11 +COPY update_news.py . +COPY requirements.txt . +RUN pip install -r requirements.txt +RUN pip install --index-url https://dev.moshington.com/api/packages/moshferatu/pypi/simple/ database +RUN pip install --index-url https://dev.moshington.com/api/packages/moshferatu/pypi/simple/ news +CMD ["python", "./update_news.py"] \ No newline at end of file diff --git a/news/update_news.py b/news/update_news.py new file mode 100644 index 0000000..8675b30 --- /dev/null +++ b/news/update_news.py @@ -0,0 +1,16 @@ +import schedule +import time + +from database.news import insert +from datetime import date +from news import scrape_news + +def update_news_data(): + news_data = scrape_news(date.today()) + insert(news_data) + +if __name__ == '__main__': + schedule.every().day.at('02:00', 'America/Los_Angeles').do(update_news_data) + while True: + schedule.run_pending() + time.sleep(1) \ No newline at end of file