spinning things back up slowly
This commit is contained in:
+17
-77
@@ -42,72 +42,26 @@ class TalentTweet:
|
||||
tweet_id=tweet_id, author_id=author_id,
|
||||
date_time=date_time, mrq=(mentions, reply_to, quote_retweeted)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
async def create_from_twint_tweet(tweet):
|
||||
# MRQ
|
||||
mentions = set()
|
||||
reply_to = None
|
||||
quoted_id = None
|
||||
|
||||
# reply_to/mentions
|
||||
is_reply = tweet.id != int(tweet.conversation_id)
|
||||
mentions = set([x['id'] for x in tweet.mentions])
|
||||
if is_reply and len(tweet.reply_to) > 0:
|
||||
reply_to = tweet.reply_to[0]['id'] # FIXME: QRT = is_reply and len(tweet.reply_to) == 0?
|
||||
reply_others = [x['id'] for x in tweet.reply_to[1:]]
|
||||
mentions.update(reply_others)
|
||||
try: mentions.remove(reply_to)
|
||||
except: pass
|
||||
|
||||
# qrt
|
||||
if type(tweet.quote_url) == str:
|
||||
# print(f'url: {tweet.quote_url} ({type(tweet.quote_url)})')
|
||||
quote_tokens = tweet.quote_url.split('/')
|
||||
if len(quote_tokens) >= 2:
|
||||
quoted_username = quote_tokens[-2]
|
||||
quoted_id = util.get_user_id_local(quoted_username)
|
||||
if quoted_id == -1:
|
||||
quoted_id = util.get_user_id_online(quoted_username)
|
||||
# Serialized one-liner format:
|
||||
# {tweet} {author} {time in seconds since epoch} m {mention_set} r {reply_to_author} q {quote_retweet_author}
|
||||
def serialize(self):
|
||||
s = f'{self.tweet_id} {self.author_id} {self.date_time.timestamp()} '
|
||||
|
||||
# NOTE: strptime doesn't attach timezone info.
|
||||
# tweet's datetime will be in local time
|
||||
date_time = datetime.datetime.strptime(tweet.datetime, '%Y-%m-%d %H:%M:%S %Z')
|
||||
LOCAL_TIMEZONE = datetime.datetime.now().astimezone().tzinfo
|
||||
date_time = date_time.replace(tzinfo=LOCAL_TIMEZONE) # attach system local timezone
|
||||
return TalentTweet(tweet_id=tweet.id, author_id=tweet.user_id, date_time=date_time, mrq=(mentions, reply_to, quoted_id))
|
||||
|
||||
@staticmethod
|
||||
def create_from_v2api_response(resp):
|
||||
tweet = resp.data
|
||||
if tweet is None: return None
|
||||
if None not in [self.rt_target, self.rt_author_id]:
|
||||
s += f'rt {self.rt_target} {self.rt_author_id}'
|
||||
return s[:-1] # stop here since retweets can't have other info
|
||||
|
||||
mrq = twapi.TwAPI.get_mrq(resp)
|
||||
rt_target = None
|
||||
rt_author_id = None
|
||||
|
||||
# check if is RT
|
||||
if tweet.referenced_tweets is not None and len(tweet.referenced_tweets) > 0:
|
||||
for ref in tweet.referenced_tweets:
|
||||
if ref.type == 'retweeted':
|
||||
rt_target = ref.id
|
||||
for incl_tweet in resp.includes['tweets']:
|
||||
if incl_tweet.id == ref.id:
|
||||
rt_author_id = incl_tweet.author_id
|
||||
|
||||
return TalentTweet(
|
||||
tweet_id=tweet.id,
|
||||
author_id=tweet.author_id,
|
||||
date_time=tweet.created_at,
|
||||
mrq=mrq,
|
||||
rt_target=rt_target,
|
||||
rt_author_id=rt_author_id
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
async def create_from_id(id):
|
||||
resp = await twapi.TwAPI.instance.get_tweet_response(id)
|
||||
return TalentTweet.create_from_v2api_response(resp)
|
||||
if len(self.mentions) > 0:
|
||||
s += 'm '
|
||||
for id in self.mentions:
|
||||
s += f'{id} '
|
||||
if self.reply_to:
|
||||
s += f'r {self.reply_to} '
|
||||
if self.quote_retweeted:
|
||||
s += f'q {self.quote_retweeted} '
|
||||
|
||||
return s[:-1]
|
||||
|
||||
def __init__(self, tweet_id: int, author_id: int, date_time: datetime.datetime, mrq: tuple, rt_target: int=None, rt_author_id: int=None):
|
||||
self.tweet_id, self.author_id = tweet_id, author_id
|
||||
@@ -140,20 +94,6 @@ class TalentTweet:
|
||||
f'{self.serialize()}\n'
|
||||
f'======================================================'
|
||||
)
|
||||
|
||||
# Serialized one-liner format:
|
||||
# {tweet} {author} {time in seconds since epoch} m {mention_set} r {reply_to_author} q {quote_retweet_author}
|
||||
def serialize(self):
|
||||
s = f'{self.tweet_id} {self.author_id} {self.date_time.timestamp()} '
|
||||
if len(self.mentions) > 0:
|
||||
s += 'm '
|
||||
for id in self.mentions:
|
||||
s += f'{id} '
|
||||
if self.reply_to:
|
||||
s += f'r {self.reply_to} '
|
||||
if self.quote_retweeted:
|
||||
s += f'q {self.quote_retweeted} '
|
||||
return s[:-1]
|
||||
|
||||
def is_cross_company(self):
|
||||
for other_id in self.all_parties:
|
||||
|
||||
Reference in New Issue
Block a user