Adding tweet ID to response messages.

pull/1/head
Ayush Sharma 2018-09-06 22:57:41 +05:30
parent 6e2709c47b
commit 996eb37c80
2 changed files with 18 additions and 12 deletions

View File

@ -34,13 +34,17 @@ Once it's all setup, just run the main file like this:
If all goes well, you'll see something like this:
```bash
Tweet-Toot | 2018-08-20 21:21:52 _info > getTweets => Fetching tweets for https://twitter.com/SarcasmMother.
Tweet-Toot | 2018-08-20 21:21:52 _info > __main__ => 20 tweets fetched.
Tweet-Toot | 2018-08-20 21:21:52 _info > tootTheTweet => 1031383086963994625 already tooted. Skipping.
Tweet-Toot | 2018-08-20 21:21:52 _info > tootTheTweet => 1031382821791657984 already tooted. Skipping.
Tweet-Toot | 2018-08-20 21:21:53 _info > tootTheTweet => OK (Response: {"id":"100583362607805661","created_at":"2018-08-20T15:51:53.284Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"en","uri":"https://botsin.space/users/motherofsarcasm/statuses/100583362607805661","content":"\u003cp\u003eYou are paid by how hard you are to replace. Not by how hard you work.\u003c/p\u003e","url":"https://botsin.space/@motherofsarcasm/100583362607805661","reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":false,"muted":false,"pinned":false,"reblog":null,"application":{"name":"TweetToot","website":""},"account":{"id":"58348","username":"motherofsarcasm","acct":"motherofsarcasm","display_name":"Mother Of Sarcasm","locked":false,"bot":true,"created_at":"2018-08-20T15:07:42.747Z","note":"\u003cp\u003eFOLLOWS YOU\u003c/p\u003e","url":"https://botsin.space/@motherofsarcasm","avatar":"https://files.botsin.space/accounts/avatars/000/058/348/original/658f78e1f07e94fa.jpg","avatar_static":"https://files.botsin.space/accounts/avatars/000/058/348/original/658f78e1f07e94fa.jpg","header":"https://botsin.space/headers/original/missing.png","header_static":"https://botsin.space/headers/original/missing.png","followers_count":0,"following_count":1,"statuses_count":3,"emojis":[],"fields":[{"name":"Name","value":"Mother Of Sarcasm"},{"name":"Owner","value":"ayushsharma22@mastodon.technology"},{"name":"Birdsite","value":"\u003ca href=\"https://twitter.com/SarcasmMother\" rel=\"me nofollow noopener\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003etwitter.com/SarcasmMother\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e"}]},"media_attachments":[],"mentions":[],"tags":[],"emojis":[]})
Tweet-Toot | 2018-08-20 21:21:53 _info > __main__ => Tooted "You are paid by how hard you are to replace. Not by how hard you work."
Tweet-Toot | 2018-08-20 21:21:53 _info > __main__ => Tooting less is tooting more. Sleeping...
Tweet-Toot | 2018-09-06 22:56:01 _info > getTweets => Fetched tweets for https://twitter.com/SarcasmMother.
Tweet-Toot | 2018-09-06 22:56:01 _info > __main__ => 20 tweets fetched.
Tweet-Toot | 2018-09-06 22:56:01 _info > tootTheTweet() => Tweet 1031642593594028032 was already posted. Skipping...
Tweet-Toot | 2018-09-06 22:56:01 _info > tootTheTweet() => Tweet 1031640753187958786 was already posted. Skipping...
Tweet-Toot | 2018-09-06 22:56:01 _info > tootTheTweet() => New tweet 1031632691500789761 => "In attempt to convince people society would have been better if humanity had never found religion, a time traveler kills anyone who begins to develop a form of faith.
He goes back to the present and finds that people now worship a god who travels through time".
Tweet-Toot | 2018-09-06 22:56:02 _info > tootTheTweet() => OK. Posted tweet 1031632691500789761to Mastodon.
Tweet-Toot | 2018-09-06 22:56:02 _info > tootTheTweet() => Response: {"id":"100679992085669673","created_at":"2018-09-06T17:26:02.245Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"en","uri":"https://botsin.space/users/motherofsarcasm/statuses/100679992085669673","content":"\u003cp\u003eIn attempt to convince people society would have been better if humanity had never found religion, a time traveler kills anyone who begins to develop a form of faith.\u003cbr /\u003eHe goes back to the present and finds that people now worship a god who travels through time\u003c/p\u003e","url":"https://botsin.space/@motherofsarcasm/100679992085669673","replies_count":0,"reblogs_count":0,"favourites_count":0,"favourited":false,"reblogged":false,"muted":false,"pinned":false,"reblog":null,"application":{"name":"TweetToot","website":""},"account":{"id":"58348","username":"motherofsarcasm","acct":"motherofsarcasm","display_name":"Mother Of Sarcasm","locked":false,"bot":true,"created_at":"2018-08-20T15:07:42.747Z","note":"\u003cp\u003eFOLLOWS YOU\u003c/p\u003e","url":"https://botsin.space/@motherofsarcasm","avatar":"https://files.botsin.space/accounts/avatars/000/058/348/original/658f78e1f07e94fa.jpg","avatar_static":"https://files.botsin.space/accounts/avatars/000/058/348/original/658f78e1f07e94fa.jpg","header":"https://botsin.space/headers/original/missing.png","header_static":"https://botsin.space/headers/original/missing.png","followers_count":0,"following_count":1,"statuses_count":6,"emojis":[],"fields":[{"name":"Name","value":"Mother Of Sarcasm"},{"name":"Owner","value":"ayushsharma22@mastodon.technology"},{"name":"Twitter Relay","value":"\u003ca href=\"https://twitter.com/SarcasmMother\" rel=\"me nofollow noopener\" target=\"_blank\"\u003e\u003cspan class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003etwitter.com/SarcasmMother\u003c/span\u003e\u003cspan class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e"}]},"media_attachments":[],"mentions":[],"tags":[],"emojis":[]}
Tweet-Toot | 2018-09-06 22:56:02 _info > __main__ => Tooted "In attempt to convince people society would have been better if humanity had never found religion, a time traveler kills anyone who begins to develop a form of faith.
He goes back to the present and finds that people now worship a god who travels through time"
Tweet-Toot | 2018-09-06 22:56:02 _info > __main__ => Tooting less is tooting more. Sleeping...
```
## Things to remember

View File

@ -65,6 +65,8 @@ def tootTheTweet(tweet):
host_instance = helpers._config('toots.host_instance')
token = helpers._config('toots.app_secure_token')
tweet_id = tweet['id']
if not host_instance:
helpers._error('tootTheTweet() => Your host Mastodon instance URL (' + host_instance + ') was incorrect.')
@ -79,7 +81,7 @@ def tootTheTweet(tweet):
headers = {}
headers['Authorization'] = 'Bearer ' + token
headers['Idempotency-Key'] = tweet['id']
headers['Idempotency-Key'] = tweet_id
data = {}
data['status'] = tweet['text']
@ -89,7 +91,7 @@ def tootTheTweet(tweet):
tweet_check_file = Path(tweet_check_file_path)
if tweet_check_file.is_file():
helpers._info('tootTheTweet() => This tweet has already been posted. Skipping...')
helpers._info('tootTheTweet() => Tweet ' + tweet_id + ' was already posted. Skipping...')
return False
@ -99,21 +101,21 @@ def tootTheTweet(tweet):
tweet_check.write(tweet['text'])
tweet_check.close()
helpers._info('tootTheTweet() => Caching new tweet.')
helpers._info('tootTheTweet() => New tweet ' + tweet_id + ' => "' + tweet['text'] + '".')
response = requests.post(
url=host_instance + '/api/v1/statuses', data=data, headers=headers)
if response.status_code == 200:
helpers._info('tootTheTweet() => OK. Posted tweet to Mastodon.')
helpers._info('tootTheTweet() => OK. Posted tweet ' + tweet_id + 'to Mastodon.')
helpers._info('tootTheTweet() => Response: ' + response.text)
return True
else:
helpers._info('tootTheTweet() => FAIL. Could not post tweet to Mastodon.')
helpers._info('tootTheTweet() => FAIL. Could not post tweet ' + tweet_id + 'to Mastodon.')
helpers._info('tootTheTweet() => Response: ' + response.text)
return False