forked from rodrigouroz/housing_scrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifier.py
More file actions
32 lines (26 loc) · 1018 Bytes
/
notifier.py
File metadata and controls
32 lines (26 loc) · 1018 Bytes
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
import telegram
import logging
import random
class NullNotifier:
def notify(self, properties):
pass
class Notifier(NullNotifier):
def __init__(self, config):
logging.info(f"Setting up bot with token {config['token']}")
self.config = config
self.bot = telegram.Bot(token=self.config['token'])
def notify(self, properties):
logging.info(f'Notifying about {len(properties)} properties')
text = random.choice(self.config['messages'])
self.bot.send_message(chat_id=self.config['chat_id'], text=text)
for prop in properties:
logging.info(f"Notifying about {prop['url']}")
self.bot.send_message(chat_id=self.config['chat_id'],
text=f"[{prop['title']}]({prop['url']})",
parse_mode=telegram.ParseMode.MARKDOWN)
@staticmethod
def get_instance(config):
if config['enabled']:
return Notifier(config)
else:
return NullNotifier()