Skip to content

Instantly share code, notes, and snippets.

@p3t3r67x0
Last active December 19, 2017 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save p3t3r67x0/bfdb5cc0aab0ed5880856ed3abed2bb1 to your computer and use it in GitHub Desktop.
Save p3t3r67x0/bfdb5cc0aab0ed5880856ed3abed2bb1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -!- coding:utf-8 -!-
import os
from twython import Twython
from twython.exceptions import TwythonError
def get_secrets():
path = os.path.abspath(os.path.join(os.path.dirname(__file__), '.secret'))
lines = load_document(path)
return [l.strip() for l in lines[0:4]]
def load_document(filename):
try:
with open(filename, 'rb') as f:
return f.readlines()
except IOError as e:
print e
sys.exit(1)
def execute_command(action, twitter, query):
result = twitter.search(q=query, result_type='resent', count=20)
for i in result['statuses']:
try:
if action == 'favorite':
r = twitter.create_favorite(id= i['id'])
elif action == 'retweet':
r = twitter.retweet(id= i['id'])
print u'[I] Favorited: {} with id: {}'.format(r['text'], r['id'])
except TwythonError as e:
print u'[E] {}'.format(e)
def authenticate():
secret = get_secrets()
return Twython(secret[0], secret[1], secret[2], secret[3])
def main():
twitter = authenticate()
query_retweet = ['ssl intercept', '#infosec #hash', '#password #cracking']
query_favorite = ['#infosec #pentest', '#cve #infosec']
for query in query_retweet:
execute_command('retweet', twitter, query)
for query in query_favorite:
execute_command('favorite', twitter, query)
if __name__ == '__main__':
main()
@p3t3r67x0
Copy link
Author

The .secret file should look like this..

<api_key>
<api_secret>
<oauth_key>
<oauth_secret>

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