|
4 | 4 | Author: Elysia |
5 | 5 | ''' |
6 | 6 | import locale |
7 | | -import json |
| 7 | +import xml.etree.ElementTree as ET |
8 | 8 | import os |
9 | 9 | import tools.base |
10 | 10 | from tools.base import CmdTask |
@@ -77,21 +77,21 @@ def isCN(self) -> bool: |
77 | 77 |
|
78 | 78 | def getLocalFromIP(self) -> str: |
79 | 79 | local_str = "" |
80 | | - temp_file = "/tmp/fishros_check_country.json" |
| 80 | + temp_file = "/tmp/fishros_check_country.xml" |
81 | 81 | try: |
82 | 82 | # Add timeout for IP detection |
83 | | - result = subprocess.run(["wget", "--header=Accept: application/json", "--no-check-certificate", |
| 83 | + result = subprocess.run(["wget", "--header=Accept: application/xml", "--no-check-certificate", |
84 | 84 | "https://ip.renfei.net/", "-O", temp_file, "-qq", "--timeout=10"], |
85 | 85 | capture_output=True, text=True, timeout=15) |
86 | 86 | if result.returncode == 0: |
87 | | - with open(temp_file, 'r') as json_file: |
88 | | - data = json.loads(json_file.read()) |
89 | | - self.ip_info = data |
90 | | - self.country = data['location']['countryCode'] |
91 | | - if data['location']['countryCode'] in COUNTRY_CODE_MAPPING: |
92 | | - local_str = COUNTRY_CODE_MAPPING[data['location']['countryCode']] |
93 | | - else: |
94 | | - local_str = "en_US" |
| 87 | + with open(temp_file, 'r') as xml_file: |
| 88 | + self.ip_info = xml_file.read() |
| 89 | + root = ET.fromstring(self.ip_info) |
| 90 | + self.country = root.find('location/countryCode').text |
| 91 | + if self.country in COUNTRY_CODE_MAPPING: |
| 92 | + local_str = COUNTRY_CODE_MAPPING[self.country] |
| 93 | + else: |
| 94 | + local_str = "en_US" |
95 | 95 | else: |
96 | 96 | local_str = "en_US" |
97 | 97 | except Exception: |
|
0 commit comments