forked from kurokobo/game-update-notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
154 lines (129 loc) · 4.73 KB
/
app.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import logging
import os
import time
from datetime import datetime
from os.path import dirname, join
from dotenv import load_dotenv
from modules.steam import Steam
from modules.discord import Discord
from modules.epicgames import EpicGames
from modules.msstore import MSStore
from modules.gog import GOG
dotenv_path = join(dirname(__file__), ".env")
load_dotenv(dotenv_path)
log_format = "%(asctime)s %(filename)s:%(name)s:%(lineno)d [%(levelname)s] %(message)s"
logging.basicConfig(
level=logging.INFO,
format=log_format,
)
logger = logging.getLogger(__name__)
def main():
IGNORE_FIRST_NOTIFICATION = os.getenv("IGNORE_FIRST_NOTIFICATION").lower() == "true"
CHECK_INTERVAL_SEC = int(os.getenv("CHECK_INTERVAL_SEC"))
WATCH_STEAM = os.getenv("WATCH_STEAM").lower() == "true"
STEAM_APP_IDS = [
x.strip()
for x in os.getenv("STEAM_APP_IDS").strip('"').strip("'").split(",")
if not os.getenv("STEAM_APP_IDS") == ""
]
WATCH_MSSTORE = os.getenv("WATCH_MSSTORE").lower() == "true"
MSSTORE_APP_IDS = [
x.strip()
for x in os.getenv("MSSTORE_APP_IDS").strip('"').strip("'").split(",")
if not os.getenv("MSSTORE_APP_IDS") == ""
]
MSSTORE_MARKET = os.getenv("MSSTORE_MARKET")
WATCH_EPICGAMES = os.getenv("WATCH_EPICGAMES").lower() == "true"
EPICGAMES_APP_IDS = [
x.strip()
for x in os.getenv("EPICGAMES_APP_IDS").strip('"').strip("'").split(",")
if not os.getenv("EPICGAMES_APP_IDS") == ""
]
WATCH_GOG = os.getenv("WATCH_GOG").lower() == "true"
GOG_APP_IDS = [
x.strip()
for x in os.getenv("GOG_APP_IDS").strip('"').strip("'").split(",")
if not os.getenv("GOG_APP_IDS") == ""
]
DISCORD_WEBHOOK_URL = os.getenv("DISCORD_WEBHOOK_URL")
DISCORD_MENTION_ROLE_IDS = [
x.strip()
for x in os.getenv("DISCORD_MENTION_ROLE_IDS").strip('"').strip("'").split(",")
if not os.getenv("DISCORD_MENTION_ROLE_IDS") == ""
]
DISCORD_MENTION_USER_IDS = [
x.strip()
for x in os.getenv("DISCORD_MENTION_USER_IDS").strip('"').strip("'").split(",")
if not os.getenv("DISCORD_MENTION_USER_IDS") == ""
]
current_path = os.path.dirname(os.path.abspath(__file__))
os.chdir(current_path)
if WATCH_STEAM:
steam_notifier = Discord(
webhook_url=DISCORD_WEBHOOK_URL,
role_ids=DISCORD_MENTION_ROLE_IDS,
user_ids=DISCORD_MENTION_USER_IDS,
platform="Steam",
thumb_url=(
"https://github.com/kurokobo/game-update-notifier/raw/main/"
"assets/steam.png"
),
embed_color="1e90ff",
)
steam = Steam(STEAM_APP_IDS, steam_notifier, IGNORE_FIRST_NOTIFICATION)
if WATCH_MSSTORE:
msstore_notifier = Discord(
webhook_url=DISCORD_WEBHOOK_URL,
role_ids=DISCORD_MENTION_ROLE_IDS,
user_ids=DISCORD_MENTION_USER_IDS,
platform="Microsoft Store",
thumb_url=(
"https://github.com/kurokobo/game-update-notifier/raw/main/"
"assets/msstore.png"
),
embed_color="e6e6fa",
)
msstore = MSStore(
MSSTORE_APP_IDS, msstore_notifier, IGNORE_FIRST_NOTIFICATION, MSSTORE_MARKET
)
if WATCH_EPICGAMES:
epicgames_notifier = Discord(
webhook_url=DISCORD_WEBHOOK_URL,
role_ids=DISCORD_MENTION_ROLE_IDS,
user_ids=DISCORD_MENTION_USER_IDS,
platform="Epic Games",
thumb_url=(
"https://github.com/kurokobo/game-update-notifier/raw/main/"
"assets/epicgames.png"
),
embed_color="11cf59",
)
epicgames = EpicGames(
EPICGAMES_APP_IDS, epicgames_notifier, IGNORE_FIRST_NOTIFICATION
)
if WATCH_GOG:
gog_notifier = Discord(
webhook_url=DISCORD_WEBHOOK_URL,
role_ids=DISCORD_MENTION_ROLE_IDS,
user_ids=DISCORD_MENTION_USER_IDS,
platform="GOG",
thumb_url=(
"https://github.com/kurokobo/game-update-notifier/raw/main/assets/gog.png"
),
embed_color="c62ee8",
)
gog = GOG(GOG_APP_IDS, gog_notifier, IGNORE_FIRST_NOTIFICATION)
while True:
logger.info("Loop start: {}".format(datetime.now()))
if WATCH_STEAM:
steam.check_update()
if WATCH_MSSTORE:
msstore.check_update()
if WATCH_EPICGAMES:
epicgames.check_update()
if WATCH_GOG:
gog.check_update()
logger.info("Will sleep {} seconds".format(CHECK_INTERVAL_SEC))
time.sleep(CHECK_INTERVAL_SEC)
if __name__ == "__main__":
main()