Esempio n. 1
0
def test_db(message):
    link_table = session.query(Link).all()
    message.reply('**Printing Link Table - **\n%s' %
                  pretty_print_table(link_table))
    tag_table = session.query(Tag).all()
    message.reply('**Printing Tag Table - **\n%s' %
                  pretty_print_table(tag_table))
    bot_subscriber_table = session.query(BotSubscriber).all()
    message.reply('**Printing BotSubscriber Table - **\n%s' %
                  pretty_print_table(bot_subscriber_table))
Esempio n. 2
0
def populate_link_data(days, tags, channels, message):
    if tags and days:
        from_time = str(time.time() - int(days) * 86400.00)
        tags = tags.encode().split()
        result = session.query(Link, Tag).filter(Link.id == Tag.message_id, Link.timestamp >= from_time, \
                                                 Link.channel.in_(channels), Tag.tag.in_(tags)).all()
    elif days and not tags:
        from_time = str(time.time() - int(days) * 86400.00)
        result = session.query(Link).filter(Link.timestamp >= from_time,
                                            Link.channel.in_(channels)).all()
    elif not days and tags:
        tags = tags.encode().split()
        result = session.query(Link, Tag).filter(Link.id == Tag.message_id, \
                                                 Link.channel.in_(channels), Tag.tag.in_(tags)).all()
    return result
Esempio n. 3
0
def unsubscribe_links_summary(message):

    jobTag = message.get_user_id()

    alreadyBotSubscribed = session.query(BotSubscriber).filter(
        BotSubscriber.user_id == jobTag).all()

    if alreadyBotSubscribed == []:
        message.reply(
            "You haven't Subscribed for the my updates! Cannot Unsubscribe you :P"
        )
        return

    # clear job
    schedule.clear(jobTag)

    session.query(BotSubscriber).filter(
        BotSubscriber.user_id == jobTag).delete()
    session.commit()
    message.reply("You have been successfully unsubscribed! :)")
    logger.info(
        "Bot Log : Function=unsubscribe_links_summary() - user unsubscribed from scheduled link updates"
    )
Esempio n. 4
0
    def run_scheduled_update_jobs(self):
        '''
        Triggers link aggregation update for already subscribed users
        Currently Link aggregation update is scheduled for every 30 seconds for testing purposes
         - schedule.every(SCHEDULED_UPDATE_TIME_INTERVAL).seconds.do(get_aggregated_links, message).tag(userId)

        For production, Link aggregation update can be scheduled every day at 10:00 AM by setting
         - schedule.every().day().at("10:00").do(get_aggregated_links, message).tag(userId)

        This functionality can be extended to support periodic scheduling for daily/weekly/monthly time period.

        Above changes also need to be reflected in 'subscribe_links_summary()' function in 'bot.plugins.link' module
        '''
        from linkbot.plugins.link import get_aggregated_links
        result = session.query(BotSubscriber).all()
        if result == []:
            return
        for row in result:
            schedule.every(SCHEDULED_UPDATE_TIME_INTERVAL).seconds.do(get_aggregated_links, \
            Message(self._client, None, None), row.user_id, row.team_id, row.channel_id).tag(row.user_id)
Esempio n. 5
0
def subscribe_links_summary(message):
    '''
    Subscribes sender of message of Link aggregation scheduled update by the bot
    Currently Link aggregation update is scheduled for every 30 seconds for testing purposes
     - schedule.every(SCHEDULED_UPDATE_TIME_INTERVAL).seconds.do(get_aggregated_links, message).tag(userId)

    For production, Link aggregation update can be scheduled every day at 10:00 AM by setting
     - schedule.every().day().at("10:00").do(get_aggregated_links, message).tag(userId)

    This functionality can be extended to support periodic scheduling for daily/weekly/monthly time period.

    Above changes also need to be reflected in 'run_scheduled_update_jobs()' function in 'bot.bot' module
    '''
    userId = message.get_user_id()

    alreadyBotSubscribed = session.query(BotSubscriber).filter(
        BotSubscriber.user_id == userId).all()

    if alreadyBotSubscribed != []:
        message.reply(
            "You are already a subscriber of the my updates! :) Wait for the next update!"
        )
        return

    # scheduled link aggregation
    schedule.every(SCHEDULED_UPDATE_TIME_INTERVAL).seconds.do(
        get_aggregated_links, message).tag(userId)

    botSubcriber = BotSubscriber(user_id=userId, team_id=message.get_teams_of_user(userId)[0][u'id'], \
                                 channel_id=message.channel)
    session.add(botSubcriber)
    session.flush()
    session.commit()
    message.reply(
        "Successfully subscribed for my updates! Wait for the next update! :)")
    logger.info(
        "Bot Log : Function=subscribe_links_summary() - user subscribed from scheduled link updates"
    )