Пример #1
0
import requests

config = SafeConfigParser()
config.read(['botter_sample.ini',
             'botter.ini'])

global_config = 'global'
global_key_option = 'key'
global_state_option = 'statefile'

if config.has_option(global_config, global_key_option):
    key = config.get(global_config, global_key_option)
else:
    sys.exit("Need an API key")

config.base_url = 'https://api.telegram.org/bot{}/'.format(key)


def get_me(config):
    response = requests.get(config.base_url + 'getMe')
    if response.status_code == 200:
        print(response.text)
    else:
        sys.exit(response)


def get_and_reply(config):
    if config.has_option(global_config, global_state_option):
        statefile_filename = config.get(global_config, global_state_option)
    else:
        statefile_filename = 'state.json'