def send_notify(message):
global last_time_send
global messages_count
global client
if client == None:
try:
client = TelegramClient('session_name', api_id, api_hash)
client.start()
except:
print('Got problem when connecting to Telegram server... \n%s' % traceback.format_exc())
return
try:
if int(time.time()) - last_time_send < 2:
time.sleep(1)
last_time_send = int(time.time())
client.send_message(TELEGRAM_PHONE, message)
messages_count += 1
except:
print('Cant send message: %s' % traceback.format_exc())
if __name__ == '__main__':
while True:
try:
send_notify('I\'m working! There is timestamp: {0!s}'.format(int(time.time())))
print('Message sent', datetime.datetime.now().strftime('%d/%m %H:%M'))
time.sleep(INTERVAL * 60)
except:
print('Got error when sending message... \n%s' % traceback.format_exc())
Here is output:
Collecting telethon-sync
Downloading https://files.pythonhosted.org/packages/7b/8a/40771ef61f6f85ad8f48c9a771b02cc823c42bc088f735529896d06ea69b/Telethon_sync-1.1.1-py3-none-any.whl (333kB)
100% |████████████████████████████████| 337kB 2.2MB/s
Requirement already satisfied: pyaes in c:\users\dmaxw\appdata\local\programs\python\python36-32\lib\site-packages (from telethon-sync) (1.6.1)
Requirement already satisfied: rsa in c:\users\dmaxw\appdata\local\programs\python\python36-32\lib\site-packages (from telethon-sync) (3.4.2)
Requirement already satisfied: pyasn1>=0.1.3 in c:\users\dmaxw\appdata\local\programs\python\python36-32\lib\site-packages (from rsa->telethon-sync) (0.4.2)
Installing collected packages: telethon-sync
Successfully installed telethon-sync-1.1.1
You are using pip version 19.0.2, however version 19.0.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
C:\Users\dmaxw\Dropbox\Bot Work\Uncompiled>telegram_test_1.py
Got problem when connecting to Telegram server...
Traceback (most recent call last):
File "C:\Users\dmaxw\Dropbox\Bot Work\Uncompiled\telegram_test_1.py", line 34, in reinit
client = TelegramClient('session_name', api_id, api_hash)
File "C:\Users\dmaxw\AppData\Local\Programs\Python\Python36-32\lib\site-packages\telethon\client\telegrambaseclient.py", line 170, in init
session = SQLiteSession(session)
File "C:\Users\dmaxw\AppData\Local\Programs\Python\Python36-32\lib\site-packages\telethon\sessions\sqlite.py", line 61, in init
self._dc_id, self._server_address, self.port, key, = tuple
ValueError: too many values to unpack (expected 4)
Message sent 11/04 10:19
This error of
telethon-sync v.1.1.1
Here is code:Here is output: