Ignore:
Timestamp:
Aug 11, 2016, 2:53:35 PM (4 years ago)
Author:
dferreira
Message:

Added option of force reload the cache

File:
1 edited

Legend:

Unmodified
Added
Removed
  • internals/2016/aptoideimagesdetector/trunk/aptoide_mature_app_detector/aptoide_mature_app_detector/explicit_content_detector/API/views.py

    r16524 r16525  
    4848# Function that analyses the information of an app and returns if it is explicit or not
    4949@postpone
    50 def get_data_async(page, url_async):
     50def get_data_async(page, url_async, cache_reload):
    5151        illust2vec = Model._model
    5252        exp = False
     
    119119        print "Analysing app..."
    120120        # Gets the percentage for safe and explicit content
    121         dist = analyse_app.analyse_app(page['apk']['id'], page['apk']['md5sum'], illust2vec, icons, screenshots, description,''.join(categories), min_age, size, title)
     121        dist = analyse_app.analyse_app(page['apk']['id'], page['apk']['md5sum'], illust2vec, icons, screenshots, description,''.join(categories), min_age, size, title, cache_reload)
    122122        try:
    123123                if dist.prob('exp')>0.5:
     
    133133
    134134# Function that analyses the information of an app and returns if it is explicit or not
    135 def get_data_sync(page):
     135def get_data_sync(page, cache_reload):
    136136        illust2vec = Model._model
    137137        exp = False
     
    204204        print "Analysing app..."
    205205        # Gets the percentage for safe and explicit content
    206         dist = analyse_app.analyse_app(page['apk']['id'], page['apk']['md5sum'], illust2vec, icons, screenshots, description,''.join(categories), min_age, size, title)
     206        dist = analyse_app.analyse_app(page['apk']['id'], page['apk']['md5sum'], illust2vec, icons, screenshots, description,''.join(categories), min_age, size, title, cache_reload)
    207207        try:
    208208                if dist.prob('exp')>0.5:
     
    219219# For more detailed error logs comment the try... except and indentate correctly its content
    220220
    221 def getbyId(request, app_id):
     221def getbyId(request, app_id, cache_reload=0):
     222        if not cache_reload:
     223                cache_reload=0
    222224        now = datetime.now()
    223225        url = "http://webservices.aptoide.com/webservices/3/getApkInfo/id:"
     
    226228                config = json.load(json_data)
    227229        exp = False
    228         try:
     230        #try:
    229231                # Fetching the JSON content
    230                 webpage = urllib2.urlopen(url+str(app_id)+"/json")
    231                 soup = BeautifulSoup(webpage, "lxml")
     232        webpage = urllib2.urlopen(url+str(app_id)+"/json")
     233        soup = BeautifulSoup(webpage, "lxml")
    232234                                               
    233                 text = soup.get_text()
    234                 page = json.loads(text)
    235                 if page['status']!='FAIL':
    236                         if config["synchronous_or_asynchronous"]=="asynchronous":
    237                                 get_data_async(page, config["directories"]["asynchronous_dir"])
    238                                 return HttpResponse("Waiting")
    239                         exp = get_data_sync(page)
    240 
    241                 else:
    242                         status = 'Failed'
    243                         print "App does not exist"
    244                         return HttpResponse(json.dumps({'status': 'Failed', 'time':str(datetime.now()-now)}, sort_keys=True))
    245         except:
     235        text = soup.get_text()
     236        page = json.loads(text)
     237        if page['status']!='FAIL':
     238                if config["synchronous_or_asynchronous"]=="asynchronous":
     239                        get_data_async(page, config["directories"]["asynchronous_dir"], cache_reload)
     240                        return HttpResponse("Waiting")
     241                exp = get_data_sync(page, int(cache_reload))
     242
     243        else:
    246244                status = 'Failed'
    247                 print "Error during parsing"
     245                print "App does not exist"
    248246                return HttpResponse(json.dumps({'status': 'Failed', 'time':str(datetime.now()-now)}, sort_keys=True))
     247        #except:
     248        #       status = 'Failed'
     249        #       print "Error during parsing"
     250        #       return HttpResponse(json.dumps({'status': 'Failed', 'time':str(datetime.now()-now)}, sort_keys=True))
    249251
    250252        # If it's explicit content, redirects to true page. Otherwise, redirects to false page.
    251253        if exp:
    252                 return HttpResponse(json.dumps({'app_id': app_id, 'status': 'OK','mature_content': 'yes', 'time':str(datetime.now()-now)}, sort_keys=True))
    253         return HttpResponse(json.dumps({'app_id': app_id, 'status': 'OK','mature_content': 'no', 'time':str(datetime.now()-now)}, sort_keys=True))
     254                return HttpResponse(json.dumps({'app_id': int(app_id), 'status': 'OK','mature_content': 'yes', 'time':str(datetime.now()-now)}, sort_keys=True))
     255        return HttpResponse(json.dumps({'app_id': int(app_id), 'status': 'OK','mature_content': 'no', 'time':str(datetime.now()-now)}, sort_keys=True))
    254256
    255257
     
    257259# View for get by md5
    258260# For more detailed error logs comment the try... except and indentate correctly its content
    259 def getbyMD5(request, app_md5):
     261def getbyMD5(request, app_md5, cache_reload=0):
     262        if not cache_reload:
     263                cache_reload=0
    260264        now = datetime.now()
    261265        url = "http://webservices.aptoide.com/webservices/3/getApkInfo/md5sum:"
     
    274278                page = json.loads(text)
    275279                if page['status']!='FAIL':
    276 
     280                        app_id = page['apk']['id']
    277281                        if config["synchronous_or_asynchronous"]=="asynchronous":
    278                                 get_data_async(page, config["directories"]["asynchronous_dir"])
     282                                get_data_async(page, config["directories"]["asynchronous_dir"], cache_reload)
    279283                                return HttpResponse("Waiting")
    280                         exp = get_data_sync(page)
     284                        exp = get_data_sync(page, int(cache_reload))
    281285
    282286                else:
Note: See TracChangeset for help on using the changeset viewer.