예제 #1
0
 def weibo_tweets_gen(_inner_current_page=1):
     while True:
         if pages is not None and _inner_current_page > pages:
             break
         tweet_response_json = weibo_tweets(containerid=tweet_container_id, page=_inner_current_page)
         # skip bad request
         if tweet_response_json is None:
             continue
         elif tweet_response_json.get("ok") != 1:
             break
         weibo_tweet_parser = WeiboTweetParser(tweet_get_index_response=tweet_response_json)
         yield weibo_tweet_parser
         _inner_current_page += 1
예제 #2
0
    def __init__(self, tweet_get_index_response: dict = None, tweet_containerid: str = None) -> None:
        if tweet_get_index_response is None and tweet_containerid is None:
            raise WeiboApiException(
                "WeiboTweetParser#__init__  tweet_get_index_response and tweet_containerid is none !")

        self.tweet_containerid = tweet_containerid

        self._tweet_get_index_reponse = weibo_tweets(containerid=tweet_containerid) \
            if tweet_get_index_response is None and tweet_containerid is not None \
            else tweet_get_index_response

        self._cards_node = [TweetMeta(card_node=card) for card in list(
            filter(lambda card: card.get('card_group') is None,
                   self._tweet_get_index_reponse.get('data').get('cards')))]
예제 #3
0
 def tweet_containerid(self):
     if isinstance(self.tabs_node, list):
         _weibo_containerid = list(filter(lambda tab: tab.get('tab_type') == 'weibo', self.tabs_node))[0].get(
             'containerid')
         if _weibo_containerid.__contains__('WEIBO_SECOND_PROFILE_WEIBO'):
             return re.findall(r'(.+?)WEIBO_SECOND_PROFILE_WEIBO_PAY_BILL',
                               list(filter(lambda tab: tab.get('tab_type') == 'weibo', self.tabs_node))[0].get(
                                   'containerid'))[0]
         else:
             return _weibo_containerid
     elif isinstance(self.tabs_node, dict):
         _response_include_tweetid = weibo_tweets(containerid=self.profile_containerid, page=0)
         _cards = _response_include_tweetid.get('data').get('cards')
         return re.findall(r'containerid=(.+?)WEIBO_SECOND',
                           list(filter(lambda _card: _card.get('itemid') == 'more_weibo', _cards))[0]
                           .get('scheme'))[0]
     else:
         return None
예제 #4
0
 def gen(_inner_current_page=1):
     while True:
         if pages is not None and _inner_current_page > pages:
             break
         _response_json = weibo_tweets(containerid=tweet_container_id, page=_inner_current_page)
         # skip bad request
         if _response_json is None:
             continue
         # break failed response
         elif _response_json.get("ok") != 1:
             break
         # break end tweet
         elif _response_json.get('data').get("cards")[0].get('name') == '暂无微博':
             break
         _cards = _response_json.get('data').get("cards")
         for _card in _cards:
             # skip recommended tweets
             if _card.get("card_group"):
                 continue
             # just yield field of mblog
             yield _card
         _inner_current_page += 1