-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathupdates.py
executable file
·47 lines (34 loc) · 1.27 KB
/
updates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import db
from parserr.parserr import get_ads_list, get_new_ads
from main import bot
import time
def send_updates():
sce = db.get_search_collection_entries()
for i in sce:
tracking_urls = []
for url in i['tracking_urls']:
old_ads = url['ads']
actual_ads = get_ads_list(url['url'])
new_ads = get_new_ads(actual_ads, old_ads)
for n_a in new_ads:
msg = n_a['title'].rstrip() + '\n' + n_a['price'].rstrip() + \
'\n' + n_a['url']
# if n_a['img']:
# from utils import get_img_file_by_url
#
# img_file = get_img_file_by_url(n_a['img'])
# if img_file:
# bot.send_photo(i['uid'], img_file)
bot.send_message(i['uid'], msg)
url['ads'] = actual_ads
tracking_urls.append(url)
import random
time.sleep(random.randint(1, 15) / 10)
db.set_actual_ads(i['uid'], tracking_urls)
if __name__ == '__main__':
import schedule
send_updates()
schedule.every(2).minutes.do(send_updates)
while True:
schedule.run_pending()
time.sleep(1)