Update examples to make them easier to run

This commit is contained in:
Lonami Exo
2018-09-04 11:52:18 +02:00
parent 3c92f6a791
commit 0e38ab412b
9 changed files with 112 additions and 96 deletions

View File

@@ -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
)