mirror of
https://github.com/d0zingcat/bluesky-crossposter.git
synced 2026-05-13 15:09:25 +00:00
Finalized post toggle
This commit is contained in:
43
crosspost.py
43
crosspost.py
@@ -50,6 +50,7 @@ def getPosts():
|
||||
# If post has an embed of type record it is a quote post, and should not be crossposted
|
||||
cid = feed_view.post.cid
|
||||
text = feed_view.post.record.text
|
||||
langs = feed_view.post.record.langs
|
||||
timestamp = datetime.strptime(feed_view.post.indexedAt.split(".")[0], date_in_format) + timedelta(hours = 2)
|
||||
# Setting replyToUser to the same as user handle and only changing it if the tweet is an actual reply.
|
||||
# This way we can just check if the variable is the same as the user handle later and send through
|
||||
@@ -83,7 +84,8 @@ def getPosts():
|
||||
"text": text,
|
||||
"replyTo": replyTo,
|
||||
"images": images,
|
||||
"type": postType
|
||||
"type": postType,
|
||||
"langs": langs
|
||||
}
|
||||
# Saving post to posts dictionary
|
||||
posts[cid] = postInfo;
|
||||
@@ -154,6 +156,7 @@ def post(posts):
|
||||
replyTo = posts[cid]["replyTo"]
|
||||
images = posts[cid]["images"]
|
||||
postType = posts[cid]["type"]
|
||||
langs = postType = posts[cid]["langs"]
|
||||
tweetReply = ""
|
||||
tootReply = ""
|
||||
# If it is a reply, we get the IDs of the posts we want to reply to from the database.
|
||||
@@ -169,26 +172,42 @@ def post(posts):
|
||||
images = getImages(images)
|
||||
# Trying to post to twitter and mastodon. If posting fails the post ID for each service is set to an
|
||||
# empty string, letting the code know it should try again next time the code is run.
|
||||
if not tweetId and tweetReply != "Too_long_post":
|
||||
if not tweetId and tweetReply != "skipped":
|
||||
try:
|
||||
tweetId = tweet(text, tweetReply, images, postType)
|
||||
tweetId = tweet(text, tweetReply, images, postType, langToggle(langs, "twitter"))
|
||||
except Exception as error:
|
||||
writeLog(error)
|
||||
tweetId = ""
|
||||
# Mastodon does not have a quote retweet function, so those will just be sent as replies.
|
||||
if not tootId:
|
||||
if not tootId and tootReply != "skipped":
|
||||
try:
|
||||
tootId = toot(text, tootReply, images)
|
||||
tootId = toot(text, tootReply, images, langToggle(langs, "mastodon"))
|
||||
except Exception as error:
|
||||
writeLog(error)
|
||||
tootId = ""
|
||||
# Saving post to database
|
||||
jsonWrite(cid, tweetId, tootId)
|
||||
|
||||
# This function uses the language selection as a way to select which posts should be crossposted.
|
||||
def langToggle(langs, service):
|
||||
if service == "twitter":
|
||||
langToggle = toggle.twitterLang
|
||||
elif service == "mastodon":
|
||||
langToggle = toggle.mastodonLang
|
||||
else:
|
||||
writeLog("Something has gone very wrong")
|
||||
exit()
|
||||
if not langToggle:
|
||||
return True
|
||||
if langToggle in langs:
|
||||
return (not toggle.postDefault)
|
||||
else:
|
||||
return toggle.postDefault
|
||||
|
||||
# Function for posting tweets
|
||||
def tweet(post, replyTo, images, postType):
|
||||
if not toggle.Twitter:
|
||||
return;
|
||||
def tweet(post, replyTo, images, postType, doPost):
|
||||
if not toggle.Twitter or not doPost:
|
||||
return "skipped";
|
||||
mediaIds = []
|
||||
# If post includes images, images are uploaded so that they can be included in the tweet
|
||||
if images:
|
||||
@@ -210,7 +229,7 @@ def tweet(post, replyTo, images, postType):
|
||||
post, partTwo = splitPost(post)
|
||||
# If the function does not return a post, splitting failed and we will skip this post.
|
||||
if not post:
|
||||
return "Too_long_post"
|
||||
return "skipped"
|
||||
# I wanted to make this part a little neater, but didn't get it to work and gave up. So here we are.
|
||||
# If post is both reply and has images it is posted as both a reply and with images (duh), if it's
|
||||
# a quote with images it's posted as that. If just either of the three it is posted as just that,
|
||||
@@ -235,9 +254,9 @@ def tweet(post, replyTo, images, postType):
|
||||
return id
|
||||
|
||||
# More or less the exact same function as for tweeting, but for tooting.
|
||||
def toot(post, replyTo, images):
|
||||
if not toggle.Mastodon:
|
||||
return;
|
||||
def toot(post, replyTo, images, doPost):
|
||||
if not toggle.Mastodon or not doPost:
|
||||
return "skipped";
|
||||
mediaIds = []
|
||||
# If post includes images, images are uploaded so that they can be included in the toot
|
||||
if images:
|
||||
|
||||
22
toggle.py
22
toggle.py
@@ -1,3 +1,23 @@
|
||||
# Enables/disables crossposting to twitter and mastodon
|
||||
# Accepted values: True, False
|
||||
Twitter = True
|
||||
Mastodon = True
|
||||
Logging = True
|
||||
# Enables/disables logging
|
||||
# Accepted values: True, False
|
||||
Logging = True
|
||||
# Sets default posting mode. True means all posts will be crossposted unless otherwise specified,
|
||||
# False means no posts will be crossposted unless explicitly specified. If no toggle (below) is specified
|
||||
# postDefault will be treated as True no matter what is set.
|
||||
# Accepted values: True, False
|
||||
postDefault = True
|
||||
# The function to select what posts are crossposted (mis)uses the language function in Bluesky.
|
||||
# Enter a language here and all posts will be filtered based on if that language is included
|
||||
# in the post.
|
||||
# E.g. if you set postDefault to True and add German ("de") as post toggle, all posts including
|
||||
# German as a language will be skipped. If postDefault is set to False, only posts including
|
||||
# german will be crossposted. You can use different languages as selectors for Mastodon
|
||||
# and Twitter. You can have both the actual language of the tweet, and the selector language
|
||||
# added to the tweet and it will still work.
|
||||
# Accepted values: Any language tag in quotes (https://en.wikipedia.org/wiki/IETF_language_tag)
|
||||
mastodonLang = ""
|
||||
twitterLang = ""
|
||||
Reference in New Issue
Block a user