コード例 #1
0
class AutoMessageManager:
    def __init__(self):
        self.targets = Database()

        self.recently_sent = False

    def subscribe(self, bot, update):
        if self.targets.add(str(update.message.chat_id)):
            bot.sendMessage(chat_id=update.message.chat_id,
                            text=responses.subscribe)
        else:
            bot.sendMessage(chat_id=update.message.chat_id,
                            text=responses.already_subscribed)

    def unsubscribe(self, bot, update):
        if self.targets.remove(str(update.message.chat_id)):
            bot.sendMessage(chat_id=update.message.chat_id,
                            text=responses.unsubscribe)
        else:
            bot.sendMessage(chat_id=update.message.chat_id,
                            text=responses.not_subscribed)

    def job(self, bot):
        try:
            if self.recently_sent:
                self.recently_sent = False
                return

            if valid_time():
                print('preparando para executar o job')

                menu = responses.cardapio()

                self.recently_sent = True

                for chat_id in self.targets:
                    try:
                        send_menu(bot, chat_id, menu)

                    except telegram.error.Unauthorized:
                        self.targets.remove(chat_id)
                        bot.sendMessage(
                            chat_id=config.MAINTAINER_ID,
                            text='Unauthorized: removed {}'.format(chat_id))

                    except telegram.error.ChatMigrated as e:
                        self.targets.remove(chat_id)
                        self.targets.add(str(e.new_chat_id))

                        bot.sendMessage(chat_id=config.MAINTAINER_ID,
                                        text='ChatMigrated: {} to {}'.format(
                                            chat_id, e.new_chat_id))

                    except Exception as e:
                        error(bot, None, e)

                print('job finalizado')

        except Exception as e:
            error(bot, None, e)
コード例 #2
0
ファイル: crawl.py プロジェクト: jklumpp0/Python
def crawl(folder = os.curdir): 
    db = Database()

    for root, dirs, files in os.walk(folder): 
        abs_files = [os.path.join(root, file) for file in files]
        img_files = [get_image(file) for file in abs_files]
 
        for image in filter(None, img_files):
            db.add(image)
コード例 #3
0
def crawl(folder=os.curdir):
    db = Database()

    for root, dirs, files in os.walk(folder):
        abs_files = [os.path.join(root, file) for file in files]
        img_files = [get_image(file) for file in abs_files]

        for image in filter(None, img_files):
            db.add(image)
コード例 #4
0
ファイル: snapshot.py プロジェクト: mich181189/stats-snapshot
def main(args):
    import logging
    if args.verbose:
        LOGGER.setLevel(logging.DEBUG)
    else:
        LOGGER.setLevel(logging.INFO)

    # Get the database handle
    db = Database(args.db, args.overwrite)

    for i in range(args.count):
        if i > 0:
            time.sleep(args.period)
        # Read all the data we need
        system_stats, processes, memory_stats = read_stats(args)

        LOGGER.info('Found {} process(es) and {} used memory fragments'.format(
                    len(processes), len(memory_stats)))
        LOGGER.info('Regions: %s' % memory_stats)

        db.add(args.host if len(args.host) else '[local]', system_stats, memory_stats, processes)
コード例 #5
0
ファイル: handler.py プロジェクト: caiopo/quibe-bot
class AutoMessageManager:
    def __init__(self):
        self.targets = Database()

        self.recently_sent = False

    def subscribe(self, bot, update):
        if self.targets.add(str(update.message.chat_id)):
            bot.sendMessage(chat_id=update.message.chat_id,
                            text=responses.subscribe)
        else:
            bot.sendMessage(chat_id=update.message.chat_id,
                            text=responses.already_subscribed)

    def unsubscribe(self, bot, update):
        if self.targets.remove(str(update.message.chat_id)):
            bot.sendMessage(chat_id=update.message.chat_id,
                            text=responses.unsubscribe)
        else:
            bot.sendMessage(chat_id=update.message.chat_id,
                            text=responses.not_subscribed)

    def job(self, bot):
        try:
            if self.recently_sent:
                self.recently_sent = False
                return

            if valid_time():
                print('preparando para executar o job')

                menu = responses.cardapio()

                self.recently_sent = True

                for chat_id in self.targets:
                    try:
                        send_menu(bot, chat_id, menu)

                    except telegram.error.Unauthorized:
                        self.targets.remove(chat_id)
                        bot.sendMessage(
                            chat_id=config.MAINTAINER_ID,
                            text='Unauthorized: removed {}'.format(chat_id))

                    except telegram.error.ChatMigrated as e:
                        self.targets.remove(chat_id)
                        self.targets.add(str(e.new_chat_id))

                        bot.sendMessage(
                            chat_id=config.MAINTAINER_ID,
                            text='ChatMigrated: {} to {}'.format(
                                chat_id, e.new_chat_id))

                    except Exception as e:
                        error(bot, None, e)

                print('job finalizado')

        except Exception as e:
            error(bot, None, e)