Subversion Repositories SmartDukaan

Rev

Rev 16685 | Rev 16687 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 16685 Rev 16686
Line 12... Line 12...
12
 
12
 
13
DataService.initialize(db_hostname='localhost' )
13
DataService.initialize(db_hostname='localhost' )
14
 
14
 
15
 
15
 
16
def dumpOffers():
16
def dumpOffers():
-
 
17
    global ACTIVE_OFFERS
17
    offer_url =  AFFILIATE_OFFER_API.get(AFFILIATE_ID)%(DEVICE_ID,RETAILER_CODE)
18
    offer_url =  AFFILIATE_OFFER_API.get(AFFILIATE_ID)%(DEVICE_ID,RETAILER_CODE)
18
    response = fetchResponseUsingProxy(offer_url, proxy=False)
19
    response = fetchResponseUsingProxy(offer_url, proxy=False)
19
    input_json = json.loads(response)
20
    input_json = json.loads(response)
20
    if input_json['status'].strip()=='ok' and input_json['message'] =="Success":
21
    if input_json['status'].strip()=='ok' and input_json['message'] =="Success":
21
        offers = (input_json['payload'])['offers']
22
        offers = (input_json['payload'])['offers']
22
        for offer in offers:
23
        for offer in offers:
-
 
24
            ACTIVE_OFFERS.append(offer['offerId'])
-
 
25
        for offer in offers:
23
            fetchOfferDescriptionAndDump(offer)
26
            fetchOfferDescriptionAndDump(offer)
24
    
27
    
25
    
28
    
26
def fetchOfferDescriptionAndDump(offer):
29
def fetchOfferDescriptionAndDump(offer):
27
    global ACTIVE_OFFERS
-
 
28
    offer_desc_url = AFFILIATE_OFFER_DESC_API.get(AFFILIATE_ID)%(DEVICE_ID,offer['offerId'],RETAILER_CODE)
30
    offer_desc_url = AFFILIATE_OFFER_DESC_API.get(AFFILIATE_ID)%(DEVICE_ID,offer['offerId'],RETAILER_CODE)
29
    response = fetchResponseUsingProxy(offer_desc_url,proxy=False)
31
    response = fetchResponseUsingProxy(offer_desc_url,proxy=False)
30
    offer_desc = json.loads(response)
32
    offer_desc = json.loads(response)
31
    input_json = offer_desc['payload']
33
    input_json = offer_desc['payload']
32
    app_master = appmasters.get_by(package_name=offer['packageName'])
34
    app_master = appmasters.get_by(package_name=offer['packageName'])
Line 36... Line 38...
36
        app_master.package_name = offer.get('packageName')
38
        app_master.package_name = offer.get('packageName')
37
        app_master.os_name = 'ANDROID'
39
        app_master.os_name = 'ANDROID'
38
    session.commit()
40
    session.commit()
39
    appMasterId = app_master.id
41
    appMasterId = app_master.id
40
    app_offer = app_offers.query.filter(app_offers.affiliate_id==AFFILIATE_ID).filter(app_offers.affiliate_offer_id==offer['offerId']).filter(app_offers.package_name==offer['packageName']).first()
42
    app_offer = app_offers.query.filter(app_offers.affiliate_id==AFFILIATE_ID).filter(app_offers.affiliate_offer_id==offer['offerId']).filter(app_offers.package_name==offer['packageName']).first()
41
    ACTIVE_OFFERS.append(offer['offerId'])
-
 
42
    
43
    
43
    if app_offer is None:
44
    if app_offer is None:
44
        app_offer = app_offers()
45
        app_offer = app_offers()
45
        app_offer.affiliate_id = AFFILIATE_ID
46
        app_offer.affiliate_id = AFFILIATE_ID
46
        app_offer.affiliate_offer_id = offer['offerId']
47
        app_offer.affiliate_offer_id = offer['offerId']
Line 64... Line 65...
64
        app_offer.ratings = offer.get('appRating')
65
        app_offer.ratings = offer.get('appRating')
65
        app_offer.downloads = offer.get('appDownloads')
66
        app_offer.downloads = offer.get('appDownloads')
66
        app_offer.image_url = offer.get('iconUrl')
67
        app_offer.image_url = offer.get('iconUrl')
67
        app_offer.appmaster_id = appMasterId
68
        app_offer.appmaster_id = appMasterId
68
        existingAppOffer = app_offers.query.filter(app_offers.affiliate_id==AFFILIATE_ID).filter(app_offers.package_name==offer['packageName']).filter(app_offers.show==True).first()
69
        existingAppOffer = app_offers.query.filter(app_offers.affiliate_id==AFFILIATE_ID).filter(app_offers.package_name==offer['packageName']).filter(app_offers.show==True).first()
-
 
70
        
69
        if existingAppOffer is None:
71
        if existingAppOffer is None:
70
            app_offer.show = True
72
            app_offer.show = True
71
        else:
73
        else:
72
            if existingAppOffer.offer_price <= float(offer['offerPrice']):
74
            if existingAppOffer.affiliate_offer_id not in ACTIVE_OFFERS:
73
                existingAppOffer.show = False
75
                existingAppOffer.show = False
74
                app_offer.show = True
76
                app_offer.show = True
75
            else:
77
            else:
-
 
78
                if existingAppOffer.offer_price <= float(offer['offerPrice']):
-
 
79
                    existingAppOffer.show = False
-
 
80
                    app_offer.show = True
-
 
81
                else:
76
                existingAppOffer.show = True
82
                    existingAppOffer.show = True
77
                existingAppOffer.offer_active = True
83
                    existingAppOffer.offer_active = True
78
                app_offer.show = False
84
                    app_offer.show = False
79
    else:
85
    else:
80
        try:
86
        try:
81
            app_offer.offer_price = float(offer['offerPrice'])
87
            app_offer.offer_price = float(offer['offerPrice'])
82
        except:
88
        except:
83
            app_offer.offer_price = 0.0
89
            app_offer.offer_price = 0.0
Line 94... Line 100...
94
        app_offer.offer_active = True
100
        app_offer.offer_active = True
95
        existingAppOffer = app_offers.query.filter(app_offers.affiliate_id==AFFILIATE_ID).filter(app_offers.package_name==offer['packageName']).filter(app_offers.show==True).first()
101
        existingAppOffer = app_offers.query.filter(app_offers.affiliate_id==AFFILIATE_ID).filter(app_offers.package_name==offer['packageName']).filter(app_offers.show==True).first()
96
        if existingAppOffer is None:
102
        if existingAppOffer is None:
97
            app_offer.show = True
103
            app_offer.show = True
98
        else:
104
        else:
99
            if existingAppOffer.offer_price <= float(offer['offerPrice']):
105
            if existingAppOffer.affiliate_offer_id not in ACTIVE_OFFERS:
100
                existingAppOffer.show = False
106
                existingAppOffer.show = False
101
                app_offer.show = True
107
                app_offer.show = True
102
            else:
108
            else:
-
 
109
                if existingAppOffer.offer_price <= float(offer['offerPrice']):
-
 
110
                    existingAppOffer.show = False
-
 
111
                    app_offer.show = True
-
 
112
                else:
103
                existingAppOffer.show = True
113
                    existingAppOffer.show = True
104
                existingAppOffer.offer_active
114
                    existingAppOffer.offer_active
105
                app_offer.show = False
115
                    app_offer.show = False
106
         
116
         
107
    '''            
117
    '''            
108
    app_offer = app_offers.get_by(affiliate_id=AFFILIATE_ID, affiliate_offer_id=offer['offerId'], package_name=offer['package_name'])
118
    app_offer = app_offers.get_by(affiliate_id=AFFILIATE_ID, affiliate_offer_id=offer['offerId'], package_name=offer['package_name'])
109
    
119
    
110
    if app_offer is None:
120
    if app_offer is None: