Skip to content

Commit dafe980

Browse files
committed
Fixed dependencies & more checking
1 parent 9a04455 commit dafe980

4 files changed

Lines changed: 21 additions & 10 deletions

File tree

datapath.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
logging.basicConfig(
1616
format="%(asctime)s - %(levelname)s - %(message)s", level=logging.INFO
1717
)
18+
logging.basicConfig(
19+
format="%(asctime)s - %(levelname)s - %(message)s", level=logging.WARNING
20+
)
1821
logging.basicConfig(
1922
format="%(asctime)s - %(levelname)s - %(message)s", level=logging.ERROR
2023
)
@@ -48,12 +51,15 @@ def send_news_to_telegram(message):
4851
if __name__ == "__main__":
4952
data_from_db = news_db.create_connection(news_db.DB_FILE)
5053
while True:
51-
time.sleep(1)
52-
current_time = datetime.now().strftime("%H:%M")
53-
if TIME_TO_SEND_START < current_time < TIME_TO_SEND_END:
54-
logging.info(f"Time: {current_time}. Time to send has come !")
55-
for news in news_db.send_all_news(data_from_db):
56-
send_news_to_telegram(news)
57-
time.sleep(300)
54+
if data_from_db:
55+
time.sleep(1)
56+
current_time = datetime.now().strftime("%H:%M")
57+
if TIME_TO_SEND_START < current_time < TIME_TO_SEND_END:
58+
logging.info(f"Time: {current_time}. Time to send has come !")
59+
for news in news_db.send_all_news(data_from_db):
60+
send_news_to_telegram(news)
61+
time.sleep(300)
62+
else:
63+
logging.info(f"Time: {current_time}. Still waiting to send.")
5864
else:
59-
logging.info(f"Time: {current_time}. Still waiting to send.")
65+
logging.warning("Looks like database is empty.")

news_db.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
TIME_TO_PURGE = "00:00"
1111

12-
DB_FILE = Path(f"/mnt/{dynaconfig.settings['DB_NAME']}")
12+
DB_FILE = Path(f"{dynaconfig.settings['DB_NAME']}")
1313

1414
# SQL queries
1515
CREATE_TABLE_SQL = """

requirements-dp.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
newsapi-python
12
requests~=2.28.1
23
dynaconf~=3.1.11
34
dynaconfig~=0.4

requirements.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
black
2-
isort
2+
isort
3+
newsapi-python
4+
requests~=2.28.1
5+
dynaconf~=3.1.11
6+
dynaconfig~=0.4

0 commit comments

Comments
 (0)