-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
74 lines (54 loc) · 2.59 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from threading import Thread
import logging
import time
from telegram_bot import TelegramBot, send_message
from decouple import config as getenv
from gecko import Gecko
from scraper import get_earn_offers
import requests
def start_alert():
logging.basicConfig(level=logging.INFO)
gecko = Gecko()
initial_earn_offers = get_earn_offers()
counter = 0
seconds_in_day = 24 * 60 * 60
iterations_until_refresh = seconds_in_day / int(getenv('TIME_INTERVAL'))
while True:
try:
old_notifications = dict(gecko.notifications)
gecko.check_price_action()
# reset after 24h = after iterations_until_refresh
counter += 1
if counter % iterations_until_refresh == 0:
logging.info(f'Notifications refreshed after: {counter} iterations')
gecko.notifications = {}
# check if the cb earn offers changed
if counter % 6 == 0:
difference = set(get_earn_offers()) - set(initial_earn_offers)
if difference:
initial_earn_offers = get_earn_offers()
logging.info("New coinbase earn offer available")
send_message("New coinbase earn offer available!\n" + ", ".join(difference) )
logging.info(f"Iteration: {counter} with {gecko.notifications}")
# only if there is a new notification added
if any(x not in old_notifications for x in gecko.notifications):
notifications_sorted = sorted(gecko.notifications.values(), key=lambda tupl: tupl[2], reverse=True)
message = "New abnormal price actions! 🥳\n\n"
message += "Price Alerts 🚨 \n\n"
for entry in notifications_sorted:
color = "🟢" if entry[2] > 0 else "🔴"
message += color + " {0[0]} is at {0[1]}€ with a {0[2]}% change in 24h."\
.format(entry) + '\n\n'
# add assets that are trending right now
message += gecko.get_trending_assets()
# uncomment for sending email notifications
# send_email("New abnormal price actions! 📈 🥳", message)
send_message(message)
except requests.exceptions.Timeout:
logging.error("Timeout occured")
except requests.exceptions.ConnectionError:
logging.error("Connection Error occured")
time.sleep(int(getenv('TIME_INTERVAL')))
alert_thread = Thread(target=start_alert)
alert_thread.start()
TelegramBot()