Compare commits

...

3 Commits

Author SHA1 Message Date
robin f01289c6c4 Add Tweepy 2022-05-22 14:16:12 +02:00
robin da26a740b7 Update with Tweepy 2022-05-22 14:13:57 +02:00
robin f76114cc94 Add twitter_auth_keys 2022-05-22 14:08:54 +02:00
3 changed files with 87 additions and 1 deletions

View File

@ -1 +1,23 @@
# matobi - Mastodon to Birdsite
Robot to mirror Mastodon posts to Twitter
## install
```bash
apt install python3-mastodon
apt install python3-tweepy
git clone https://git.grml.de/robin/python-matobi.git
```
If your repo for Tweepy is too old you might have to install it from git.
https://github.com/tweepy/tweepy lists different options for this.
## setup
```bash
cd python-matobi
cp settings.py.sample settings.py
```
Edit settings.py for your setup
## run
Run once
```bash
python3 main.py
```

50
main.py Normal file
View File

@ -0,0 +1,50 @@
from settings import *
from mastodon import Mastodon
from os.path import exists
import tweepy
def main():
if not exists(app_path):
Mastodon.create_app(
bot_name,
api_base_url = api_url,
to_file = app_path
)
if not exists(user_path):
mastodon = Mastodon(
client_id = app_path,
api_base_url = api_url
)
mastodon.log_in(
account_name,
account_password,
to_file = user_path
)
mastodon_api = Mastodon(
access_token = user_path,
api_base_url = api_url
)
mastodon_user = mastodon_api.account_verify_credentials()
# auth = tweepy.OAuthHandler(
# twitter_auth_keys['consumer_key'],
# twitter_auth_keys['consumer_secret']
# )
# auth.set_access_token(
# twitter_auth_keys['access_token'],
# twitter_auth_keys['access_token_secret']
# )
# twitter_api = tweepy.API(auth)
twitter_api = tweepy.Client(
consumer_key = twitter_auth_keys['consumer_key'],
consumer_secret = twitter_auth_keys['consumer_secret'],
access_token = twitter_auth_keys['access_token'],
access_token_secret = twitter_auth_keys['access_token_secret']
)
print(twitter_api.get_me())
timeline = mastodon_api.account_statuses(mastodon_user,exclude_replies=True)
for toot in timeline:
if(toot.visibility == 'public' and toot.account.id == mastodon_user.id and not toot.reblog):
print(toot)
#print(timeline)
if __name__ == "__main__":
main()

14
settings.py.sample Normal file
View File

@ -0,0 +1,14 @@
log_path = "./store/" # Stores toot data
data_path = "./data/" # Make sure this directory is not accessible for other users or per web
app_path = f"{data_path}.htapp.data" # Store app secret
user_path = f"{data_path}.htuser.data" # Store user secret
api_url = 'https://mastodon.grml.de' # Mastodon Server URL
bot_name = 'grmlmatobi' # Botname
account_name = 'matobi' # Mastodon-Account name
account_password = 'supersecret' # Mastodon-Account password
twitter_auth_keys = { # Twitter API
"consumer_key" : "REPLACE_THIS_WITH_YOUR_CONSUMER_KEY",
"consumer_secret" : "REPLACE_THIS_WITH_YOUR_CONSUMER_SECRET",
"access_token" : "REPLACE_THIS_WITH_YOUR_ACCESS_TOKEN",
"access_token_secret" : "REPLACE_THIS_WITH_YOUR_ACCESS_TOKEN_SECRET"
}