Tweet echo works. Yay.

This commit is contained in:
Alex Huddleston 2019-02-17 01:38:53 -06:00
parent c7a90f1e80
commit dff97c5ce8
4 changed files with 65 additions and 8 deletions

5
.gitignore vendored
View file

@ -1,5 +1,8 @@
.vscode/* .vscode/*
.pyenv/* .pyenv/*
__pycache__/*
.empty/*
keys* keys*
users* users*
*_tweets* *_tweets*
*.secret

22
mastodon_publisher.py Normal file
View file

@ -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.'
)

View file

@ -3,6 +3,7 @@
# Tweet echoing works. I just need this to be refactored into something more useful... # Tweet echoing works. I just need this to be refactored into something more useful...
from tweet_converter import convert_tweets from tweet_converter import convert_tweets
from mastodon import Mastodon
from time import sleep from time import sleep
import tweepy import tweepy
@ -22,10 +23,21 @@ def echo_recent_tweets(screen_name):
access_key = f.readline().rstrip() access_key = f.readline().rstrip()
access_secret = f.readline().rstrip() access_secret = f.readline().rstrip()
# Authorize twitter, initialize tweepy # Authorize Twitter, initialize tweepy
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret) auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth) 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 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') new_tweets = api.user_timeline(screen_name = screen_name,count=10,tweet_mode = 'extended')
recent_tweets = [] recent_tweets = []
outtweets = []
# Only bother processing new tweets. # Only bother processing new tweets.
for tweet in new_tweets: for tweet in new_tweets:
if(tweet.id > last_tweet): if(int(tweet.id) > last_tweet):
recent_tweets.append(tweet) recent_tweets.append(tweet)
# Only do this if there are new tweets. # Only do this if there are new tweets.
@ -47,12 +60,31 @@ def echo_recent_tweets(screen_name):
outtweets = convert_tweets(recent_tweets) outtweets = convert_tweets(recent_tweets)
last_tweet = int(outtweets[len(outtweets) - 1]['id']) last_tweet = int(outtweets[len(outtweets) - 1]['id'])
# Debugging purposes... if(not fresh_start):
# TODO: Clean this up probably. # Debugging purposes...
for t in outtweets: # TODO: Clean this up probably.
print(t['date'] + '\t' + t['text']) 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) sleep(30)
fresh_start = False
# TODO: Stop reading users from a file, unnecessary. # TODO: Stop reading users from a file, unnecessary.
if __name__ == '__main__': if __name__ == '__main__':
@ -60,7 +92,7 @@ if __name__ == '__main__':
for l in f: for l in f:
echo_recent_tweets(l.rstrip()) echo_recent_tweets(l.rstrip())
# Clean these up lmao # Clean these up
''' '''
#write the csv #write the csv