Remove deprecated functions for log managing from Python example.

GitOrigin-RevId: 76ce3b9dbd5b8d9d4d8f92fd3ee158cc8c8d6d12
This commit is contained in:
levlam 2019-04-30 22:51:17 +03:00
parent 37c83bd39e
commit fca3eacf4b

View File

@ -38,18 +38,6 @@ td_json_client_destroy = tdjson.td_json_client_destroy
td_json_client_destroy.restype = None
td_json_client_destroy.argtypes = [c_void_p]
td_set_log_file_path = tdjson.td_set_log_file_path
td_set_log_file_path.restype = c_int
td_set_log_file_path.argtypes = [c_char_p]
td_set_log_max_file_size = tdjson.td_set_log_max_file_size
td_set_log_max_file_size.restype = None
td_set_log_max_file_size.argtypes = [c_longlong]
td_set_log_verbosity_level = tdjson.td_set_log_verbosity_level
td_set_log_verbosity_level.restype = None
td_set_log_verbosity_level.argtypes = [c_int]
fatal_error_callback_type = CFUNCTYPE(None, c_char_p)
td_set_log_fatal_error_callback = tdjson.td_set_log_fatal_error_callback
@ -60,10 +48,20 @@ td_set_log_fatal_error_callback.argtypes = [fatal_error_callback_type]
def on_fatal_error_callback(error_message):
print('TDLib fatal error: ', error_message)
td_set_log_verbosity_level(1)
def td_execute(query):
query = json.dumps(query).encode('utf-8')
result = td_json_client_execute(None, query)
if result:
result = json.loads(result.decode('utf-8'))
return result
c_on_fatal_error_callback = fatal_error_callback_type(on_fatal_error_callback)
td_set_log_fatal_error_callback(c_on_fatal_error_callback)
# setting TDLib log verbosity level to 1 (errors)
print(td_execute({'@type': 'setLogVerbosityLevel', 'new_verbosity_level': 1, '@extra': 1.01234}))
# create client
client = td_json_client_create()
@ -78,14 +76,7 @@ def td_receive():
result = json.loads(result.decode('utf-8'))
return result
def td_execute(query):
query = json.dumps(query).encode('utf-8')
result = td_json_client_execute(None, query)
if result:
result = json.loads(result.decode('utf-8'))
return result
# testing TDLib execute method
# another test for TDLib execute method
print(td_execute({'@type': 'getTextEntities', 'text': '@telegram /test_command https://telegram.org telegram.me', '@extra': ['5', 7.0]}))
# testing TDLib send method
@ -107,36 +98,36 @@ while True:
# you MUST obtain your own api_id and api_hash at https://my.telegram.org
# and use them in the setTdlibParameters call
if auth_state['@type'] == 'authorizationStateWaitTdlibParameters':
td_send({'@type':'setTdlibParameters', 'parameters':{
'database_directory':'tdlib',
'use_message_database':True,
'use_secret_chats':True,
'api_id':94575,
'api_hash':'a3406de8d171bb422bb6ddf3bbd800e2',
'system_language_code':'en',
'device_model':'Desktop',
'system_version':'Linux',
'application_version':'1.0',
'enable_storage_optimizer':True}})
td_send({'@type': 'setTdlibParameters', 'parameters': {
'database_directory': 'tdlib',
'use_message_database': True,
'use_secret_chats': True,
'api_id': 94575,
'api_hash': 'a3406de8d171bb422bb6ddf3bbd800e2',
'system_language_code': 'en',
'device_model': 'Desktop',
'system_version': 'Linux',
'application_version': '1.0',
'enable_storage_optimizer': True}})
# set an encryption key for database to let know tdlib how to open the database
if auth_state['@type'] == 'authorizationStateWaitEncryptionKey':
td_send({'@type':'checkDatabaseEncryptionKey', 'key':'my_key'})
td_send({'@type': 'checkDatabaseEncryptionKey', 'key': 'my_key'})
# insert phone number for login
if auth_state['@type'] == 'authorizationStateWaitPhoneNumber':
phone_number = input('Please insert your phone number: ')
td_send({'@type':'setAuthenticationPhoneNumber', 'phone_number':phone_number})
td_send({'@type': 'setAuthenticationPhoneNumber', 'phone_number': phone_number})
# wait for authorization code
if auth_state['@type'] == 'authorizationStateWaitCode':
code = input('Please insert the authentication code you received: ')
td_send({'@type':'checkAuthenticationCode', 'code':code})
td_send({'@type': 'checkAuthenticationCode', 'code': code})
# wait for password if present
if auth_state['@type'] == 'authorizationStateWaitPassword':
password = input('Please insert your password: ')
td_send({'@type':'checkAuthenticationPassword', 'password':password})
td_send({'@type': 'checkAuthenticationPassword', 'password': password})
# handle an incoming update or an answer to a previously sent request
print(event)