File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77import dynaconfig
88import news_db
99
10- current_time = datetime .now ().strftime ("%H:%M" )
1110# Time range for sending messages
1211TIME_TO_SEND_START = datetime .now ().replace (hour = 10 , minute = 00 ).strftime ("%H:%M" )
1312TIME_TO_SEND_END = datetime .now ().replace (hour = 20 , minute = 00 ).strftime ("%H:%M" )
@@ -42,10 +41,13 @@ def send_news_to_telegram(message):
4241
4342
4443if __name__ == "__main__" :
44+ data_from_db = news_db .create_connection (news_db .DB_FILE )
4545 while True :
46+ current_time = datetime .now ().strftime ("%H:%M" )
4647 if TIME_TO_SEND_START < current_time < TIME_TO_SEND_END :
47- for news in news_db .send_all_news (
48- news_db .create_connection (news_db .DB_FILE )
49- ):
50- time .sleep (300 )
48+ logging .info (f"Time: { current_time } . Time to send has come !" )
49+ for news in news_db .send_all_news (data_from_db ):
5150 send_news_to_telegram (news )
51+ time .sleep (300 )
52+ else :
53+ logging .info (f"Time: { current_time } . Still waiting to send." )
Original file line number Diff line number Diff line change 11import logging
22import sqlite3
3+ import time
34from datetime import datetime
45from pathlib import Path
56from sqlite3 import Error
67
7- now = datetime .now ()
8-
9- CURRENT_TIME = now .strftime ("%H:%M" )
108TIME_TO_PURGE = "00:00"
119
1210
@@ -120,10 +118,14 @@ def delete_all_news(conn):
120118 create_table (conn , CREATE_TABLE_SQL )
121119
122120 while True :
121+ time .sleep (1 )
122+ CURRENT_TIME = datetime .now ().strftime ("%H:%M" )
123123 if conn is not None :
124124 send_all_news (conn )
125125 if CURRENT_TIME == TIME_TO_PURGE :
126- logging .info (" Time to purge has come !" )
126+ logging .info (f"Time: { CURRENT_TIME } . Time to purge has come !" )
127127 delete_all_news (conn )
128+ else :
129+ logging .info (f"Time: { CURRENT_TIME } . Still waiting for purging." )
128130 else :
129131 logging .error ("Error! Cannot create the database connection." )
Original file line number Diff line number Diff line change 11import logging
2+ import time
23from datetime import date , datetime , timedelta
34
45from newsapi import NewsApiClient
1415
1516newsapi = NewsApiClient (api_key = API_KEY )
1617
17- now = datetime .now ()
18-
19- CURRENT_TIME = now .strftime ("%H:%M" )
20- TIME_TO_SEARCH = "01:00"
18+ TIME_TO_SEARCH = "14:10"
2119
2220
2321# Logging
@@ -71,10 +69,14 @@ def load_to_db(fetch_info: dict):
7169
7270if __name__ == "__main__" :
7371 while True :
72+ time .sleep (1 )
73+ CURRENT_TIME = datetime .now ().strftime ("%H:%M" )
7474 # Pull too much info
7575 if CURRENT_TIME == TIME_TO_SEARCH :
76- logging .info (" Time to search has come !" )
76+ logging .info (f"Time: { CURRENT_TIME } . Time to search has come !" )
7777 try :
7878 load_to_db (fetch_info ())
7979 except BaseException as base_err :
8080 logging .error (base_err )
81+ else :
82+ logging .info (f"Time: { CURRENT_TIME } . Still waiting for searching." )
You can’t perform that action at this time.
0 commit comments