| 7912 |
vikram.rag |
1 |
import urllib2
|
|
|
2 |
import requests
|
|
|
3 |
import ast
|
|
|
4 |
import time
|
|
|
5 |
from elixir import *
|
|
|
6 |
from elixir import metadata, setup_all
|
|
|
7 |
from sqlalchemy.engine import create_engine
|
|
|
8 |
from shop2020.model.v1.order.impl.model.RechargeDenomination import RechargeDenomination
|
|
|
9 |
|
|
|
10 |
|
|
|
11 |
engine = create_engine('mysql://root:shop2020@' + 'localhost' + '/' + 'transaction', pool_recycle=7200)
|
|
|
12 |
metadata.bind = engine
|
|
|
13 |
metadata.bind.echo = True
|
|
|
14 |
setup_all(True)
|
|
|
15 |
|
|
|
16 |
listCircle = [
|
| 11995 |
kshitij.so |
17 |
['Andhra Pradesh','ANDHRA%20PRADESH',1],
|
| 11993 |
kshitij.so |
18 |
['Assam','ASSAM',2],
|
| 11995 |
kshitij.so |
19 |
['Bihar','BIHAR%20JHARKHAND',3],
|
| 11993 |
kshitij.so |
20 |
['Chennai','CHENNAI',4],
|
| 11996 |
kshitij.so |
21 |
['Delhi NCR','DELHI%20NCR',5],
|
| 11993 |
kshitij.so |
22 |
['Gujarat','GUJARAT',6],
|
|
|
23 |
['Haryana','HARYANA',9],
|
| 11995 |
kshitij.so |
24 |
['Himachal Pradesh','HIMACHAL%20PRADESH',7],
|
|
|
25 |
['Jammu','JAMMU%20KASHMIR',8],
|
| 11993 |
kshitij.so |
26 |
['Karnataka','KARNATAKA',10],
|
|
|
27 |
['Kerela','KERALA',11],
|
|
|
28 |
['Kolkata','KOLKATA',12],
|
| 11995 |
kshitij.so |
29 |
['MP','MADHYA%20PRADESH%20CHHATTISGARH',14],
|
| 11993 |
kshitij.so |
30 |
['Maharashtra','MAHARASHTRA',13],
|
|
|
31 |
['Mumbai','MUMBAI',15],
|
| 11995 |
kshitij.so |
32 |
['North East','NORTH%20EAST',16],
|
| 11993 |
kshitij.so |
33 |
['Orissa','ORISSA',17],
|
|
|
34 |
['Punjab','PUNJAB',18],
|
|
|
35 |
['Rajasthan','RAJASTHAN',19],
|
| 11995 |
kshitij.so |
36 |
['Tamil Nadu','TAMIL%20NADU',20],
|
|
|
37 |
['UP East','UP%20EAST',21],
|
|
|
38 |
['UP(West)','UP%20WEST',22],
|
|
|
39 |
['West Bengal','WEST%20BENGAL',23]
|
| 7912 |
vikram.rag |
40 |
]
|
|
|
41 |
|
|
|
42 |
listOperator =[
|
|
|
43 |
['Aircel','aircel',6],
|
|
|
44 |
['Airtel','airtel',7],
|
|
|
45 |
['Idea','idea',10],
|
|
|
46 |
['Mtnl Delhi','mtnl',11],
|
|
|
47 |
['Mtnl Mumbai','mtnl',12],
|
| 11997 |
kshitij.so |
48 |
['Reliance GSM','reliance%20gsm',13],
|
|
|
49 |
['Reliance CDMA','reliance%20cdma',14],
|
| 7912 |
vikram.rag |
50 |
['Uninor','uninor',17],
|
|
|
51 |
['Vodafone','vodafone',19]
|
|
|
52 |
]
|
|
|
53 |
|
|
|
54 |
listRechargeType = ['top_up','special_recharge','2g_data','3g_data']
|
|
|
55 |
|
| 12003 |
kshitij.so |
56 |
def fetch_plans(operator,circle):
|
|
|
57 |
url='https://hub.paytm.com/api/plans/list?type=mobile&operator=%s&circle=%s&auth=nosession&callback=jQuery15203827297973902207_1374842060208'%(operator[1],circle[1])
|
| 11994 |
kshitij.so |
58 |
print url
|
| 7912 |
vikram.rag |
59 |
time.sleep(2)
|
|
|
60 |
req = urllib2.Request(url)
|
|
|
61 |
response = urllib2.urlopen(req)
|
|
|
62 |
json_input = response.read()
|
|
|
63 |
start = json_input.rindex("\"plans\":") + len( "\"plans\":" )
|
|
|
64 |
end = json_input.rindex( ",\"count\":", start )
|
|
|
65 |
parse= json_input[start:end]
|
|
|
66 |
plans = ast.literal_eval(parse)
|
| 12003 |
kshitij.so |
67 |
commit_details(operator,circle,plans)
|
| 7912 |
vikram.rag |
68 |
|
|
|
69 |
|
| 12005 |
kshitij.so |
70 |
def commit_details(operator,circle,plans):
|
| 7912 |
vikram.rag |
71 |
for plan in plans:
|
| 11999 |
kshitij.so |
72 |
try:
|
| 12003 |
kshitij.so |
73 |
rechargeType = str(plan['category'])
|
| 12006 |
kshitij.so |
74 |
print rechargeType
|
| 11999 |
kshitij.so |
75 |
value = int(plan['value'])
|
|
|
76 |
talktime = str(plan['talktime'])
|
|
|
77 |
validity = str(plan['validity'])
|
|
|
78 |
description = str(plan['full_desc'].replace("\u2022",""))
|
|
|
79 |
description = description.replace("\/", "/")
|
|
|
80 |
description = description.replace("\n",".")
|
|
|
81 |
denomination = RechargeDenomination()
|
|
|
82 |
denomination.operatorId = operator[2]
|
|
|
83 |
denomination.circleId = circle[2]
|
| 12006 |
kshitij.so |
84 |
if rechargeType == 'Top_Up':
|
| 11999 |
kshitij.so |
85 |
denomination.denominationType = 1
|
|
|
86 |
else:
|
|
|
87 |
denomination.denominationType = 2
|
|
|
88 |
denomination.validity = validity
|
|
|
89 |
denomination.amount = value
|
|
|
90 |
denomination.description = "Talktime (Rs)"+talktime+"."+description
|
|
|
91 |
except Exception as e:
|
|
|
92 |
print "Unable to populate because ",e
|
| 11996 |
kshitij.so |
93 |
session.commit()
|
| 7912 |
vikram.rag |
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
def main():
|
|
|
99 |
for operator in listOperator:
|
|
|
100 |
for circle in listCircle:
|
| 12004 |
kshitij.so |
101 |
print "Trying to fetch recharge plans for Operator = %s , Circle = %s" %(operator[0],circle[0])
|
| 12003 |
kshitij.so |
102 |
print "\n"
|
|
|
103 |
fetch_plans(operator,circle)
|
| 7912 |
vikram.rag |
104 |
|
|
|
105 |
if __name__ == "__main__":
|
|
|
106 |
main()
|