My favorites | Sign in
Project Logo
                
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Licensed under GPL v2 or later at your option
# Copyright 2007, İsmail Dönmez

import sys
import os
import tempfile
import getopt
import subprocess
import time
import urllib2_file
import urllib2
from mechanize import Browser
from BeautifulSoup import BeautifulSoup

def grabQuota(username=None,password=None):
br = Browser()
br.addheaders = [("User-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)")]

# Download CAPTCHA image
imageData = br.open("http://adslkota.ttnet.net.tr/adslkota/jcaptcha").read(4096*10)
tmpFile = tempfile.mkstemp()[1];
imageFile = open(tmpFile, "w")
imageFile.write(imageData)
imageFile.close()

# Use captchakiller.com to solve captcha
data = {
'method' : 'upload_captcha',
'api_key' : 'EE05855B-391B-B86A-6DAC-B393EB08325D',
'file' : open(tmpFile),
'expire' : '300',
'rights' : 'true'
}
success = False

while not success:
result=urllib2.urlopen('http://www.captchakiller.com/api.php', data).read().strip()
if result.startswith("FAILURE"):
print "Captcha detection failed : %s" % result.split(':')[-1]
return
elif result.startswith("SUCCESS"):
success = True
id = result.split('=')[-1]

# Remove temporary file
os.unlink(tmpFile)

data = {
'method' : 'get_result',
'api_key' : 'EE05855B-391B-B86A-6DAC-B393EB08325D',
'captcha_id' : id
}
solved = False

while not solved:
result = urllib2.urlopen('http://www.captchakiller.com/api.php', data).read().strip()
if result.startswith("WAIT"):
print "Sleeping 10 seconds..."
time.sleep(10)
elif result.startswith("FAILURE"):
print "Error occurred: %s" % result
return
elif result.startswith("SUCCESS"):
solved = True
captcha = result.split('=')[-1].replace('"','')

br.open("http://adslkota.ttnet.net.tr/adslkota/login.jsp")
br.select_form(nr=0)
br["userName"]=username
br["password"]=password
br["captchaResponse"]=captcha
br.submit()

br.open("http://adslkota.ttnet.net.tr/adslkota/confirmAgreement.do","dispatch=agree")
response = br.open("http://adslkota.ttnet.net.tr/adslkota/viewTransfer.do","dispatch=entry")

soup = BeautifulSoup(response.read(),fromEncoding="windows-1254")
quotaTable = soup.find('table',align='center')

i=1
for data in quotaTable.findAll('td'):
print data.contents[0],
if i % 4 == 0:
print
i += 1

def showHelp():
print 'Usage: kota.py -u username -p password'
sys.exit(1)

if __name__ == "__main__":
username = None
password = None

try:
opts, args = getopt.getopt(sys.argv[1:],"u:p:h",["username=","password=","help"])
for opt, arg in opts:
if opt in ("-h","--help"):
showHelp()
elif opt in ("-u","--username"):
username = arg
elif opt in ("-p","--password"):
password = arg

if username and password:
grabQuota(username,password)
else:
showHelp()
except getopt.GetoptError:
showHelp()
sys.exit(1)
Show details Hide details

Change log

r19 by ismail.donmez on Dec 03, 2007   Diff
be secure
Go to: 
Project members, sign in to write a code review

Older revisions

r18 by ismail.donmez on Nov 11, 2007   Diff
ignore.
r17 by ismail.donmez on Nov 11, 2007   Diff
less debug spam
r15 by ismail.donmez on Nov 11, 2007   Diff
use a fixed apikey
All revisions of this file

File info

Size: 3349 bytes, 114 lines
Hosted by Google Code