Last active
August 29, 2015 14:12
-
-
Save zzuf/5a414e25cf9d2afaa6a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python | |
# -*- coding: utf-8 -*- | |
import urllib | |
import urllib2 | |
import cookielib | |
import oauth2 | |
import re | |
import random | |
#TwitterForAndroidのCKとCS | |
CK = '3nVuSoBZnx6U4vzUxf5w' | |
CS = 'Bcs59EFbbsdF6Sl9Ng71smgStWEGwXXKSjYvPVt7qys' | |
#擬似xAuth用のTwitterIDとPW | |
SN = 'vbsmaubf5i' | |
PW = 'twitterpassword' | |
#生成するアカウントのPW | |
GenePW = 'twitterpassword' | |
def PIN(url): | |
cj = cookielib.CookieJar() | |
#proxy_handler = urllib2.ProxyHandler({'http':'http://127.0.0.1:8080'}) | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
headers = { | |
'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:35.0) Gecko/20100101 Firefox/30.0', | |
'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', | |
'Accept-Language' : 'ja,en-us;q=0.7,en;q=0.3', | |
'Connection' : 'close' | |
} | |
req = urllib2.Request(url,None,headers) | |
res = opener.open(req).read() | |
pt1 = r'<input name="authenticity_token" type="hidden" value="(.*)" />' | |
pt2 = r'<input id="oauth_token" name="oauth_token" type="hidden" value="(.*)" />' | |
authenticity_token = re.findall(pt1,res)[0] | |
oauth_token = re.findall(pt2,res)[0] | |
########################### | |
headers.update({'Referer' : url}) | |
params = urllib.urlencode({ | |
'authenticity_token' : authenticity_token, | |
'repost_after_login' : 'https://api.twitter.com/oauth/authorize', | |
'oauth_token' : oauth_token, | |
'session[username_or_email]' : SN, | |
'session[password]' : PW, | |
'remember_me' : '0', | |
}) | |
req = urllib2.Request('https://twitter.com/intent/sessions',params,headers) | |
url = opener.open(req).geturl() | |
########################### | |
headers.update({'Referer' : url}) | |
params = urllib.urlencode({ | |
'authenticity_token' : authenticity_token, | |
'oauth_token' : oauth_token, | |
}) | |
req = urllib2.Request('https://api.twitter.com/oauth/authorize',params,headers) | |
res = opener.open(req).read() | |
pt = r'<code>(.*)</code>' | |
pin = re.findall(pt,res)[0] | |
return pin | |
def OAuth_Key(): | |
consumer = oauth2.Consumer(CK,CS) | |
client = oauth2.Client(consumer, None) | |
result = client.request('http://api.twitter.com/oauth/request_token','GET')[1] | |
result = dict([tuple(parameter.split('=')) for parameter in result.split('&')]) | |
token = oauth2.Token(result['oauth_token'],result['oauth_token_secret']) | |
tokenurl = "https://api.twitter.com/oauth/authenticate?oauth_token="+result['oauth_token'] | |
pin = PIN(tokenurl) | |
token.set_verifier(pin) | |
client.token = token | |
result = client.request('http://api.twitter.com/oauth/access_token','POST')[1] | |
token = dict([tuple(parameter.split('=')) for parameter in result.split('&')]) | |
return token | |
def API(): | |
token = OAuth_Key() | |
AT = token['oauth_token'] | |
AS = token['oauth_token_secret'] | |
client = oauth2.Client( | |
oauth2.Consumer(key=CK,secret=CS), | |
oauth2.Token(AT,AS) | |
) | |
rnd_str = "".join([random.choice('abcdefghijklmnopqrstuvwxyz1234567890') for x in xrange(10)]) | |
params = urllib.urlencode({ | |
'screen_name' : rnd_str, | |
'password' : GenePW, | |
'email' : rnd_str+'@gmail.com', | |
'name' : rnd_str, | |
}) | |
res = client.request( | |
'http://api.twitter.com/1/account/generate.json','POST',params | |
) | |
if res[0]['status'] == '200': | |
print "ID: "+rnd_str | |
print "PW: "+GenePW | |
else: | |
print res[1] | |
API() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment