Compare commits

...

5 Commits

Author SHA1 Message Date
Lasse Edfast 9467b60abd
Update README.md 3 years ago
Lasse Studion 244de5578b Reply to private 3 years ago
Lasse Studion 7acb9c95e4 Return private 3 years ago
Lasse Studion a9298d5bf2 Added answer to private profile. 3 years ago
Lasse Studion dfb09a7255 Added reply_to_private() 3 years ago
  1. 10
      README.md
  2. 18
      answering_machine.py
  3. 9
      collect_followers.py
  4. 7
      twitter_api.py

@ -1,7 +1,13 @@
Simple script to find out if Twitter accounts one is following are on Mastodon. Identifying mastodon handles from Twitter accounts' bio, adding them to a CSV file, uploading that file to Dropbox and then answering with a link to a shared Dropbox file.
_To run this you need:_
_To run this you'll need:_
- [Twitter API credentials](https://developer.twitter.com/en/docs/twitter-api)
- [Dropbox API credentials](https://www.dropbox.com/developers/)
The project is in development and I will fill out this readme later.
When you have created a bot accound and got your keys for Twitter and Dropbox API, and Python on installed, run
```
pip install -r requirements.txt
```
and then twitterbot.py. This will set up a json-file with credentials (config.json) and start the bot.
Please keep in mind that Twitter tends to lock down anything related to Mastodon when you're writing your bio and tweets. [I didn't in my first attempt](https://twitter.com/lasseedfast/status/1604850583940354049)...

@ -12,16 +12,20 @@ def main(tweet):
t_username = tweet["t_username"]
followings = collect_followers.get_followings(t_username)
followings = collect_followers.update_db(followings)
if followings == 'private':
twitter.reply_to_private(tweet["tweet_id"], t_username)
else:
followings = collect_followers.update_db(followings)
filename = collect_followers.export_followings(followings, t_username)
filename = collect_followers.export_followings(followings, t_username)
# Share to dropbox
dropbox = dropbox_api.API()
shared_file_url = dropbox.upload_file(filename)
# Share to dropbox
dropbox = dropbox_api.API()
shared_file_url = dropbox.upload_file(filename)
# Reply to tweet with url.
twitter.reply_with_url(tweet["tweet_id"], shared_file_url, t_username)
# Reply to tweet with url.
twitter.reply_with_url(tweet["tweet_id"], shared_file_url, t_username)
sql = f'DELETE FROM queue WHERE t_username == "{t_username}"'
db.commit(sql)

@ -35,6 +35,13 @@ def get_followings(username):
f"https://api.twitter.com/2/users/{id}/following",
params = {'pagination_token': pagination_token, "max_results": 1000, 'user.fields': 'description'}
)
if 'errors' in result:
try:
error_title = result['errors'][0]['title']
if error_title == 'Authorization Error':
return 'private'
except:
break
if 'data' not in result:
break
# Append data to list json_response_list.
@ -52,7 +59,7 @@ def update_db(followings):
""" Update Mastodon username DB. Returns the followings who has a Mastodon hansle in their bio. """
# Create SQL-query.
l = []
tweeters_with_mastodon = ['lasseedfast']
tweeters_with_mastodon = []
for i in followings:
m_username = extract_mastodon_handle(i["description"].replace('"', "'")) # Can't be double quotes when sending to SQL.
if m_username:

@ -100,4 +100,9 @@ class API:
def reply_with_url(self, tweet_id, url, username):
params = {"reply": {"in_reply_to_tweet_id": str(tweet_id)}, "text": f"Hi {username}! Download a list of Mastodon users that you are following on Twitter: {url} Take that csv-file and import in Mastodon (Settings > Import)."}
self.post_tweet(params=params)
self.post_tweet(params=params)
def reply_to_private(self, tweet_id, username):
""" Reply to private profiles. """
params = {"reply": {"in_reply_to_tweet_id": str(tweet_id)}, "text": f"Hi {username}! Because you have a private I can't see what profiles you are following."}
self.post_tweet(params=params)
Loading…
Cancel
Save