Esempio n. 1
0
 def is_post_seen(self, user_id, post_id):
     LOG.debug("is_post_seen user_id:%s post_id:%s" % (user_id, post_id))
     return self.table.find_one({
         "user_id": user_id,
         "post_id": post_id,
         "status": self.POST_ALREADY_SEEN
     })
Esempio n. 2
0
 def mark_as_seen(self, user_id, post_id):
     LOG.debug("mark_as_seen user_id:%s post_id:%s" % (user_id, post_id))
     if not self.is_post_seen(user_id, post_id):
         self.table.insert_one({
             "user_id": user_id,
             "post_id": post_id,
             "status": PostsModel.POST_ALREADY_SEEN})
Esempio n. 3
0
 def mark_as_seen(self, user_id, post_id):
     LOG.debug("mark_as_seen user_id:%s post_id:%s" % (user_id, post_id))
     if not self.is_post_seen(user_id, post_id):
         self.table.insert_one({
             "user_id": user_id,
             "post_id": post_id,
             "status": PostsModel.POST_ALREADY_SEEN
         })
    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))
Esempio n. 5
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))
Esempio n. 6
0
def main():
    try:
        r = Robot()
        while True:
            pass
    except KeyboardInterrupt:
        LOG.error("KeyboardInterrupt")
        r.stop()
        exit()
Esempio n. 7
0
    def get_city(self, user_id):
        LOG.debug("get_city user_id:%s" % user_id)
        if not user_id:
            raise exceptions.NoUserException()

        result = self.table.find_one({"user_id": user_id})
        LOG.error(result)
        if result is None:
            return None
        return result['city']
Esempio n. 8
0
    def get_city(self, user_id):
        LOG.debug("get_city user_id:%s" % user_id)
        if not user_id:
            raise exceptions.NoUserException()

        result = self.table.find_one({"user_id": user_id})
        LOG.error(result)
        if result is None:
            return None
        return result['city']
Esempio n. 9
0
    def unwatch(self, user_id, keyword):
        LOG.debug("unwatch user_id:%s keyword:%s" % (user_id, keyword))
        if not user_id:
            raise exceptions.NoUserException()
        if not keyword:
            raise exceptions.EmptyKeywordException()

        keyword = keyword.lower()

        if self.is_watched(user_id, keyword):
            self.table.delete_one({"user_id": user_id, "keyword": keyword})
Esempio n. 10
0
    def is_watched(self, user_id, keyword):
        LOG.debug("is_watched user_id:%s keyword:%s" % (user_id, keyword))
        if not user_id:
            raise exceptions.NoUserException()
        if not keyword:
            raise exceptions.EmptyKeywordException()

        keyword = keyword.lower()

        if self.table.find_one({"user_id": user_id, "keyword": keyword}):
            return True
        return False
Esempio n. 11
0
def extract_command_value(update):
    LOG.debug("Extract value from command.")
    message = update.to_dict()["message"]["text"]
    if not message.startswith('/'):
        raise exceptions.CommandNotFound('Missed starting /')
    r = re.compile(r'/\w+(\ +)(.+)')
    try:
        keyword = r.search(message).group(2)
    except AttributeError:
        raise exceptions.CommandRequiresValue()
    if not keyword:
        raise Exception('Keyword is empty')
    return keyword
Esempio n. 12
0
    def is_watched(self, user_id, keyword):
        LOG.debug("is_watched user_id:%s keyword:%s" % (user_id, keyword))
        if not user_id:
            raise exceptions.NoUserException()
        if not keyword:
            raise exceptions.EmptyKeywordException()

        keyword = keyword.lower()

        if self.table.find_one({"user_id": user_id,
                                "keyword": keyword}):
            return True
        return False
Esempio n. 13
0
    def unwatch(self, user_id, keyword):
        LOG.debug("unwatch user_id:%s keyword:%s" % (user_id, keyword))
        if not user_id:
            raise exceptions.NoUserException()
        if not keyword:
            raise exceptions.EmptyKeywordException()

        keyword = keyword.lower()

        if self.is_watched(user_id, keyword):
            self.table.delete_one({
                "user_id": user_id,
                "keyword": keyword})
Esempio n. 14
0
def extract_command_value(update):
    LOG.debug("Extract value from command.")
    message = update.to_dict()["message"]["text"]
    if not message.startswith('/'):
        raise exceptions.CommandNotFound('Missed starting /')
    r = re.compile(r'/\w+(\ +)(.+)')
    try:
        keyword = r.search(message).group(2)
    except AttributeError:
        raise exceptions.CommandRequiresValue()
    if not keyword:
        raise Exception('Keyword is empty')
    return keyword
Esempio n. 15
0
    def set_city(self, user_id, city):
        LOG.debug("set_city user_id:%s city:%s" % (user_id, city))
        if not city:
            raise exceptions.EmptyCityException()
        if not user_id:
            raise exceptions.NoUserException()

        city = city.lower()

        if not self.is_city_set(user_id):
            self.table.insert_one({"user_id": user_id, "city": city})
        else:
            self.table.update_one({"user_id": user_id},
                                  {"$set": {
                                      "city": city
                                  }})
Esempio n. 16
0
    def set_city(self, user_id, city):
        LOG.debug("set_city user_id:%s city:%s" % (user_id, city))
        if not city:
            raise exceptions.EmptyCityException()
        if not user_id:
            raise exceptions.NoUserException()

        city = city.lower()

        if not self.is_city_set(user_id):
            self.table.insert_one({
                "user_id": user_id,
                "city": city})
        else:
            self.table.update_one(
                {"user_id": user_id},
                {"$set": {"city": city}})
Esempio n. 17
0
 def contains_in_watchlist(self, user_id, keyword):
     LOG.info("Replace contains_in_watchlist with is_watched")
     return self.is_watched(user_id, keyword)
Esempio n. 18
0
 def is_city_set(self, user_id):
     LOG.debug("is_city_set user_id:%s" % user_id)
     if self.table.find_one({"user_id": user_id}):
         return True
     return False
Esempio n. 19
0
 def update_or_set(self, user_id, city):
     LOG.info("Replace update_or_set with set_city")
     return self.set_city(user_id, city)
Esempio n. 20
0
 def watchlist(self, user_id):
     LOG.debug("watchlist user_id:%s" % user_id)
     if not user_id:
         raise exceptions.NoUserException()
     return self.table.find({"user_id": user_id})
Esempio n. 21
0
 def watchlist(self, user_id):
     LOG.debug("watchlist user_id:%s" % user_id)
     if not user_id:
         raise exceptions.NoUserException()
     return self.table.find({"user_id": user_id})
Esempio n. 22
0
 def contains_in_watchlist(self, user_id, keyword):
     LOG.info("Replace contains_in_watchlist with is_watched")
     return self.is_watched(user_id, keyword)
Esempio n. 23
0
 def update_or_set(self, user_id, city):
     LOG.info("Replace update_or_set with set_city")
     return self.set_city(user_id, city)
Esempio n. 24
0
def get_user_id(update):
    LOG.debug('Unpack user_id from update')
    return update.to_dict()["message"]["from"]["id"]
Esempio n. 25
0
 def is_post_seen(self, user_id, post_id):
     LOG.debug("is_post_seen user_id:%s post_id:%s" % (user_id, post_id))
     return self.table.find_one({
         "user_id": user_id,
         "post_id": post_id,
         "status": self.POST_ALREADY_SEEN})
Esempio n. 26
0
def get_user_id(update):
    LOG.debug('Unpack user_id from update')
    return update.to_dict()["message"]["from"]["id"]
Esempio n. 27
0
 def is_city_set(self, user_id):
     LOG.debug("is_city_set user_id:%s" % user_id)
     if self.table.find_one({"user_id": user_id}):
         return True
     return False