9
9
10
10
from Config import Config
11
11
from mats_counter import count_mats
12
+ from youtube_parser import *
12
13
13
14
conf = Config ('config.ini' , ['telegram_token' , 'destruction_timeout' , 'database_filename' ])
14
15
28
29
29
30
bot_id = None
30
31
last_top = None
32
+ url_video_list_dima = None
33
+ url_video_list_asado = None
31
34
32
35
#Todo:
33
36
#ignore karmaspam from users
@@ -242,6 +245,40 @@ def on_msg(update, context):
242
245
print (e )
243
246
244
247
248
+ def callback_minute (context : CallbackContext ):
249
+ global url_video_list_dima
250
+ global url_video_list_asado
251
+
252
+ new_video_list_dima = get_urls ('https://www.youtube.com/feeds/videos.xml?channel_id=UC20M3T-H-Pv0FPOEfeQJtNQ' )
253
+ new_video_list_asado = get_urls ('https://www.youtube.com/feeds/videos.xml?channel_id=UCfkPlh5dfjbw8hc1s-yJQdw' )
254
+
255
+ # get new url list
256
+ if url_video_list_dima is None :
257
+ url_video_list_dima = new_video_list_dima
258
+ return
259
+
260
+ if url_video_list_asado is None :
261
+ url_video_list_asado = new_video_list_asado
262
+ return
263
+
264
+
265
+ # look for new videos
266
+ new_videos_dima = get_new_urls (url_video_list_dima , new_video_list_dima )
267
+ new_videos_asado = get_new_urls (url_video_list_asado , new_video_list_asado )
268
+
269
+ if len (new_videos_dima ) > 0 :
270
+ url_video_list_dima = new_video_list_dima
271
+
272
+ for new_video in new_videos_dima :
273
+ context .bot .send_message (chat_id = '@rude_chat' , text = new_video )
274
+
275
+ if len (new_videos_asado ) > 0 :
276
+ url_video_list_asado = new_video_list_asado
277
+
278
+ for new_video in new_videos_asado :
279
+ context .bot .send_message (chat_id = '@rude_chat' , text = new_video )
280
+
281
+
245
282
def add_group (update , context ):
246
283
for member in update .message .new_chat_members :
247
284
if not member .is_bot :
@@ -265,6 +302,10 @@ def main():
265
302
dp .add_handler (CallbackQueryHandler (btn_clicked ))
266
303
dp .add_handler (MessageHandler (Filters .status_update .new_chat_members , add_group ))
267
304
305
+ # new videos
306
+ j = updater .job_queue
307
+ job_minute = j .run_repeating (callback_minute , interval = 60 , first = 0 )
308
+
268
309
updater .start_polling ()
269
310
bot_id = updater .bot .id
270
311
print ("Bot is started." )
0 commit comments