-
Notifications
You must be signed in to change notification settings - Fork 0
/
push.py
153 lines (144 loc) · 5.88 KB
/
push.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
import requests
import json
import os
def update_banner():
url = os.getenv("POST_ENDPOINT")
if url is None:
raise AttributeError("POST_ENDPOINT is not set.")
with open("banner-data.json", "r", encoding="utf-8") as f:
data = json.loads(f.read())
for k, v in data.items():
print("Current ann_id: " + str(k))
print("Sample data: " + str(v["zh-cn"]))
version_input = input("Please enter [Version]: ")
order_input = input("Please enter [Order] (1,2,3): ")
type_input = input("Please enter [UIGF-Type] 301(1)/400(2)/302(w): ")
for lang, data in v.items():
match lang:
case "zh-cn":
locale = "CHS"
case "en-us":
locale = "EN"
case "zh-tw":
locale = "CHT"
case "ja":
locale = "JP"
case "ko":
locale = "KR"
case "es":
locale = "ES"
case "fr":
locale = "FR"
case "ru":
locale = "RU"
case "th":
locale = "TH"
case "vi":
locale = "VI"
case "de":
locale = "DE"
case "id":
locale = "ID"
case "pt":
locale = "PT"
case "it":
locale = "IT"
case "tr":
locale = "TR"
case __:
break
body = {
"version": version_input,
"locale": locale,
"order": int(order_input),
"type": int(type_input),
"name": data["banner_name"],
"banner": data["banner_image"]
}
print("Sending data: " + str(body))
result = requests.post(url, json=body)
print("Result: " + str(result.status_code) + "\n" + "=" * 20)
image_data = requests.get(data["banner_image"])
os.makedirs(os.path.dirname(data["banner_image"].replace('https://sdk.hoyoverse.com/', "")), exist_ok=True)
open(data["banner_image"].replace('https://sdk.hoyoverse.com/', ""), 'wb').write(image_data.content)
def create_banner(mode: str = "production"):
new_data = {}
with open("banner-data.json", "r", encoding="utf-8") as f:
data = json.loads(f.read())
for lang in list(item for item in list(data.values())[0].keys() if len(item) <= 5):
new_data[lang] = []
banner_list = list(data.values())
for banner in banner_list:
generic_metadata = {k: banner[k] for k in list(banner.keys()) if len(k) > 5}
for lang in [k for k in list(banner.keys()) if len(k) <= 5]:
this_post = generic_metadata.copy()
this_post = this_post | banner[lang]
this_post["Name"] = this_post.pop("banner_name")
this_post["Version"] = this_post.pop("version_number")
this_post["Order"] = this_post.pop("order_number")
this_post["Banner"] = this_post.pop("banner_image")
this_post["Banner2"] = this_post["Banner"].replace("sdk.hoyoverse.com", "jihulab.com/DGP-Studio"
"/CurrentBannerWatcher/-/raw/main")
this_post["From"] = this_post.pop("start_time").replace("/", "-").replace(" ", "T")
this_post["To"] = this_post.pop("end_time").replace("/", "-").replace(" ", "T")
this_post["Type"] = this_post.pop("UIGF_pool_type")
new_data[lang].append([this_post])
# Download Image
image_data = requests.get(this_post["Banner"])
os.makedirs(os.path.dirname(this_post["Banner"].replace('https://sdk.hoyoverse.com/', "")), exist_ok=True)
open(this_post["Banner"].replace('https://sdk.hoyoverse.com/', ""), 'wb').write(image_data.content)
# Start of Debug #
print(new_data)
with open("post-data.json", "w", encoding="utf-8") as outfile:
json.dump(new_data, outfile, indent=2, ensure_ascii=False)
# END of Debug #
for lang in new_data.keys():
match lang:
case "zh-cn":
locale = "CHS"
case "en-us":
locale = "EN"
case "zh-tw":
locale = "CHT"
case "ja":
locale = "JP"
case "ko":
locale = "KR"
case "es":
locale = "ES"
case "fr":
locale = "FR"
case "ru":
locale = "RU"
case "th":
locale = "TH"
case "vi":
locale = "VI"
case "de":
locale = "DE"
case "id":
locale = "ID"
case "pt":
locale = "PT"
case "it":
locale = "IT"
case "tr":
locale = "TR"
case __:
break
for banner in new_data[lang]:
print("Sending data: " + str(banner))
if mode == "production":
url = os.getenv("CREATION_POST_ENDPOINT")
if url is None:
raise AttributeError("CREATION_POST_ENDPOINT env is not set.")
url = url.format(locale=locale)
print("URL: " + url)
return_result = requests.post(url, json=banner)
print("status_code: " + str(return_result.status_code))
print("content: " + json.loads(return_result.content.decode("utf-8"))["message"])
print("Full content: " + str(return_result.content.decode("utf-8")))
print("=" * 20)
if __name__ == "__main__":
create_banner(os.getenv("run_mode"))
# update_banner()