mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 12:59:46 +00:00
Update examples to make them easier to run
This commit is contained in:
@@ -1,18 +1,28 @@
|
||||
#!/usr/bin/env python3
|
||||
# A simple script to print all updates received
|
||||
#
|
||||
# NOTE: To run this script you MUST have 'TG_API_ID' and 'TG_API_HASH' in
|
||||
# your environment variables. This is a good way to use these private
|
||||
# values. See https://superuser.com/q/284342.
|
||||
from os import environ
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
from telethon import TelegramClient
|
||||
|
||||
|
||||
def get_env(name, message, cast=str):
|
||||
if name in os.environ:
|
||||
return os.environ[name]
|
||||
while True:
|
||||
value = input(message)
|
||||
try:
|
||||
return cast(value)
|
||||
except ValueError as e:
|
||||
print(e, file=sys.stderr)
|
||||
time.sleep(1)
|
||||
|
||||
|
||||
client = TelegramClient(
|
||||
environ.get('TG_SESSION', 'session'),
|
||||
environ['TG_API_ID'],
|
||||
environ['TG_API_HASH'],
|
||||
os.environ.get('TG_SESSION', 'printer'),
|
||||
get_env('TG_API_ID', 'Enter your API ID: ', int),
|
||||
get_env('TG_API_HASH', 'Enter your API hash: '),
|
||||
proxy=None
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user