def _update(): """ Polls the feeds to fetch the latest mentions """ coll = Keyword.collection() keyword_obj_lis = [Keyword.unserialize(x) for x in coll.find()] for keyword in keyword_obj_lis: d = feedparser.parse(keyword.feed_url) for entry in d["entries"]: if get_mention_by_alert_id(entry["id"]) is None and entry["title"] != "Feeds for Google Alerts": _save_mention(keyword.keyword, entry)
def get_keyword_from_str(kw): dic = Keyword.collection().find_one({"keyword": kw}) return Keyword.unserialize(dic) if dic is not None else None
from datetime import datetime from time import mktime import feedparser import galerts from unifide_backend.action.social.brand_mention.model import Keyword, Mention from unifide_backend.action.util import readable, generator_to_list from unifide_backend.local_config import GOOGLE_USERNAME, GOOGLE_PASSWD_ENCODED def del_keyword(keyword_str, async=False): kw_obj = get_keyword_from_str(keyword_str) if kw_obj is None: return #delete off db Keyword.collection().remove({"_id": kw_obj.obj_id()}) #dleete off google alert account alert_obj = _get_alert_from_keyword(keyword_str) _gam().delete(alert_obj) def get_keyword_from_str(kw): dic = Keyword.collection().find_one({"keyword": kw}) return Keyword.unserialize(dic) if dic is not None else None def get_str_keywords(): """ Gets all registered keywords """ alerts = generator_to_list(_gam().alerts)