-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchecker_book.py
More file actions
40 lines (32 loc) · 1.4 KB
/
checker_book.py
File metadata and controls
40 lines (32 loc) · 1.4 KB
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
import time
import logger
from bots import bot
from databases.database import Database
from parsers import parser_manager
class CheckerBook:
@staticmethod
def check_book():
"""
This method checks book discounts every 36 minutes and removes books from which no one is subscribed.
If there is a discount, then it calls the method of notifying subscribers.
"""
parser = parser_manager.ParserManager()
bot_ = bot.Bot()
while True:
database = Database()
books = database.get_books()
database.delete_empty_subscriptions()
for book in books:
try:
book_detail = parser.parsing_book(book['link'])
if book_detail['price'] != book['price']:
database.change_price(book['link'], book_detail['price'])
if book_detail['price'] < book['price']:
sale = 100 - int(book_detail['price'] / book['price'] * 100)
for follower in book['followers']:
if database.check_service(follower):
bot_.send_notification(follower, book_detail, sale)
except AttributeError as ae:
logger.show_error(system="Book24", error=repr(ae))
database.__del__()
time.sleep(2200)