def need_send_weibo(email, name, weibo): """ return new weibo or last day weibo : name: weibo name in once search news : weibo: weibo info of searching , must contain name,content,time,url """ need_send_weibo = {} last_search_time, last_email_time = AccountSetting.get_last_time(email, name) if last_search_time <= trans_time(weibo["time"]) and last_search_time >= last_email_time: return weibo return {}
def need_send_news(email, keyword, news_list): """ 根据消息发布时间查询数据库,判断该消息是否需要发送, 若发布时间>=数据库中该用户keyword的最后一次发送邮件时间,则发送 #若发布时间>=数据库中该用户keyword的最后一次搜索时间,且最后一次发送时间>=最后一次搜索时间,则发送; : keyword: key word in once search news : news_list: news results(a list) of searching , must contain title,content,time,url """ need_send_news = [] last_search_time, last_email_time = AccountSetting.get_last_time(email, keyword) for news in news_list: if last_email_time <= trans_time(news["time"]): #and last_search_time >= last_email_time: need_send_news.append(news) #send_news.append("%s %s %s \n %s\n %s" % # (news["title"], news["source"], news["time"], news["content"], news["url"])) return need_send_news
def create(cls, name, add_weibo): """ : add_weibo : a dict which must contain : content, url, time; may content ... """ key = cal_key(add_weibo["content"]) ret = weibo_collection.find_one({"name": name, "key": key}) if ret: return ret, False weibo = { "name": name, "content": add_weibo["content"], "url": add_weibo["url"], "key": key, } weibo.update(add_weibo) weibo["time"] = trans_time(weibo["time"]) weibo_collection.insert(weibo) return weibo, True
def create(cls, keyword, add_news): """ : add_news : a dict which must contain : title, content, url, time; may content source, ... """ key = cal_key(add_news["content"]) ret = news_collection.find_one({"keyword": keyword, "key": key}) if ret: return ret, False news = { "keyword": keyword, "title": add_news["title"], "content": add_news["content"], "url": add_news["url"], "key": key, } news.update(add_news) news["time"] = trans_time(news["time"]) news_collection.insert(news) return news, True