-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_stuffimporter.py
More file actions
89 lines (78 loc) · 3.28 KB
/
_stuffimporter.py
File metadata and controls
89 lines (78 loc) · 3.28 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
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
import os
import random
class StuffImporter(object):
def __init__(self, s_cont, _, ngettext) -> None:
self.s_cont = s_cont
self._ = _
self.ngettext = ngettext
@staticmethod
def get_config() -> dict:
return {
"telegram_send_url": os.getenv("TELEGRAM_SEND_URL"),
"db": {
"url": os.getenv("DB_URL"),
"key": os.getenv("DB_KEY")
},
"google": {
"oauth_id": os.getenv("GOOGLE_OAUTH_ID"),
"oauth_secret": os.getenv("GOOGLE_OAUTH_SECRET"),
"discovery_url": os.getenv("GOOGLE_DISCOVERY_URL")
},
"twitter": {
"apiv1_key": os.getenv("TWITTER_APIV1_KEY"),
"apiv1_secret": os.getenv("TWITTER_APIV1_SECRET")
},
"facebook": {
"client_id": os.getenv("FACEBOOK_CLIENT_ID"),
"client_secret": os.getenv("FACEBOOK_CLIENT_SECRET")
},
"github": {
"client_id": os.getenv("GH_CLIENT_ID"),
"client_secret": os.getenv("GH_CLIENT_SECRET")
},
"discord": {
"client_id": os.getenv("DISCORD_CLIENT_ID"),
"client_secret": os.getenv("DISCORD_CLIENT_SECRET")
},
"twitch": {
"client_id": os.getenv("TWITCH_CLIENT_ID"),
"client_secret": os.getenv("TWITCH_CLIENT_SECRET")
},
"email_password": os.getenv("EMAIL_PASSWORD"),
"deepl_auth_key": os.getenv("DEEPL_AUTH_KEY")
}
def get_stats(self) -> dict:
return self.s_cont.read_item("stats.json", "stats.json")
def set_stats(self, stats: dict):
self.s_cont.replace_item("stats.json", stats)
def select_random_broadcaster(self, user_container, last_brod: str) -> str:
brods_query = user_container.query_items(f"SELECT u.id FROM Users u WHERE NOT IS_DEFINED(u.ban) AND u.id <> '{last_brod}'", enable_cross_partition_query=True)
brods = []
while True:
try:
brods.append(brods_query.next()["id"])
except StopIteration:
break
return random.choice(brods)
def seconds_to_str(self, seconds: float) -> str:
days = round(seconds // 86400)
hours = round((seconds % 86400) // 3600)
minutes = round(((seconds % 86400) % 3600) // 60)
rem_seconds = round(((seconds % 86400) % 3600) % 60)
result = []
if days:
result.append(self.ngettext("%(num)s day", "%(num)s days", days))
if days or hours:
result.append(self.ngettext("%(num)s hour", "%(num)s hours", hours))
if days or hours or minutes:
result.append(self.ngettext("%(num)s minute", "%(num)s minutes", minutes))
if days or hours or minutes or rem_seconds:
result.append(self.ngettext("%(num)s second", "%(num)s seconds", rem_seconds))
return ", ".join(result[:-1]) + " " + self._("and") + " " + result[-1] if len(result) > 1 else result[0]
def itempaged_to_list(self, itempaged) -> list:
result = []
while True:
try:
result.append(itempaged.next())
except StopIteration:
return result