From dff97c5ce8800deb4c231aaacc36f3354bd03792 Mon Sep 17 00:00:00 2001 From: Alex Huddleston Date: Sun, 17 Feb 2019 01:38:53 -0600 Subject: [PATCH] Tweet echo works. Yay. --- .gitignore | 5 ++- __pycache__/tweet_converter.cpython-37.pyc | Bin 804 -> 0 bytes mastodon_publisher.py | 22 ++++++++++ tweet_echoer.py | 46 +++++++++++++++++---- 4 files changed, 65 insertions(+), 8 deletions(-) delete mode 100644 __pycache__/tweet_converter.cpython-37.pyc create mode 100644 mastodon_publisher.py diff --git a/.gitignore b/.gitignore index f2d8e24..7a723c1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ .vscode/* .pyenv/* +__pycache__/* +.empty/* keys* users* -*_tweets* \ No newline at end of file +*_tweets* +*.secret \ No newline at end of file diff --git a/__pycache__/tweet_converter.cpython-37.pyc b/__pycache__/tweet_converter.cpython-37.pyc deleted file mode 100644 index fc119a8cd78d2eec4ab3aacf5068b01b44e06954..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 804 zcmb7C&2H2%5FR^;H@oUq6_g4t2yx4Sh69HRp{fF|R0tMz8-bz_ySr(36KXs3N7+;1 z-Ur~Yd*sd=@D{#u>ML+!>qEP|A@J|KM%OKAXxP|e5Q8*@7TPl{Qq!-^8I+IULK zgcUr+XnMI6h~{agWyg+UqRcBUOlXn15XyKXB<&v5lSyis&00GMK}u)3R*|1DH(Hs# z6gdLZHtklmZjXVBUqRl)DL)^^Z%~Vh)i~qT$(DW;j|v^Xs3*F3S-+26Z<<%-M-(jN z=7%%0+GZ`a{g3J~I-ox8RZ0mXq1zjzM>af0{;n)LD7lRt_dR(F(Yq0G(aHM5t>c{u PpG+%WPsFyHW{3R(N0i76 diff --git a/mastodon_publisher.py b/mastodon_publisher.py new file mode 100644 index 0000000..6a88b3f --- /dev/null +++ b/mastodon_publisher.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +# encoding: utf-8 + +''' +This is literally just straight copied from https://mastodonpy.readthedocs.io/en/latest/ +but yeah it's gonna eventually be the framework for posting here... +Just right now it was a proof of concept for me. +TODO: Clean this stuff up. +''' + +from mastodon import Mastodon + +mastodon = Mastodon( + access_token = '/Users/shadow8t4/.secrets/mastodon_api_access_token.secret', + api_base_url = 'https://masto.werefoxsoftware.com' +) + +mastodon.status_post( + 'This is a test post!', + visibility='public', + spoiler_text='I am testing this.' +) \ No newline at end of file diff --git a/tweet_echoer.py b/tweet_echoer.py index fa48b4c..7097e5c 100644 --- a/tweet_echoer.py +++ b/tweet_echoer.py @@ -3,6 +3,7 @@ # Tweet echoing works. I just need this to be refactored into something more useful... from tweet_converter import convert_tweets +from mastodon import Mastodon from time import sleep import tweepy @@ -22,10 +23,21 @@ def echo_recent_tweets(screen_name): access_key = f.readline().rstrip() access_secret = f.readline().rstrip() - # Authorize twitter, initialize tweepy + # Authorize Twitter, initialize tweepy auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access_secret) api = tweepy.API(auth) + + # Authorize Mastodon, set api base + # TODO: Modularize this + mastodon = Mastodon( + access_token = '/Users/shadow8t4/.secrets/mastodon_api_access_token.secret', + api_base_url = 'https://masto.werefoxsoftware.com' + ) + + # In case I am just now starting up script, don't make 10 posts. + # TODO: Fix this later. + fresh_start = True last_tweet = 0 @@ -36,10 +48,11 @@ def echo_recent_tweets(screen_name): new_tweets = api.user_timeline(screen_name = screen_name,count=10,tweet_mode = 'extended') recent_tweets = [] + outtweets = [] # Only bother processing new tweets. for tweet in new_tweets: - if(tweet.id > last_tweet): + if(int(tweet.id) > last_tweet): recent_tweets.append(tweet) # Only do this if there are new tweets. @@ -47,12 +60,31 @@ def echo_recent_tweets(screen_name): outtweets = convert_tweets(recent_tweets) last_tweet = int(outtweets[len(outtweets) - 1]['id']) - # Debugging purposes... - # TODO: Clean this up probably. - for t in outtweets: - print(t['date'] + '\t' + t['text']) + if(not fresh_start): + # Debugging purposes... + # TODO: Clean this up probably. + for t in outtweets: + ''' + Mastodon.status_post( + status, + in_reply_to_id=None, + media_ids=None, + sensitive=False, + visibility=None, + spoiler_text=None, + language=None, + idempotency_key=None) + ''' + + mastodon.status_post( + t['text'][1:-1], + visibility='public', + spoiler_text='Twitter Echo, I\'m not on Masto rn.' + ) + print(t['date'] + '\t' + t['text']) sleep(30) + fresh_start = False # TODO: Stop reading users from a file, unnecessary. if __name__ == '__main__': @@ -60,7 +92,7 @@ if __name__ == '__main__': for l in f: echo_recent_tweets(l.rstrip()) -# Clean these up lmao +# Clean these up ''' #write the csv