Dereflinks

This commit is contained in:
Homer S. 2018-02-05 21:09:50 +00:00
parent a4afd01146
commit 5548bd9349
1 changed files with 13 additions and 2 deletions

View File

@ -4,7 +4,7 @@ from mastodon import Mastodon
from dateutil.parser import parse
import tweepy, wget, os, time, json
settings_path = '/home/user/mastobot/settings.json'
settings_path = './settings.json'
with open(settings_path, 'r+') as fp:
settings = json.load(fp)
@ -14,7 +14,6 @@ mastodon_instance = settings["mastodon"]["instance"]
clientcreds = settings["mastodon"]["clientcreds"]
transitions = settings["transitions"]
consumer_key = settings["twitter"]["consumer_key"]
consumer_secret = settings["twitter"]["consumer_secret"]
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_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:
tweet_text = status.full_text
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
# 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")
@ -97,6 +107,7 @@ for account in transitions:
# Output text to stdout respect. post it to Mastodon.
print(mastodon_text)
# mastodon.status_post(mastodon_text, None, masto_media, True)
time.sleep(2)