forked from dylanpdx/BetterTwitFix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivity.py
More file actions
82 lines (75 loc) · 2.87 KB
/
activity.py
File metadata and controls
82 lines (75 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import datetime
import msgs
from utils import determineEmbedTweet, determineMediaToEmbed
from copy import deepcopy
def tweetDataToActivity(tweetData,embedIndex = -1):
content=""
if tweetData['replyingTo'] is not None:
content += f"<blockquote>↪️ <i>Replying to @{tweetData['replyingTo']}</i></blockquote>"
content+=f"<p>{tweetData['text']}</p>"
attachments=[]
if tweetData['qrt'] is not None:
content += f"<blockquote><b>QRT: <a href=\"{tweetData['qrtURL']}\">{tweetData['qrt']['user_screen_name']}</a></b><br>{tweetData['qrt']['text']}</blockquote>"
if tweetData['pollData'] is not None:
content += f"<p>{msgs.genPollDisplay(tweetData['pollData'])}</p>"
content += "</p>"
content = content.replace("\n","<br>")
#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,embedIndex)
if media is not None:
media = deepcopy(media)
if media['type'] == "gif":
if "/convert.avif" in media['url']:
media['type'] = "image"
else:
media['type'] = "gifv"
if 'thumbnail_url' not in media:
media['thumbnail_url'] = media['url']
if media['type'] == "image" and "?" not in media['url']:
media['url'] += "?name=orig"
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,
},
}