Compare commits

..

No commits in common. '9467b60abd34b2104b98af4ce5a8bf467c970645' and '0ab9f122dab7af6cc16893067e92284a565cc7a5' have entirely different histories.

  1. 10
      README.md
  2. 18
      answering_machine.py
  3. 9
      collect_followers.py
  4. 5
      twitter_api.py

@ -1,13 +1,7 @@
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'll need:_
_To run this you need:_
- [Twitter API credentials](https://developer.twitter.com/en/docs/twitter-api)
- [Dropbox API credentials](https://www.dropbox.com/developers/)
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)...
The project is in development and I will fill out this readme later.

@ -12,20 +12,16 @@ def main(tweet):
t_username = tweet["t_username"]
followings = collect_followers.get_followings(t_username)
if followings == 'private':
twitter.reply_to_private(tweet["tweet_id"], t_username)
followings = collect_followers.update_db(followings)
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,13 +35,6 @@ 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.
@ -59,7 +52,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 = []
tweeters_with_mastodon = ['lasseedfast']
for i in followings:
m_username = extract_mastodon_handle(i["description"].replace('"', "'")) # Can't be double quotes when sending to SQL.
if m_username:

@ -101,8 +101,3 @@ class API:
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)
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