Skip to content

Commit

Permalink
load_mapping, load_mission: explicitly specify utf-8 to avoid gbk in
Browse files Browse the repository at this point in the history
windows environment.
  • Loading branch information
saitewasreset committed Aug 26, 2024
1 parent 46a545e commit 40cf759
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions script/load_mapping/load_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
print("Loading config.json...")

try:
with open("config.json", "r") as f:
with open("config.json", "r", encoding="utf-8") as f:
try:
config = json.load(f)
admin_endpoint = config["admin_endpoint"]
Expand All @@ -40,7 +40,7 @@ def load_mapping(mapping_name: str):
mapping = {}
print("Loading {}/{}.txt...".format(mapping_path, mapping_name))
try:
with open("{}/{}.txt".format(mapping_path, mapping_name), "r") as f:
with open("{}/{}.txt".format(mapping_path, mapping_name), "r", encoding="utf-8") as f:
for line in f.readlines():
line = line.strip()

Expand Down Expand Up @@ -75,7 +75,7 @@ def load_mapping(mapping_name: str):
load_mapping(mapping_name)

try:
with open("{}/entity_blacklist.txt".format(mapping_path), "r") as f:
with open("{}/entity_blacklist.txt".format(mapping_path), "r", encoding="utf-8") as f:
entity_blacklist = [x.strip() for x in f.read().splitlines()]
r = requests.post("{}/mapping/entity_blacklist".format(admin_endpoint), json=entity_blacklist)
try:
Expand All @@ -84,14 +84,14 @@ def load_mapping(mapping_name: str):
except json.JSONDecodeError as e:
print("Invalid response from server: ", e)
input("Press enter to exit...")
sys.sys.exit(1)
sys.exit(1)
except OSError as e:
print("Cannot open entity_blacklist.txt: ", e)
input("Press enter to exit...")
sys.exit(1)

print("Updating cache...")
r = requests.get("https://rocknstone.top/wearerich/mission_monitor/api/secret20231301_admin/update_essential")
r = requests.get("{}/update_essential".format(admin_endpoint))
try:
res = r.json()
if res["code"] != 200:
Expand Down
2 changes: 1 addition & 1 deletion script/load_mission/load_mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
print("Loading config.json...")

try:
with open("config.json", "r") as f:
with open("config.json", "r", encoding="utf-8") as f:
try:
config = json.load(f)
admin_endpoint = config["admin_endpoint"]
Expand Down

0 comments on commit 40cf759

Please sign in to comment.