Subversion Repositories SmartDukaan

Rev

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

Rev 16578 Rev 16595
Line 1... Line 1...
1
from elixir import *
1
from elixir import *
2
from dtr.storage import DataService
2
from dtr.storage import DataService
3
from dtr.storage.DataService import app_offers, app_affiliates
3
from dtr.storage.DataService import app_offers, app_affiliates, appmasters
4
from dtr.utils.utils import AFFILIATE_OFFER_API, AFFILIATE_OFFER_DESC_API, fetchResponseUsingProxy
4
from dtr.utils.utils import AFFILIATE_OFFER_API, AFFILIATE_OFFER_DESC_API, fetchResponseUsingProxy
5
import json
5
import json
6
 
6
 
7
AFFILIATE_ID = 1
7
AFFILIATE_ID = 1
8
DEVICE_ID = "SpiceRetail"
8
DEVICE_ID = "SpiceRetail"
Line 26... Line 26...
26
    global ACTIVE_OFFERS
26
    global ACTIVE_OFFERS
27
    offer_desc_url = AFFILIATE_OFFER_DESC_API.get(AFFILIATE_ID)%(DEVICE_ID,offer['offerId'],RETAILER_CODE)
27
    offer_desc_url = AFFILIATE_OFFER_DESC_API.get(AFFILIATE_ID)%(DEVICE_ID,offer['offerId'],RETAILER_CODE)
28
    response = fetchResponseUsingProxy(offer_desc_url,proxy=False)
28
    response = fetchResponseUsingProxy(offer_desc_url,proxy=False)
29
    offer_desc = json.loads(response)
29
    offer_desc = json.loads(response)
30
    input_json = offer_desc['payload']
30
    input_json = offer_desc['payload']
-
 
31
    app_master = appmasters.get_by(package_name=offer['package_name'])
-
 
32
    if app_master is None:
-
 
33
        app_master = appmasters()
-
 
34
        app_master.app_name = offer.get('appName')
-
 
35
        app_master.package_name = offer.get('packageName')
-
 
36
    session.commit()
-
 
37
    appMasterId = app_master.id
31
    app_offer = app_offers.get_by(affiliate_id=AFFILIATE_ID, affiliate_offer_id=offer['offerId'])
38
    single_app_offers = app_offers.query.filter(app_offers.affiliate_id==AFFILIATE_ID).filter(app_offers.package_name==offer['package_name']).all()
32
    ACTIVE_OFFERS.append(offer['offerId'])
39
    ACTIVE_OFFERS.append(offer['offerId']) 
-
 
40
    for app_offer in single_app_offers:
-
 
41
        if app_offer.affiliate_offer_id == offer['offerId']:
-
 
42
            app_offer.offer_price = float(offer['offerPrice'])
-
 
43
            app_offer.show = True
-
 
44
            app_offer.user_payout = .8 * app_offer.offer_price
-
 
45
            app_offer.description = input_json.get('description')
-
 
46
            app_offer.shortDescription = offer.get('shortDesc')
-
 
47
            app_offer.longDescription = offer.get('longDesc')
-
 
48
            app_offer.link = offer.get('url')
-
 
49
            app_offer.offerCategory = offer.get('offerCategory')
-
 
50
            app_offer.promoImage = input_json.get('promoImage')
-
 
51
            app_offer.ratings = offer.get('appRating')
-
 
52
            app_offer.downloads = offer.get('appDownloads')
-
 
53
            app_offer.image_url = offer.get('iconUrl')
-
 
54
            if not app_offer.appmaster_id:
-
 
55
                app_offer.appmaster_id = appMasterId
-
 
56
        else:
-
 
57
            app_offerObj = app_offers()
-
 
58
            app_offerObj.affiliate_id = AFFILIATE_ID
-
 
59
            app_offerObj.affiliate_offer_id = offer['offerId']
-
 
60
            try:
-
 
61
                app_offerObj.offer_price = float(offer['offerPrice'])
-
 
62
            except:
-
 
63
                app_offerObj.offer_price = 0.0
-
 
64
            app_offerObj.user_payout = .8 * app_offer.offer_price
-
 
65
            app_offerObj.override_payout = False
-
 
66
            app_offerObj.overriden_payout = 0.0
-
 
67
            app_offerObj.app_name = offer.get('appName')
-
 
68
            app_offerObj.package_name = offer.get('packageName')
-
 
69
            app_offerObj.description = input_json.get('description')
-
 
70
            app_offerObj.shortDescription = offer.get('shortDesc')
-
 
71
            app_offerObj.longDescription = offer.get('longDesc')
-
 
72
            app_offerObj.link = offer.get('url')
-
 
73
            app_offerObj.offer_active = True
-
 
74
            app_offerObj.priority = 0
-
 
75
            app_offerObj.offerCategory = offer.get('offerCategory')
-
 
76
            app_offerObj.promoImage = input_json.get('promoImage')
-
 
77
            app_offerObj.ratings = offer.get('appRating')
-
 
78
            app_offerObj.downloads = offer.get('appDownloads')
-
 
79
            app_offerObj.image_url = offer.get('iconUrl')
-
 
80
            app_offerObj.appmaster_id = appMasterId
-
 
81
            if app_offer.offer_price < float(offer['offerPrice']):
-
 
82
                app_offer.show = False
-
 
83
                if not app_offer.appmaster_id:
-
 
84
                    app_offer.appmaster_id = appMasterId
-
 
85
                app_offerObj.show = True
-
 
86
            else:
-
 
87
                app_offerObj.show = False
-
 
88
    session.commit()
-
 
89
    '''            
-
 
90
    app_offer = app_offers.get_by(affiliate_id=AFFILIATE_ID, affiliate_offer_id=offer['offerId'], package_name=offer['package_name'])
-
 
91
    
33
    if app_offer is None:
92
    if app_offer is None:
34
        app_offer = app_offers()
93
        app_offer = app_offers()
35
        app_offer.affiliate_id = AFFILIATE_ID
94
        app_offer.affiliate_id = AFFILIATE_ID
36
        app_offer.affiliate_offer_id = offer['offerId']
95
        app_offer.affiliate_offer_id = offer['offerId']
37
        try:
96
        try:
Line 69... Line 128...
69
        app_offer.promoImage = input_json.get('promoImage')
128
        app_offer.promoImage = input_json.get('promoImage')
70
        app_offer.ratings = offer.get('appRating')
129
        app_offer.ratings = offer.get('appRating')
71
        app_offer.downloads = offer.get('appDownloads')
130
        app_offer.downloads = offer.get('appDownloads')
72
        app_offer.image_url = offer.get('iconUrl')
131
        app_offer.image_url = offer.get('iconUrl')
73
    session.commit()
132
    session.commit()
-
 
133
    '''
74
        
134
        
75
def markOfferAsInactive():
135
def markOfferAsInactive():
76
    all_active_offers = app_offers.query.filter(app_offers.affiliate_id==AFFILIATE_ID).filter(~app_offers.affiliate_offer_id.in_(ACTIVE_OFFERS)).filter(app_offers.offer_active==True).all()
136
    all_active_offers = app_offers.query.filter(app_offers.affiliate_id==AFFILIATE_ID).filter(~app_offers.affiliate_offer_id.in_(ACTIVE_OFFERS)).filter(app_offers.offer_active==True).all()
77
    for active_offer in all_active_offers:
137
    for active_offer in all_active_offers:
78
        active_offer.offer_active = False
138
        active_offer.offer_active = False