Add script for updating news data on a daily basis

This commit is contained in:
moshferatu 2023-10-25 07:41:47 -07:00
parent 3619a6ec0c
commit d68783ddda
2 changed files with 23 additions and 0 deletions

7
news/Dockerfile Normal file
View File

@ -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"]

16
news/update_news.py Normal file
View File

@ -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)