Exemplo n.º 1
0
def update_app_after_save(sender, instance: App, created: bool,
                          **kwargs) -> None:
    if created:
        instance.users.add(instance.owner)
        instance.save()
    people: int = instance.users.count()
    if instance.people != people:
        instance.people = people
        instance.save()
Exemplo n.º 2
0
    def authenticate_app(self, app_key, app_secret):
        #authenticate app
        app = App(self._db)
        app = app.filter(app_key=app_key, app_secret=app_secret)
        if len(app) == 1:
            app = app[0]
            if not app.get('is_active'):
                raise falcon.HTTPForbidden(
                    title='Permission Denied ',
                    description='Your app account is inactive')

        elif len(app) > 1:
            raise falcon.HTTPUnauthorized(
                title='Duplicate  Autheentication',
                description='Duplicate Authentication Occured')
        else:
            raise falcon.HTTPUnauthorized(
                title='Authentication Failed ',
                description='Valid app-key and app-secret are  needed')
        return app
Exemplo n.º 3
0
def app_button_by_name(app_name):
    try:
        app = App.object.get(name=app_name)
        c = {}
        c['app'] = app
        return c
    except:
        app = App.get(name=app_name)
        c = {}
        c['app'] = app
        return c
Exemplo n.º 4
0
    def post(self, aid):
        data = self.get_data()

        app = App()
        app.from_dict(data)
        app.generate_secret()

        if app.save():
            self.set_status(201)
            self.set_header("Location", app.get_link("appkey"))
        else:
            raise HTTPError(500, "Created fail. wrong arguments or save error.")

        self.finish()
Exemplo n.º 5
0
    def save(self,request, *args, **kw):
#           commentModel.content_type_id = 47
#         commentModel.object_pk = self.cleaned_data.get("object_pk")
#         commentModel.site_id = 1
#         commentModel.user_id = self.request.user.id
#         commentModel.user_name = self.cleaned_data.get("user_name")
#         commentModel.user_email = self.cleaned_data.get("user_email")
#         commentModel.user_url = self.cleaned_data.get("user_url")
#         commentModel.submit_date = datetime.datetime.today()
#         commentModel.comment = self.cleaned_data.get("comment")
#         commentModel.ip_address = socket.gethostbyname(socket.gethostname())
#         commentModel.save()
        
      
            
       
        instance = App()
        instance.name = self.cleaned_data.get('name')
        instance.description = self.cleaned_data.get('description')
        instance.category = self.cleaned_data.get('category')
        
#         instance.platforms = self.cleaned_data.get('platforms')
#         instance.devices = self.cleaned_data.get('devices')
        instance.playstore_url = self.cleaned_data.get('playstore_url')
        instance.itunes_url = self.cleaned_data.get('itunes_url')
#         instance.plugins = self.cleaned_data.get('plugins')
#         print instance.name
#        instance.save()
       
        instance.create_user=request.user
        
        instance.save()
        for key in self.cleaned_data['platforms']:
                instance.platforms.add(key)
                #print instance.platforms.db_index
        for key in self.cleaned_data['devices']:
                instance.devices.add(key)
        for key in self.cleaned_data['plugins']:
                print key
                instance.plugins.add(key)
                
        return True;

          



#     def __init__(self, qs=None, *args, **kwargs):
#         super(App, self).__init__(*args, **kwargs)
#         if qs:
#             self.fields['plugins']=forms.ModelMultipleChoiceField(choices=Plugin.objects.all(),widget=forms.CheckboxSelectMultiple())
        
#         widgets = {
#                 'plugins' : forms.ModelMultipleChoiceField(choices=Plugin.objects.all(),widget=forms.CheckboxSelectMultiple()),
#                 
#             }
#     def __init__(self, qs=None, *args, **kwargs):
#         super(App, self).__init__(*args, **kwargs)
#         if qs:
#             self.fields['plugins']=forms.ModelMultipleChoiceField(choices=Plugin.objects.all(),widget=forms.CheckboxSelectMultiple())
        
Exemplo n.º 6
0
def getAppInfo(request,app_id):
    url = 'http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsLookup?country=CN&id=%s' % app_id
    u = urllib.urlopen(url)
    content = u.read()
    u.close()
    contentObj = json.loads(unicode(content,"UTF-8"))['results'][0]    
    app = App()
    app.app_id = app_id
    exists = App.objects.filter(app_id=app_id)
    if exists:
        app = exists[0]
        
    app.title = contentObj['trackName']
    app.price = float(contentObj['price'])
    app.icon = contentObj['artworkUrl60']
    app.icon100 = contentObj['artworkUrl100']
    app.icon512 = contentObj['artworkUrl512']
    app.description = contentObj['description']
    # print contentObj['releaseDate'] 2011-02-15T02:52:45Z
    # print datetime.strptime(contentObj['releaseDate'],'%Y-%m-%dT%H:%M:%SZ')
    app.releaseDate = datetime.strptime(contentObj['releaseDate'],'%Y-%m-%dT%H:%M:%SZ')

    app.userRatingCountForCurrentVersion = Decimal(contentObj['userRatingCountForCurrentVersion'])
    app.version = contentObj['version']
    
    primaryGenreId = contentObj['primaryGenreId']
    pc = Category.objects.filter(cate_id = primaryGenreId)
    if not pc:
        primaryCate = Category()
        primaryCate.cate_id = primaryGenreId
        primaryCate.cate_name = contentObj['primaryGenreName']
        primaryCate.save()
        app.primaryCategory = primaryCate
    else:
        app.primaryCategory = pc[0]
    
    secondGenreId = contentObj['genreIds'][1]
    sc = Category.objects.filter(cate_id = secondGenreId)
    if not sc:
        secondCate = Category()
        secondCate.cate_id = secondGenreId
        secondCate.cate_name = contentObj['genres'][1]
        secondCate.save()
        app.secondCategory = secondCate
    else:
        app.secondCategory = sc[0]
        
    app.fileSizeBytes = int(contentObj['fileSizeBytes'])
    app.isGameCenterEnabled = contentObj['isGameCenterEnabled']
    app.trackCensoredName = contentObj['trackCensoredName']
    app.userRatingCount = contentObj['userRatingCount']
    app.trackContentRating = contentObj['trackContentRating']
    app.averageUserRatingForCurrentVersion = float(contentObj['averageUserRatingForCurrentVersion'])
    app.averageUserRating = float(contentObj['averageUserRating'])
    
    # app.supportedDevices = contentObj['']
    deviceSupportStr = ''
    for d in contentObj['supportedDevices']:
        deviceSupportStr = '%s,%s' % (deviceSupportStr,d)
    app.supportedDevices = deviceSupportStr
    
    languageSupport = ''
    for l in contentObj['languageCodesISO2A']:
        languageSupport = '%s,%s' % (languageSupport,l)
    app.languageCodesISO2A = languageSupport
    
    artistId = contentObj['artistId']
    print artistId
    vendors = Vendor.objects.filter(artistId = artistId)
    if not vendors:
        vendor = Vendor()
        vendor.artistId = artistId
        vendor.name = contentObj['artistName']
        vendor.url = contentObj['sellerUrl']
        vendor.seller_name = contentObj['sellerName']
        vendor.save()
    else:
        vendor = vendors[0]
        
    app.seller = vendor
    # print app.app_id
    #  print app.title
    #  print app.price
    #  print app.icon
    #  print app.icon100
    #  print app.icon512
    #  print app.description
    #  print app.releaseDate
    #  print app.version
    #  print app.primaryCategory
    #  print app.secondCategory
    #  print app.fileSizeBytes
    #  print app.isGameCenterEnabled
    #  print app.trackCensoredName
    #  print app.supportedDevices
    #  print app.languageCodesISO2A      
    app.save()
        
    for i in contentObj['ipadScreenshotUrls']:
        iPadScreenShot = iPadScreenShots()
        iPadScreenShot.ipad_screenshot_url = i
        iPadScreenShot.app = app
        exists = iPadScreenShots.objects.filter(ipad_screenshot_url=i)
        if not exists:
            iPadScreenShot.save()
        else:
            print 'already saved. need check and update operation.'
        
    for i in contentObj['screenshotUrls']:
        screenShot = ScreenShots()
        screenShot.screenshot_url = i
        screenShot.app = app
        exists = ScreenShots.objects.filter(screenshot_url=i)
        if not exists:
            screenShot.save()
        else:
            print 'already saved. need check and update operation.'
    
    #get reviews from all countries
    reviews = storeReviews(app_id)
    if len(reviews)>0:    
        #single country review
        for country_reviews in reviews:
            if len(country_reviews)>0:
                print 'Country : %s' % country_reviews[1]
                country = country_reviews[1]
                for countryReview in country_reviews[0]:
                    print "%s (%s) %s" % (countryReview['rank'],countryReview["topic"], countryReview["review"])
                    review = Reviews()
                    review.country = country
                    review.rating = int(countryReview['rank'])
                    review.topic = countryReview['topic']
                    review.review = countryReview['review']
                    review.app = app
                    review.save()
    return HttpResponse('done')
Exemplo n.º 7
0
 def create(self, validated_data):
     App.objects.create(**validated_data)
     caddy.build_caddyfile(self)
     return App(**validated_data)