Skip to content

Instantly share code, notes, and snippets.

@zitterbewegung
Created November 22, 2022 18:51
Show Gist options
  • Save zitterbewegung/61902bc53c8d0cd02ad86582e1e8c395 to your computer and use it in GitHub Desktop.
Save zitterbewegung/61902bc53c8d0cd02ad86582e1e8c395 to your computer and use it in GitHub Desktop.
Simple script to upload your twitter tweets from a twitter.js file to a mastodon server. NOTE: only upload around 600 at a time or contact the server owners or you can be banned.
#!/usr/bin/env python3
from mastodon import Mastodon
import re
import json
def main(api_base_url: str, client_id: str, secret: str,username: str, password:str, tweets= 'tweets.js': str, listed=True: bool)-> str:
Mastodon.create_app(
'pytooterapp',
api_base_url = api_base_url,
to_file = secret,
)
mastodon = Mastodon(
access_token = secret,
api_base_url = api_base_url,
)
mastodon.log_in(
username,
password,
to_file = secret,
)
data = '/content/tweets.js'
tweet_file = open(data, 'r')
tweet_with_js = tweet_file.read()
result = re.sub(r'[a-z]*.[A-Z]*.[a-z]*.[a-z]*. = \[', "[", tweet_with_js)
tweets = json.loads(result)
tweets_text = []
for tweet in tweets:
tweets_text.append(tweet['tweet']['full_text'])
for tweet in tweets_text:
mastodon.toot(tweet, unlisted=listed)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment