Subversion Repositories SmartDukaan

Rev

Rev 7912 | Rev 11994 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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 = [
11993 kshitij.so 17
['Andhra Pradesh','ANDHRA PRADESH',1],
18
['Assam','ASSAM',2],
19
['Bihar','BIHAR JHARKHAND',3],
20
['Chennai','CHENNAI',4],
21
['Delhi NCR','DELHI NCR',5],
22
['Gujarat','GUJARAT',6],
23
['Haryana','HARYANA',9],
24
['Himachal Pradesh','HIMACHAL PRADESH',7],
25
['Jammu','JAMMU KASHMIR',8],
26
['Karnataka','KARNATAKA',10],
27
['Kerela','KERALA',11],
28
['Kolkata','KOLKATA',12],
29
['MP','MADHYA PRADESH CHHATTISGARH',14],
30
['Maharashtra','MAHARASHTRA',13],
31
['Mumbai','MUMBAI',15],
32
['North East','NORTH EAST',16],
33
['Orissa','ORISSA',17],
34
['Punjab','PUNJAB',18],
35
['Rajasthan','RAJASTHAN',19],
36
['Tamil Nadu','TAMIL NADU',20],
37
['UP East','UP EAST',21],
38
['UP(West)','UP WEST',22],
39
['West Bengal','WEST BENGAL',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],
48
               ['Reliance GSM','reliance_gsm',13],
49
               ['Reliance CDMA','reliance_cdma',14],
50
               ['Uninor','uninor',17],
51
               ['Vodafone','vodafone',19]
52
               ]
53
 
54
listRechargeType = ['top_up','special_recharge','2g_data','3g_data']
55
 
56
def fetch_plans(operator,circle,rechargeType):
57
    url='https://hub.paytm.com/api/plans/list?type=mobile&operator=%s&circle=%s&category=%s&auth=nosession&callback=jQuery15203827297973902207_1374842060208'%(operator[1],circle[1],rechargeType)
58
    time.sleep(2)
59
    req = urllib2.Request(url)
60
    response = urllib2.urlopen(req)
61
    json_input = response.read()
62
    start = json_input.rindex("\"plans\":") + len( "\"plans\":" )
63
    end = json_input.rindex( ",\"count\":", start )
64
    parse= json_input[start:end]
65
    plans = ast.literal_eval(parse)
66
    commit_details(operator,circle,rechargeType,plans)
67
 
68
 
69
def commit_details(operator,circle,rechargeType,plans):
70
    for plan in plans:
71
        value = int(plan['value'])
72
        talktime = str(plan['talktime'])
73
        validity = str(plan['validity'])
74
        description = str(plan['full_desc'].replace("\u2022",""))
75
        description = description.replace("\/", "/")
76
        description = description.replace("\n",".")
77
        denomination = RechargeDenomination()
78
        denomination.operatorId = operator[2]
79
        denomination.circleId = circle[2]
80
        if rechargeType == 'top_up':
81
            denomination.denominationType = 1
82
        else:
83
            denomination.denominationType = 2
84
        denomination.validity = validity
85
        denomination.amount = value
86
        denomination.description = "Talktime (Rs)"+talktime+"."+description
87
        session.commit()
88
 
89
 
90
 
91
 
92
def main():
93
    for operator in listOperator:
94
        for circle in listCircle:
95
            for rechargeType in listRechargeType:
96
                print "Trying to fetch recharge plans for Operator = %s , Circle = %s, Recharge Type = %s" %(operator[0],circle[0],rechargeType)
97
                print "\n"
98
                fetch_plans(operator,circle,rechargeType)
99
 
100
if __name__ == "__main__":
101
    main()