Tweet echo works. Yay.
This commit is contained in:
parent
c7a90f1e80
commit
dff97c5ce8
4 changed files with 65 additions and 8 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,5 +1,8 @@
|
|||
.vscode/*
|
||||
.pyenv/*
|
||||
__pycache__/*
|
||||
.empty/*
|
||||
keys*
|
||||
users*
|
||||
*_tweets*
|
||||
*.secret
|
Binary file not shown.
22
mastodon_publisher.py
Normal file
22
mastodon_publisher.py
Normal 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.'
|
||||
)
|
|
@ -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,11 +23,22 @@ 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
|
||||
|
||||
# TODO: Don't do while(True). Use another safer method.
|
||||
|
@ -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'])
|
||||
|
||||
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
|
||||
|
|
Reference in a new issue