Changeset 16487


Ignore:
Timestamp:
Aug 5, 2016, 8:06:25 AM (3 years ago)
Author:
dferreira
Message:

Query By ID and MD5Sum added

Location:
internals/2016/aptoideimagesdetector/trunk/aptoide_mature_app_detector
Files:
3 edited

Legend:

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

    r16486 r16487  
    55
    66urlpatterns = [
    7     url(r'^(?P<app_md5>[0-9a-zA-Z]+)/$', views.index, name='index'),
     7    url(r'^md5sum=(?P<app_md5>[0-9a-zA-Z]+)/$', views.getbyMD5, name='md5'),
     8    url(r'^id=(?P<app_id>[0-9]+)/$', views.getbyId, name='id'),
    89    url(r'^(?P<app_id>[0-9]+)/true/$', views.true, name='true'),
    910    url(r'^(?P<app_id>[0-9]+)/false/$', views.false, name='false'),
  • internals/2016/aptoideimagesdetector/trunk/aptoide_mature_app_detector/aptoide_mature_app_detector/explicit_content_detector/API/views.py

    r16486 r16487  
    33# Aptoide, 2016
    44
    5 # API in Django to deploy the analysis of an app, given its MD5.
     5# API in Django to deploy the analysis of an app, given its MD5 or ID.
    66# Just start the server and write the following url:
    7 # http://127.0.0.1:8000/detect_mature/md5_of_app
     7# http://127.0.0.1:8000/detect_mature/md5sum=md5_of_app
     8# or
     9# http://127.0.0.1:8000/detect_mature/id=md5_of_app
    810
    911from django.http import HttpResponse
     
    2325        _time = datetime.now()
    2426
     27# Function that analyses the information of an app and returns if it is explicit or not
     28def get_data(page):
     29        illust2vec = Model._model
     30        exp = False
     31        print "Fetching data..."
     32        title = page['meta']['title']
    2533
    26 def index(request, app_md5):
     34        description = page['meta']['description']
     35
     36        categories = []
     37
     38        for cat in page['meta']['categories']['standard']:
     39                categories.append(cat['name'])
     40
     41        for cat in page['meta']['categories']['custom']:
     42                categories.append(cat['name'])
     43
     44        scr = []
     45        scr_hd = []
     46
     47        if 'sshots' in page['media']:
     48                for s in page['media']['sshots']:
     49                        scr.append(s)
     50
     51        if 'sshots_hd' in page['media']:
     52                for s in page['media']['sshots_hd']:
     53                        scr_hd.append(s['path'])
     54
     55        min_age = page['meta']['min_age']
     56
     57        icon = page['apk']['icon']
     58
     59        icon_hd = []
     60        if 'icon_hd' in page['apk']:
     61                icon_hd = page['apk']['icon_hd']
     62
     63        icons = []
     64        icons.append(icon)
     65        if icon_hd:
     66                icons.append(icon_hd)
     67
     68        screenshots = scr+scr_hd
     69        size = len(description)
     70        print "Analysing app..."
     71        # Gets the percentage for safe and explicit content
     72        dist = analyse_app.analyse_app(illust2vec, icons, screenshots, description,''.join(categories), min_age, size, title)
     73        if dist.prob('exp')>0.5:
     74                exp = True
     75        print "Done"
     76        return exp
     77
     78# View for get by id
     79def getbyId(request, app_id):
    2780        now = datetime.now()
    28         url = "http://webservices.aptoide.com/webservices/3/getApkInfo/md5sum:"
    29         illust2vec = Model._model
     81        url = "http://webservices.aptoide.com/webservices/3/getApkInfo/id:"
     82
    3083        Model._time = now
     84        exp = False
    3185        try:
    3286                # Fetching the JSON content
    33                 webpage = urllib2.urlopen(url+str(app_md5)+"/json")
     87                webpage = urllib2.urlopen(url+str(app_id)+"/json")
    3488                soup = BeautifulSoup(webpage, "lxml")
    3589                               
    3690                text = soup.get_text()
    3791                page = json.loads(text)
    38                 exp = False
    3992                if page['status']!='FAIL':
    4093
    41                         print "Fetching data..."
    42                         app_id = page['apk']['id']
    43                         title = page['meta']['title']
    44 
    45                         description = page['meta']['description']
    46 
    47                         categories = []
    48 
    49                         for cat in page['meta']['categories']['standard']:
    50                                 categories.append(cat['name'])
    51 
    52                         for cat in page['meta']['categories']['custom']:
    53                                 categories.append(cat['name'])
    54 
    55                         scr = []
    56                         scr_hd = []
    57 
    58                         if 'sshots' in page['media']:
    59                                 for s in page['media']['sshots']:
    60                                         scr.append(s)
    61 
    62                         if 'sshots_hd' in page['media']:
    63                                 for s in page['media']['sshots_hd']:
    64                                         scr_hd.append(s['path'])
    65 
    66                         min_age = page['meta']['min_age']
    67 
    68                         icon = page['apk']['icon']
    69 
    70                         icon_hd = []
    71                         if 'icon_hd' in page['apk']:
    72                                 icon_hd = page['apk']['icon_hd']
    73 
    74                         icons = []
    75                         icons.append(icon)
    76                         if icon_hd:
    77                                 icons.append(icon_hd)
    78 
    79                         screenshots = scr+scr_hd
    80                         size = len(description)
    81                         print "Analysing app..."
    82                         # Gets the percentage for safe and explicit content
    83                         dist = analyse_app.analyse_app(illust2vec, icons, screenshots, description,''.join(categories), min_age, size, title)
    84                         if dist.prob('exp')>0.5:
    85                                 exp = True
    86                         print "Done"
     94                        exp = get_data(page)
    8795
    8896                else:
     
    93101                status = 'Failed'
    94102                print "Error during parsing"
     103                return redirect('error')
     104
     105        # If it's explicit content, redirects to true page. Otherwise, redirects to false page.
     106        if exp:
     107                return redirect('true', app_id=app_id)
     108        return redirect('false', app_id=app_id)
     109
     110# View for get by md5
     111def getbyMD5(request, app_md5):
     112        now = datetime.now()
     113        url = "http://webservices.aptoide.com/webservices/3/getApkInfo/md5sum:"
     114        app_id = 0
     115        Model._time = now
     116        exp = False
     117        try:
     118                # Fetching the JSON content
     119                webpage = urllib2.urlopen(url+str(app_md5)+"/json")
     120                soup = BeautifulSoup(webpage, "lxml")
     121                               
     122                text = soup.get_text()
     123                page = json.loads(text)
     124                if page['status']!='FAIL':
     125
     126                        app_id = page['apk']['id']
     127                        exp = get_data(page)
     128
     129                else:
     130                        status = 'Failed'
     131                        print "App does not exist"
     132                        return redirect('error')
     133        except:
     134                status = 'Failed'
     135                print "Error during parsing"
     136                return redirect('error')
    95137
    96138        # If it's explicit content, redirects to true page. Otherwise, redirects to false page.
  • internals/2016/aptoideimagesdetector/trunk/aptoide_mature_app_detector/readme.rst

    r16486 r16487  
    77---------------------------
    88
    9 Django API to analyse an aptoide app given an MD5 sum of an app
     9Django API to analyse an aptoide app given an ID or MD5 sum of an app
    1010and check if it has nudity content or not with 95% accuracy.
    1111
     
    1515python manage.py runserver
    1616
    17 Then, choose an app MD5 sum and go to the url 127.0.0.1:8000/detect_mature/md5_sum
     17Then, choose an app MD5 sum and go to the url 127.0.0.1:8000/detect_mature/md5sum=app_md5_sum
     18
     19or
     20
     21choose an app ID and go to the url 127.0.0.1:8000/detect_mature/id=app_id
    1822
    1923That's it!
Note: See TracChangeset for help on using the changeset viewer.