def testGetBad(self): import config_manager config = config_manager.load() try: config.get("editor_encoding_BLAH"); except config_manager.InvalidKeyException: pass else: fail("InvalidKeyException not raised for invalid key")
def start(): global bot global commands global authorized config = config_manager.load() token = config.get('telegram', 'token', fallback=None) authorized = config.getint('telegram', 'user', fallback=None) host = config.get('lighter', 'host', fallback=None) port = config.get('lighter', 'port', fallback=None) cert_path = config.get('lighter', 'cert', fallback=None) macaroon_path = config.get('lighter', 'macaroon', fallback=None) commands = Commands(host, port, cert_path, macaroon_path) while not token: print('Talk with the BotFather on Telegram ' '(https://telegram.me/BotFather), ' 'create a bot and insert the token') token = input('> ') config['telegram']['token'] = token config_manager.save(config) bot = telepot.Bot(token) # answerer = telepot.helper.Answerer(bot) MessageLoop(bot, {'chat': on_chat_message}).run_as_thread() print('Listening ...') while not authorized: print('Please add your bot on Telegram, ' 'than copy here the numeric code') try: code = int(input('> ')) except ValueError: continue if int(code) == challenge[1]: # User paired msg = [ '\U0001f308 Congratulations \U0001f308', 'Your bot is now ready for use \u26a1\ufe0f' ] print('Congratulations') authorized = challenge[0] # chat_id config['telegram']['user'] = str(authorized) config_manager.save(config) bot.sendMessage(authorized, '\n'.join(msg)) # Keep the program running. while 1: time.sleep(10)
import csv import getopt import os import re import sys import urllib from tempfile import NamedTemporaryFile import config_manager import client as mwclient verbose = False config = config_manager.load() class Usage(Exception): def __init__(self, msg): self.msg = msg class Query(object): """ Query class Initialized with a query, options, and a site. If no options are given, defaults to HTML If no site is given, reads from config file Has only a single execute method which executes the query and reformats the results in some way """ global verbose def __init__(self, query, opts=None, site=None): if not site: print >> sys.stderr, "Connecting as %s to http://%s%s" % (config.get("username"), config.get("site"), config.get("path")) self.site = mwclient.Site(config.get("site"), path=config.get("path"))
def testImport(self): import config_manager config = config_manager.load()
def testGet(self): import config_manager config = config_manager.load() config.get("editor_encoding");