mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-07-11 08:32:22 +03:00
Sort keys and use Mozilla agent on error generator, update file
This commit is contained in:
parent
700b4c3169
commit
7286f77008
|
@ -26,7 +26,9 @@ known_codes = {
|
||||||
|
|
||||||
def fetch_errors(output, url=URL):
|
def fetch_errors(output, url=URL):
|
||||||
print('Opening a connection to', url, '...')
|
print('Opening a connection to', url, '...')
|
||||||
r = urllib.request.urlopen(url)
|
r = urllib.request.urlopen(urllib.request.Request(
|
||||||
|
url, headers={'User-Agent' : 'Mozilla/5.0'}
|
||||||
|
))
|
||||||
print('Checking response...')
|
print('Checking response...')
|
||||||
data = json.loads(
|
data = json.loads(
|
||||||
r.read().decode(r.info().get_param('charset') or 'utf-8')
|
r.read().decode(r.info().get_param('charset') or 'utf-8')
|
||||||
|
@ -34,11 +36,11 @@ def fetch_errors(output, url=URL):
|
||||||
if data.get('ok'):
|
if data.get('ok'):
|
||||||
print('Response was okay, saving data')
|
print('Response was okay, saving data')
|
||||||
with open(output, 'w', encoding='utf-8') as f:
|
with open(output, 'w', encoding='utf-8') as f:
|
||||||
json.dump(data, f)
|
json.dump(data, f, sort_keys=True)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
print('The data received was not okay:')
|
print('The data received was not okay:')
|
||||||
print(json.dumps(data, indent=4))
|
print(json.dumps(data, indent=4, sort_keys=True))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -164,3 +166,11 @@ def generate_code(output, json_file, errors_desc):
|
||||||
for pattern, name in patterns:
|
for pattern, name in patterns:
|
||||||
f.write(' {}: {},\n'.format(repr(pattern), name))
|
f.write(' {}: {},\n'.format(repr(pattern), name))
|
||||||
f.write('}\n')
|
f.write('}\n')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
if input('generate (y/n)?: ').lower() == 'y':
|
||||||
|
generate_code('../telethon/errors/rpc_error_list.py',
|
||||||
|
'errors.json', 'error_descriptions')
|
||||||
|
elif input('fetch (y/n)?: ').lower() == 'y':
|
||||||
|
fetch_errors('errors.json')
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user