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 })
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 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))
def main(): try: r = Robot() while True: pass except KeyboardInterrupt: LOG.error("KeyboardInterrupt") r.stop() exit()
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']
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})
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
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
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})
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 }})
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}})
def contains_in_watchlist(self, user_id, keyword): LOG.info("Replace contains_in_watchlist with is_watched") return self.is_watched(user_id, keyword)
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
def update_or_set(self, user_id, city): LOG.info("Replace update_or_set with set_city") return self.set_city(user_id, city)
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})
def get_user_id(update): LOG.debug('Unpack user_id from update') return update.to_dict()["message"]["from"]["id"]
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})