예제 #1
0
    def updates(bot, update):
        """Returns list of updated posts"""
        user_id = utils.get_user_id(update)
        cm = db.CityModel()
        wm = db.WatchModel()
        pm = db.PostsModel()

        user_city = cm.get_city(user_id)
        watchlist = wm.watchlist(user_id)

        posts = []
        for item in watchlist:
            for post in feed.get_posts(user_city, item['keyword']):
                if not pm.is_post_seen(user_id, post.post_id):
                    posts.append(post)
                    pm.mark_as_seen(user_id, post.post_id)

        if not posts:
            utils.send_message_with_keyboard(bot, update, "No updates so far.")
            return

        for ten_posts in utils.chunks(posts, 10):
            updates = ""
            for post in ten_posts:
                updates += post.oneline
            utils.send_message_with_keyboard(bot, update, updates)
    def updates(bot, update):
        """Returns list of updated posts"""
        user_id = utils.get_user_id(update)
        cm = db.CityModel()
        wm = db.WatchModel()
        pm = db.PostsModel()

        user_city = cm.get_city(user_id)
        watchlist = wm.watchlist(user_id)

        posts = []
        for item in watchlist:
            for post in feed.get_posts(user_city, item['keyword']):
                if not pm.is_post_seen(user_id, post.post_id):
                    posts.append(post)
                    pm.mark_as_seen(user_id, post.post_id)

        if not posts:
            utils.send_message_with_keyboard(bot, update, "No updates so far.")
            return

        for ten_posts in utils.chunks(posts, 10):
            updates = ""
            for post in ten_posts:
                updates += post.oneline
            utils.send_message_with_keyboard(bot, update, updates)
예제 #3
0
    def citylist(bot, update):
        LOG.debug('Requesting citylist')
        cities_list = utils.get_craigslist_sites()
        cities_list = sorted(cities_list)

        for chunk in utils.chunks(cities_list, 200):
            LOG.debug('Generate citylist message')
            utils.send_message_with_keyboard(bot, update, " | ".join(chunk))
    def citylist(bot, update):
        LOG.debug('Requesting citylist')
        cities_list = utils.get_craigslist_sites()
        cities_list = sorted(cities_list)

        for chunk in utils.chunks(cities_list, 200):
            LOG.debug('Generate citylist message')
            utils.send_message_with_keyboard(bot, update, " | ".join(chunk))
    def watchlist(bot, update):
        user_id = utils.get_user_id(update)
        wm = db.WatchModel()
        watchlist = wm.watchlist(user_id)

        if watchlist:
            message = "\n".join([item['keyword'] for item in watchlist])
        else:
            message = "empty"

        utils.send_message_with_keyboard(bot, update, "Your watchlist is:\n%s" % message)
예제 #6
0
    def watchlist(bot, update):
        user_id = utils.get_user_id(update)
        wm = db.WatchModel()
        watchlist = wm.watchlist(user_id)

        if watchlist:
            message = "\n".join([item['keyword'] for item in watchlist])
        else:
            message = "empty"

        utils.send_message_with_keyboard(bot, update,
                                         "Your watchlist is:\n%s" % message)
예제 #7
0
    def unwatch(bot, update):
        user_id = utils.get_user_id(update)
        keyword = utils.extract_command_value(update)

        wm = db.WatchModel()

        if wm.is_watched(user_id, keyword):
            wm.unwatch(user_id, keyword)
            message = "%s removed from watching list." % keyword
        else:
            message = "Keyword %s not found in you're watching list." % keyword

        utils.send_message_with_keyboard(bot, update, message)
    def unwatch(bot, update):
        user_id = utils.get_user_id(update)
        keyword = utils.extract_command_value(update)

        wm = db.WatchModel()

        if wm.is_watched(user_id, keyword):
            wm.unwatch(user_id, keyword)
            message = "%s removed from watching list." % keyword
        else:
            message = "Keyword %s not found in you're watching list." % keyword

        utils.send_message_with_keyboard(bot, update, message)
예제 #9
0
    def watch(bot, update):
        """Add new item to watchlist"""
        user_id = utils.get_user_id(update)
        keyword = utils.extract_command_value(update)

        wm = db.WatchModel()

        if not wm.is_watched(user_id, keyword):
            wm.watch(user_id, keyword)
            message = "You are now watching %s" % keyword
        else:
            message = "You already watching %s" % keyword

        utils.send_message_with_keyboard(bot, update, message)
예제 #10
0
    def search(bot, update):
        user_id = utils.get_user_id(update)
        cm = db.CityModel()
        user_city = cm.get_city(user_id)

        posts = feed.get_posts(user_city, update.message.text)

        text = ""
        for p in posts:
            text += p.oneline

        if not text:
            text = "Empty search result."
        utils.send_message_with_keyboard(bot, update, text)
    def watch(bot, update):
        """Add new item to watchlist"""
        user_id = utils.get_user_id(update)
        keyword = utils.extract_command_value(update)

        wm = db.WatchModel()

        if not wm.is_watched(user_id, keyword):
            wm.watch(user_id, keyword)
            message = "You are now watching %s" % keyword
        else:
            message = "You already watching %s" % keyword

        utils.send_message_with_keyboard(bot, update, message)
예제 #12
0
    def city(bot, update):
        city_name = utils.extract_command_value(update)
        if city_name not in utils.get_craigslist_sites():
            bot.sendMessage(chat_id=update.message.chat_id,
                            text="City not found. Please send /citylist "
                            "to check list of avaliable cities.")
            return

        user_id = utils.get_user_id(update)

        cm = db.CityModel()
        cm.set_city(user_id=user_id, city=city_name)

        utils.send_message_with_keyboard(bot, update,
                                         "City set to %s" % city_name)
    def city(bot, update):
        city_name = utils.extract_command_value(update)
        if city_name not in utils.get_craigslist_sites():
            bot.sendMessage(
                chat_id=update.message.chat_id,
                text="City not found. Please send /citylist "
                     "to check list of avaliable cities.")
            return

        user_id = utils.get_user_id(update)

        cm = db.CityModel()
        cm.set_city(user_id=user_id, city=city_name)

        utils.send_message_with_keyboard(bot, update, "City set to %s" % city_name)
 def start(bot, update):
     utils.send_message_with_keyboard(bot, update, message)
예제 #15
0
 def help(bot, update):
     utils.send_message_with_keyboard(bot, update, help_message)
예제 #16
0
 def restart(bot, update):
     db.PostsModel().delete_all()
     db.WatchModel().delete_all()
     db.CityModel().delete_all()
     utils.send_message_with_keyboard(bot, update, "Total reset")
예제 #17
0
 def start(bot, update):
     utils.send_message_with_keyboard(bot, update, message)
 def help(bot, update):
     utils.send_message_with_keyboard(bot, update, help_message)
 def restart(bot, update):
     db.PostsModel().delete_all()
     db.WatchModel().delete_all()
     db.CityModel().delete_all()
     utils.send_message_with_keyboard(bot, update, "Total reset")