Skip to content

Instantly share code, notes, and snippets.

@miyachin
Last active March 14, 2019 13:12
Show Gist options
  • Save miyachin/f6a07f4f90aec5fb1ef726cb11dfe343 to your computer and use it in GitHub Desktop.
Save miyachin/f6a07f4f90aec5fb1ef726cb11dfe343 to your computer and use it in GitHub Desktop.
import tweepy
import sys
CONSUMER_KEY = 'xxxxxxxxxxxxxxxxxxxx'
CONSUMER_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
ACCESS_TOKEN = 'xxxxxxxxxxxxxxxxxxxx'
ACCESS_SECRET = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(auth)
def execLike(keyword, threshold):
search_results = api.search(q=keyword, lang='ja', count=100)
for result in search_results:
if result.favorite_count > threshold and result.in_reply_to_screen_name is None:
twi_id = result.id
try:
api.create_favorite(twi_id)
except Exception as e:
print(e)
if __name__ == '__main__':
keyword = sys.argv[1]
threshold = int(sys.argv[2])
execLike(keyword, threshold)
@miyachin
Copy link
Author

miyachin commented Mar 11, 2019

How To Run

python favorite_bot.py "{キーワード}" {ツイートがすでに獲得しているいいねの下限} 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment