<commit_before>#!/usr/bin/env python

import twitter
from requests_oauthlib import OAuth1Session
import webbrowser, os, sys, time

REQUEST_TOKEN_URL = 'https://api.twitter.com/oauth/request_token'
ACCESS_TOKEN_URL = 'https://api.twitter.com/oauth/access_token'
AUTHORIZATION_URL = 'https://api.twitter.com/oauth/authorize'
SIGNIN_URL = 'https://api.twitter.com/oauth/authenticate'


def get_access_token(consumer_key, consumer_secret):
    oauth_client = OAuth1Session(consumer_key, client_secret=consumer_secret)

    print 'Requesting temp token from Twitter'

    try:
        resp = oauth_client.fetch_request_token(REQUEST_TOKEN_URL)
    except ValueError, e:
        print 'Invalid respond from Twitter requesting temp token: %s' % e
        return
    url = oauth_client.authorization_url(AUTHORIZATION_URL)

    print ''
    print 'I will try to start a browser to visit the following Twitter page'
    print 'if a browser will not start, copy the URL to your browser'
    print 'and retrieve the pincode to be used'
    print 'in the next step to obtaining an Authentication Token:'
    print ''
    print url
    print ''

    webbrowser.open(url)
    print "Enter code prompted after leaving twitter."
    pincode = raw_input("> ")

    print ''
    print 'Generating and signing request for an access token'
    print ''

    oauth_client = OAuth1Session(consumer_key, client_secret=consumer_secret,
                                 resource_owner_key=resp.get('oauth_token'),
                                 resource_owner_secret=resp.get('oauth_token_secret'),
                                 verifier=pincode
    )
    try:
        resp = oauth_client.fetch_access_token(ACCESS_TOKEN_URL)
    except ValueError, e:
        print 'Invalid respond from Twitter requesting access token: %s' % e
        return

    # print 'Your Twitter Access Token key: %s' % resp.get('oauth_token')
    # print '          Access Token secret: %s' % resp.get('oauth_token_secret')
    print "Authenticated"
    return {'access_token': resp.get('oauth_token'), 'access_secret': resp.get('oauth_token_secret')}

def get_attack_type():
    print "How should we attack? (fav, RT, or mention)"
    attack = raw_input("> ").upper()
    return 

def get_user(api):
    print "Enter the username of who you'd like to attack."
    user = raw_input("> ")
    return api.GetUser(user)

def init_attack(api):
    user = get_user(api)
    timeline = api.GetUserTimeline(user)
    attack_type = get_attack_type()
    if attack_type == "FAV":
        fav_attack(api=api, u=user, tl=timeline)
    elif attack_type == "RT":
        rt_attack(api=api, u=user, tl=timeline)
    elif attack_type == "MENTION":
        mention_attack(api=api, u=user, tl=timeline)
    else:
        print "Unknown input."
        init_attack()

def fav_attack(u, tl):
    print [s.text for s in tl]

def main():
    consumer_key = 'p0k5TwqEaNspElJkQCsD33Khn'
    consumer_secret = '<KEY>'
    tokens = get_access_token(consumer_key, consumer_secret)

    api = twitter.Api(consumer_key=consumer_key, 
            consumer_secret=consumer_secret,
            access_token_key=tokens['access_token'],
            access_token_secret=tokens['access_secret'])

    init_attack(api)

if __name__ == "__main__":
    main()<commit_msg>Changed consumer_secret to be supplied as argument for safer testing<commit_after>#!/usr/bin/env python

# Shitty code, deal with it. (atleast it's better than Instagram.py)

import twitter
from requests_oauthlib import OAuth1Session
import webbrowser, os, sys, time

REQUEST_TOKEN_URL = 'https://api.twitter.com/oauth/request_token'
ACCESS_TOKEN_URL = 'https://api.twitter.com/oauth/access_token'
AUTHORIZATION_URL = 'https://api.twitter.com/oauth/authorize'
SIGNIN_URL = 'https://api.twitter.com/oauth/authenticate'


def get_access_token(consumer_key, consumer_secret):
    oauth_client = OAuth1Session(consumer_key, client_secret=consumer_secret)

    print 'Requesting temp token from Twitter'

    try:
        resp = oauth_client.fetch_request_token(REQUEST_TOKEN_URL)
    except ValueError, e:
        print 'Invalid respond from Twitter requesting temp token: %s' % e
        return
    url = oauth_client.authorization_url(AUTHORIZATION_URL)

    print ''
    print 'I will try to start a browser to visit the following Twitter page'
    print 'if a browser will not start, copy the URL to your browser'
    print 'and retrieve the pincode to be used'
    print 'in the next step to obtaining an Authentication Token:'
    print ''
    print url
    print ''

    webbrowser.open(url)
    print "Enter code prompted after leaving twitter."
    pincode = raw_input("> ")

    print ''
    print 'Generating and signing request for an access token'
    print ''

    oauth_client = OAuth1Session(consumer_key, client_secret=consumer_secret,
                                 resource_owner_key=resp.get('oauth_token'),
                                 resource_owner_secret=resp.get('oauth_token_secret'),
                                 verifier=pincode
    )
    try:
        resp = oauth_client.fetch_access_token(ACCESS_TOKEN_URL)
    except ValueError, e:
        print 'Invalid respond from Twitter requesting access token: %s' % e
        return

    # print 'Your Twitter Access Token key: %s' % resp.get('oauth_token')
    # print '          Access Token secret: %s' % resp.get('oauth_token_secret')
    print "Authenticated"
    return {'access_token': resp.get('oauth_token'), 'access_secret': resp.get('oauth_token_secret')}

def get_attack_type():
    print "How should we attack? (fav, RT, or mention)"
    return raw_input("> ").upper()

def get_user():
    print "Enter the username of who you'd like to attack."
    return raw_input("> ")

def init_attack(api):
    user = get_user()
    print "How many tweets should be fetched?"
    tweet_limit = raw_input("> ")
    timeline = api.GetUserTimeline(screen_name=user, count=tweet_limit, include_rts=True)
    attack_type = get_attack_type()
    if attack_type == "FAV":
        fav_attack(api=api, u=user, tl=timeline)
    elif attack_type == "RT":
        rt_attack(api=api, u=user, tl=timeline)
    elif attack_type == "MENTION":
        mention_attack(api=api, u=user, tl=timeline)
    else:
        print "Unknown input."
        init_attack(api)

def fav_attack(api, u, tl):
    for s in tl:
        if not s.favorited:
            api.CreateFavorite(s)
            print "Favorited a tweet by @" + u
        else:
            print "Tweet already favorited, skipping..."

def main():
    consumer_key = 'p0k5TwqEaNspElJkQCsD33Khn'
    consumer_secret = sys.argv[1]
    tokens = get_access_token(consumer_key, consumer_secret)

    init_attack(twitter.Api(consumer_key=consumer_key, 
            consumer_secret=consumer_secret,
            access_token_key=tokens['access_token'],
            access_token_secret=tokens['access_secret']))


if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.0985895221646517, 'fraction_numerical': 0.002158894645941278, 'mean_word_length': 3.1937235968617985, 'pattern_counts': {'":': 8, '<': 4, '<?xml version=': 0, '>': 11, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3539865', 'n_tokens_mistral': 2211, 'n_tokens_neox': 2144, 'n_words': 553}