From 5548bd9349feb6d3467d4b94f55f3c2991c853c0 Mon Sep 17 00:00:00 2001 From: Homer S Date: Mon, 5 Feb 2018 21:09:50 +0000 Subject: [PATCH] Dereflinks --- mastobot.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mastobot.py b/mastobot.py index cb8ec91..a341c25 100644 --- a/mastobot.py +++ b/mastobot.py @@ -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,9 +84,20 @@ 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. @@ -96,6 +106,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)