def __init__(self): conf = ConfigCenter.FileConfig() self.__path = conf self.year, self.month, day = Time.now_ymd() self.lasty, self.lastm, _ = Time.lastday_ymd() if day == "01": self._new_month_do_()
def __parse_html__(self, html_data): html_data_iter = self.__html_data_iter__(html_data) try: next(html_data_iter) except Exception: raise ("Not a list.") dict_data_list = list() for html_data in html_data_iter: hotkey_emoji = re.findall( """<a href=\"/weibo\?q=.+;Refer=top\" target=\"_blank\">(.+)</a>""", html_data) flag = re.findall("""<i class=\"icon-txt .+\">(.+)</i></td>""", html_data) amount = re.findall("""<span>([0-9]+)</span>""", html_data) if len(hotkey_emoji) > 0 and "荐" not in flag: hotkey = re.findall("(.+)<img", hotkey_emoji[0]) emoji = list() if len(hotkey) == 0: hotkey = hotkey_emoji[0] else: hotkey = hotkey[0] emoji = re.findall("<img.+alt=\"\[(.+)\]\"", hotkey_emoji[0]) dict_data_list.append( dict(hotkey=hotkey, flag=flag, amount=amount[0], emoji=emoji, time=Time.now_timestamp())) return dict_data_list
def push_data(self): conf = ConfigCenter.GitConfig() filepath = conf['filepath'].split(',') msg = "Auto commit for %s." % (Time.now_date_str()) err = self.push(msg, *filepath) if err is not None: print(err)
# -*- coding: utf-8 -*- # 监控机器人,当出现爆炸新闻或者出现监控词的时候会自动推送到群内。 from cronjob.crawler.hotkey_fetcher import HotkeyFetcher from cronjob.datacenter.cache.cache_controller import CacheController from util.configcenter.config_center import ConfigCenter from cronjob.tool.qywx import QYWX, MSG_TYPE_MARKDOWN from util.constant.enum import * from util.base.time import Time if __name__ == "__main__": now = Time.now_timestamp() fetcher = HotkeyFetcher() data = fetcher.get_data(ENUM_DATATYPE_JSON, limit=10) # cacheController = CacheController() # cacheController.insert_cache(now, data) print(now, data)