Dereflinks
This commit is contained in:
parent
a4afd01146
commit
5548bd9349
15
mastobot.py
15
mastobot.py
|
@ -4,7 +4,7 @@ from mastodon import Mastodon
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
import tweepy, wget, os, time, json
|
import tweepy, wget, os, time, json
|
||||||
|
|
||||||
settings_path = '/home/user/mastobot/settings.json'
|
settings_path = './settings.json'
|
||||||
|
|
||||||
with open(settings_path, 'r+') as fp:
|
with open(settings_path, 'r+') as fp:
|
||||||
settings = json.load(fp)
|
settings = json.load(fp)
|
||||||
|
@ -14,7 +14,6 @@ mastodon_instance = settings["mastodon"]["instance"]
|
||||||
clientcreds = settings["mastodon"]["clientcreds"]
|
clientcreds = settings["mastodon"]["clientcreds"]
|
||||||
transitions = settings["transitions"]
|
transitions = settings["transitions"]
|
||||||
|
|
||||||
|
|
||||||
consumer_key = settings["twitter"]["consumer_key"]
|
consumer_key = settings["twitter"]["consumer_key"]
|
||||||
consumer_secret = settings["twitter"]["consumer_secret"]
|
consumer_secret = settings["twitter"]["consumer_secret"]
|
||||||
access_token_key = settings["twitter"]["access_token_key"]
|
access_token_key = settings["twitter"]["access_token_key"]
|
||||||
|
@ -85,10 +84,21 @@ for account in transitions:
|
||||||
tweet_text = status._json['retweeted_status']['full_text']
|
tweet_text = status._json['retweeted_status']['full_text']
|
||||||
tweet_origin = status._json['retweeted_status']['id_str']
|
tweet_origin = status._json['retweeted_status']['id_str']
|
||||||
|
|
||||||
|
# derefering twitter short urls to expanded
|
||||||
|
for url in status._json['retweeted_status']['entities']["urls"]:
|
||||||
|
|
||||||
|
tweet_text = tweet_text.replace(url["url"], url["expanded_url"])
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
tweet_text = status.full_text
|
tweet_text = status.full_text
|
||||||
tweet_origin = status.id_str
|
tweet_origin = status.id_str
|
||||||
|
|
||||||
|
# derefering twitter short urls to expanded
|
||||||
|
for url in status.entities["urls"]:
|
||||||
|
|
||||||
|
tweet_text = tweet_text.replace(url["url"], url["expanded_url"])
|
||||||
|
|
||||||
mastodon_text += tweet_text
|
mastodon_text += tweet_text
|
||||||
# Add info about source and a related link to toot.
|
# Add info about source and a related link to toot.
|
||||||
mastodon_text += "\n\nPosted " + parse(str(status.created_at)).strftime("%d. %B %Y - %H:%M on Twitter")
|
mastodon_text += "\n\nPosted " + parse(str(status.created_at)).strftime("%d. %B %Y - %H:%M on Twitter")
|
||||||
|
@ -97,6 +107,7 @@ for account in transitions:
|
||||||
# Output text to stdout respect. post it to Mastodon.
|
# Output text to stdout respect. post it to Mastodon.
|
||||||
print(mastodon_text)
|
print(mastodon_text)
|
||||||
|
|
||||||
|
|
||||||
# mastodon.status_post(mastodon_text, None, masto_media, True)
|
# mastodon.status_post(mastodon_text, None, masto_media, True)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue