| 6395 |
kshitij.so |
1 |
from BeautifulSoup import BeautifulSoup
|
|
|
2 |
import urllib2
|
|
|
3 |
import urllib
|
|
|
4 |
import MySQLdb
|
|
|
5 |
import sys
|
|
|
6 |
listCircle = [
|
|
|
7 |
['Andhra Pradesh','12',1],
|
|
|
8 |
['Assam','20',2],
|
|
|
9 |
['Bihar','17',3],
|
|
|
10 |
['Chennai','6',4],
|
|
|
11 |
['Delhi NCR','2',5],
|
|
|
12 |
['Gujarat','10',6],
|
|
|
13 |
['Haryana','15',9],
|
|
|
14 |
['Himachal Pradesh','13',7],
|
|
|
15 |
['Jammu','22',8],
|
|
|
16 |
['Karnataka','4',10],
|
|
|
17 |
['Kerela','7',11],
|
|
|
18 |
['Kolkata','5',12],
|
|
|
19 |
['MP','8',14],
|
|
|
20 |
['Maharashtra','11',13],
|
|
|
21 |
['Mumbai','3',15],
|
|
|
22 |
['North East','25',16],
|
|
|
23 |
['Orissa','18',17],
|
|
|
24 |
['Punjab','1',18],
|
|
|
25 |
['Rajasthan','23',19],
|
|
|
26 |
['Tamil Nadu','14',20],
|
|
|
27 |
['UP East','19',21],
|
|
|
28 |
['UP(West)','9',22],
|
|
|
29 |
['West Bengal','16',23]
|
|
|
30 |
]
|
|
|
31 |
|
|
|
32 |
j = 0
|
|
|
33 |
|
|
|
34 |
db = MySQLdb.connect("localhost","root","shop2020","transaction" )
|
|
|
35 |
url = "http://www.airtel.in/applications/xm/MobilePrepaidTariffTab_ExistingUser.jsp?"
|
|
|
36 |
http_header = {
|
|
|
37 |
"User-Agent" : "Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.218 Safari/535.1",
|
|
|
38 |
"Accept" : " text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
|
|
39 |
"Accept-Language" : "en-us,en;q=0.5",
|
|
|
40 |
"Accept-Encoding" : "gzip, deflate",
|
|
|
41 |
"Connection" : "keep-alive",
|
|
|
42 |
"Accept-Charset" : "ISO-8859-1",
|
|
|
43 |
"Content-type": "application/x-www-form-urlencoded"
|
|
|
44 |
}
|
|
|
45 |
for i in listCircle:
|
|
|
46 |
data = {
|
|
|
47 |
'CIRCLE' : listCircle[j][1],
|
|
|
48 |
'CIRCLENAME' : listCircle[j][0],
|
|
|
49 |
'link' : 'VR'
|
|
|
50 |
}
|
|
|
51 |
print listCircle[j][0]
|
|
|
52 |
Connected =False
|
|
|
53 |
Attempt = 1
|
|
|
54 |
while not Connected:
|
|
|
55 |
try:
|
|
|
56 |
data = urllib.urlencode(data)
|
|
|
57 |
req = urllib2.Request(url, data)
|
|
|
58 |
response = urllib2.urlopen(req)
|
|
|
59 |
page = response.read()
|
|
|
60 |
page=page.decode("utf-8")
|
|
|
61 |
soup = BeautifulSoup(page,convertEntities=BeautifulSoup.HTML_ENTITIES)
|
|
|
62 |
Connected =True
|
|
|
63 |
except:
|
|
|
64 |
print "In Except Block for Url "+url+" And Circle "+listCircle[j][0]
|
|
|
65 |
print "Retrying :",
|
|
|
66 |
print Attempt
|
|
|
67 |
Attempt = Attempt+1
|
|
|
68 |
if Attempt ==4:
|
|
|
69 |
sys.exit(1)
|
|
|
70 |
Rechargetables = soup.findAll("ul" , {"class" : "listexpander"})
|
|
|
71 |
rows = Rechargetables[0].findAll("li")
|
|
|
72 |
table = soup.findAll("table" , {"class" : "arial11grey"})
|
|
|
73 |
rows = table[1].findAll("td")
|
|
|
74 |
column_count = 1
|
|
|
75 |
for td in rows[5:]:
|
|
|
76 |
if column_count == 1:
|
|
|
77 |
Denomination = td.text
|
|
|
78 |
print "Deno: "+Denomination
|
|
|
79 |
Denomination = float(Denomination)
|
|
|
80 |
column_count = column_count+1
|
|
|
81 |
elif column_count ==2:
|
|
|
82 |
Talktime = td.text
|
|
|
83 |
column_count = column_count+1
|
|
|
84 |
if Talktime == '-' or Talktime == 'NA' or Talktime =='na' or Talktime =='nil' or Talktime =='' or Talktime =='Nil' or Talktime =='NIL':
|
|
|
85 |
Talktime = '0'
|
|
|
86 |
print "talk: "+Talktime
|
|
|
87 |
elif column_count ==3:
|
|
|
88 |
ProcessingFee = td.text
|
|
|
89 |
column_count = column_count+1
|
|
|
90 |
print "Process: "+ProcessingFee
|
|
|
91 |
elif column_count ==4:
|
|
|
92 |
ServiceTax = td.text
|
|
|
93 |
column_count = column_count+1
|
|
|
94 |
print "tax: "+ServiceTax
|
|
|
95 |
try:
|
|
|
96 |
Deduction = float(ProcessingFee)
|
|
|
97 |
print "Deduction: ",
|
|
|
98 |
print Deduction
|
|
|
99 |
if Deduction > (Denomination/2):
|
|
|
100 |
IsSpecial = 2
|
|
|
101 |
else:
|
|
|
102 |
IsSpecial = 1
|
|
|
103 |
except:
|
|
|
104 |
'''Case for no service tax and processing fee value in tables'''
|
|
|
105 |
try:
|
|
|
106 |
Talktime =float(Talktime)
|
|
|
107 |
if Talktime > (Denomination/2):
|
|
|
108 |
IsSpecial =1
|
|
|
109 |
else:
|
|
|
110 |
IsSpecial =2
|
|
|
111 |
except:
|
|
|
112 |
IsSpecial =2
|
|
|
113 |
print "IsSpecial",
|
|
|
114 |
print IsSpecial
|
|
|
115 |
elif column_count ==5:
|
|
|
116 |
Validity = td.text
|
|
|
117 |
if Validity == '-' or Validity == 'NA' or Validity =='na' or Validity =='nil' or Validity =='' or Validity =='Nil' or Validity =='NIL' or Validity =='0':
|
|
|
118 |
Validity = '0'
|
|
|
119 |
if IsSpecial ==1 and (Validity =='lifetime' or Validity =='Lifetime' or Validity =='life time' or Validity=='Life Time' or Validity =='Life time' or Validity== 'UNLIMITED' or Validity== 'unlimited' or Validity== 'Unlimited' or Validity== 'Unlimted'):
|
|
|
120 |
Validity='0'
|
|
|
121 |
column_count = column_count+1
|
|
|
122 |
column_count = 1
|
|
|
123 |
print "valid: "+Validity
|
|
|
124 |
cursor = db.cursor()
|
|
|
125 |
sql = "INSERT INTO rechargedenomination (operatorId, circleId, denominationType, validity, amount, description)\
|
|
|
126 |
VALUES ('%d', '%d', '%d', '%s', '%s', '%s' )" % \
|
|
|
127 |
(7, listCircle[j][2], IsSpecial, Validity, Denomination, Talktime)
|
|
|
128 |
cursor.execute(sql)
|
|
|
129 |
db.commit()
|
|
|
130 |
j = j+1
|
|
|
131 |
cursor = db.cursor()
|
|
|
132 |
sql = "delete from rechargedenomination where operatorId=7 and ((description like '%foot%' OR description like '%*' OR description like '%refer%') OR (validity like '%foot%' OR validity like '%*' OR validity like '%refer%'))"
|
|
|
133 |
cursor.execute(sql)
|
|
|
134 |
sql_setdenomination ="update rechargedenomination set denominationType=1 where (validity like '%top up%' OR validity ='main acc validity' OR validity ='Main a/c talktime' )"
|
|
|
135 |
cursor.execute(sql_setdenomination)
|
|
|
136 |
db.commit()
|
|
|
137 |
db.close()
|