Merge branch 'dereflinks' into 'master'
Dereflinks See merge request homer77/mastobot!3
This commit is contained in:
commit
c2510cfe47
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,9 +84,20 @@ 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.
|
||||||
|
@ -96,6 +106,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