if not args.fastforward: args.fastforward = 1 if not args.timeout: args.timeout = 0 if args.action == 'truncate': q = '''SELECT * FROM tweets_origins LIMIT 1;''' elif not args.period: q = '''SELECT * FROM tweets_origins;''' elif args.period == "hour": q = '''SELECT * FROM tweets_origins WHERE tstamp >= '2015-06-22 19:00:00' AND tstamp <= '2015-06-23 20:00:00';''' elif args.period == "day": q = '''SELECT * FROM tweets_origins WHERE tstamp >= '2015-06-22 00:00:00' AND tstamp <= '2015-06-23 00:00:00';''' elif args.period == "week": q = '''SELECT * FROM tweets_origins WHERE tstamp >= '2015-06-29 00:00:00' AND tstamp <= '2015-07-06 00:00:00';''' elif args.period == "month": q = '''SELECT * FROM tweets_origins WHERE tstamp >= '2015-06-21 00:00:00' AND tstamp <= '2015-07-18 00:00:00';''' if args.action: from settings import REDIS_HOST, REDIS_PORT, REDIS_DB from redis import StrictRedis from utilities import get_mysql_con redis_db = StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB) mysql_db = get_mysql_con() dataset = exec_mysql(q, mysql_db)[0] if args.action == 'run': emulator = CollectorEmulator(mysql_db, redis_db, dataset=dataset, fast_forward_ratio=args.fastforward, start_timeout=args.timeout, run_on_init = True, truncate_on_init = False) elif args.action == 'runclean': emulator = CollectorEmulator(mysql_db, redis_db, dataset=dataset, fast_forward_ratio=args.fastforward, start_timeout=args.timeout, run_on_init = True, truncate_on_init = True) elif args.action == 'truncate': emulator = CollectorEmulator(mysql_db, redis_db, dataset=dataset, fast_forward_ratio=args.fastforward, start_timeout=args.timeout, run_on_init = False, truncate_on_init = True)
'unknown.command':"""Strange answer...""", 'ok':"""Ok!""", 'no.context':"""What we were talking about?""", 'contact.new':"""You sent me a contact. If you want to add this user to a privileged group, specify it, or press "Cancel".""", 'contact.added':u"""Added {} to group {}""", } updater = Updater(token=TELEGRAM_BOT_TOKEN) dispatcher = updater.dispatcher redis_con = StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB) mysql_con = get_mysql_con() def role_dispatcher(role=None): def decorator(func): def wrapper(bot, update): users = {'admin':redis_con.smembers("admins"), 'tester':redis_con.smembers("testers")} if role and role in users.keys() and str(update.message.from_user.id) in users[role]: return func(bot, update) elif not role: if str(update.message.from_user.id) in users['admin']: return func(bot, update, role='admin') elif str(update.message.from_user.id) in users['tester']: return func(bot, update, role='tester') else: return func(bot, update, role='other') return wrapper