import datetime import msgs from utils import determineEmbedTweet, determineMediaToEmbed from copy import deepcopy def tweetDataToActivity(tweetData): content="" if tweetData['replyingTo'] is not None: content += f"
↪️ Replying to @{tweetData['replyingTo']}
" content+=f"

{tweetData['text']}

" attachments=[] if tweetData['qrt'] is not None: content += f"
QRT: {tweetData['qrt']['user_screen_name']}
{tweetData['qrt']['text']}
" if tweetData['pollData'] is not None: content += f"

{msgs.genPollDisplay(tweetData['pollData'])}

" content += "

" content = content.replace("\n","
") #if media is not None: # attachments.append({"type":mediatype,"url":media}) likes = tweetData['likes'] retweets = tweetData['retweets'] # convert date epoch to iso format date = tweetData['date_epoch'] date = datetime.datetime.fromtimestamp(date).isoformat() + "Z" embedTweetData = determineEmbedTweet(tweetData) embeddingMedia = embedTweetData['hasMedia'] media = None if embeddingMedia: media = determineMediaToEmbed(embedTweetData,-1) if media is not None: media = deepcopy(media) if media['type'] == "gif": media['type'] = "gifv" attachments.append({ "id": "114163769487684704", "type": media['type'], "url": media['url'], "preview_url": media['thumbnail_url'], }) # https://docs.joinmastodon.org/methods/statuses/ return { "id": tweetData['tweetID'], "url": f"https://x.com/{tweetData['user_screen_name']}/status/{tweetData['tweetID']}", "uri": f"https://x.com/{tweetData['user_screen_name']}/status/{tweetData['tweetID']}", "created_at": date, "edited_at": None, "reblog": None, "in_reply_to_account_id": None, "language": "en", "content": content, "spoiler_text": "", "visibility": "public", "application": { "website": None }, "media_attachments": attachments, "account": { "display_name": tweetData['user_name'], "username": tweetData['user_screen_name'], "acct": tweetData['user_screen_name'], "url": f"https://x.com/{tweetData['user_screen_name']}/status/{tweetData['tweetID']}", "uri": f"https://x.com/{tweetData['user_screen_name']}/status/{tweetData['tweetID']}", "locked": False, "avatar": tweetData['user_profile_image_url'], "avatar_static": tweetData['user_profile_image_url'], "hide_collections": False, "noindex": False, }, }