def feed_to_weibo(feed: Feed) -> Weibo or None: mapping = {'instagram_v2': 'ins', 'twitter': '推特'} feed_type = mapping[feed.type] text = f'【{feed.user.name} {feed_type}】{feed.title[:140]} {"..." if len(feed.title) > 140 else ""} {settings.BUZZBIRD_FEED_URL}/{feed.id}' text = text_processing(text) media = None if feed.media.count() > 0: media = feed.media.all()[0] if media is None and feed.type == 'instagram_v2': logger.warning( f"{feed.type} {feed.id} missing media. Stop generating Weibo data." ) return None data = { 'text': text, 'pic': core.func.get_local_image(media.local_path) if media is not None else None, 'tweet_id': feed.id, } return Weibo(**data)
def ig_to_weibo(ig: Instagram): text = f'【{ig.user.chinese_name} Ins】{ig.title[:120]}... https://t.co/ins' data = { 'text': text, 'pic': get_image(ig.media_url), 'tweet_id': ig.id, } return Weibo(**data)
def ig_to_weibo(ig: Feed): text = f'【{ig.user.chinese_name} Ins】{ig.title[:110]}... https://spursnews.net/weibo/instagrams/{ig.id}' media = None if ig.media.count() > 0: media = ig.media.all()[0] data = { 'text': text, 'pic': func.get_local_image(media.local_path), 'tweet_id': ig.id, } return Weibo(**data)
def twitter_to_weibo(twitter: Feed): text = f'【{twitter.user.name} 推特】{twitter.title[:110]}... https://spursnews.net/weibo/instagrams/{twitter.id}' media = None if twitter.media.count() > 0: media = twitter.media.all()[0] data = { 'text': text, 'pic': func.get_local_image(media.local_path) if media is not None else None, 'tweet_id': twitter.id, } return Weibo(**data)
def to_weibo(self): # 原创和转推,text 格式不一样 if self.retweet is None: text = f'【{self.screen_name} 推特】{self.text}' image = self.first_image() else: # text = f'【{self.screen_name} 推特】{self.text} RT @{self.retweeted_status._status.user.screen_name} {self.retweeted_status.text}' # image = self.first_image(retweet=True) return None text = text if len( text) < 140 else text[:125] + '...' + 'https://t.co/diu' if 'https://t.co' not in text: text += ' https://t.co/diu' data = { 'text': text, 'pic': image, 'tweet_id': self.tweet_id, } logger.info( f'text: {text}, image: {True if image else False}, tweet_id: {self.tweet_id}' ) return Weibo(**data)