-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirst.rb
75 lines (64 loc) · 1.76 KB
/
first.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'nokogiri'
require 'curb'
def login(username, password)
c = Curl::Easy.new("https://mobile.twitter.com/session/new")
c.ssl_verify_peer = false
c.perform
response = c.body_str
doc = Nokogiri::XML(response)
span = doc.css('span.m2-auth-token').to_s
auth = (/value="(.*)"/.match(span))[1]
headers = c.header_str
cookies = headers.scan(/^Set-Cookie:\s*([^;]*)/mi)
cookie = cookies.join(";")
http = Curl.post("https://mobile.twitter.com/session", {:authenticity_token => auth,
:username => username,
:password => password,
:commit => "Sign+in"}) do|http|
http.headers['Cookie'] = cookie
http.ssl_verify_peer = false
end
headers2 = http.header_str
cookies2 = headers2.scan(/^Set-Cookie:\s*([^;]*)/mi)
cookie2 = cookies2.join(";")
return cookie2 + ":" + auth
end
def follow(cookie, auth, user)
http = Curl.post("https://mobile.twitter.com/" + user + "/follow", {:authenticity_token => auth,
:commit => "Follow"}) do|http|
http.headers['Cookie'] = cookie
http.ssl_verify_peer = false
end
res = http.body_str
end
def colorize(text, color_code)
"\e[#{color_code}m#{text}\e[0m"
end
def green(text); colorize(text, 32); end
def red(text); colorize(text, 31); end
doc = IO.read('file.txt')
content = doc.split("\n")
#counter
success = 0
fail = 0
for item in content
#bikin array
datfx = item.split(":")
user = datfx[0]
pass = datfx[1]
#mulai login
creds = login(user, pass)
#ambil response
datax = creds.split(":")
cookie = datax[0]
auth = datax[1]
if cookie.scan(/auth_token/).length == 0
fail += 1
puts user + " - " + red("Fail")
else
success += 1
follow(cookie, auth, "Twitter")
puts user + " - " + green("Success")
end
end
puts fail.to_s + " Fail & " + success.to_s + " Success"