Example #1
0
 def artists(self, request):
     '''API endpoint to query for artists'''
     next_page = request.next_page or 'first_artists_page'
     cache = memcache.get(next_page)
     if cache:
         return ArtistsResponse(artists=cache[0], next_page=cache[1])
     query = Artist.query()
     if next_page is 'first_artists_page':
         artists, cursor, more = query.fetch_page(300) 
     else:
         artists, cursor, more = query.fetch_page(300, 
                 start_cursor=Cursor.from_websafe_string(next_page))
     artists = [artist.to_message() for artist in artists]
     memcache.add(next_page, (artists, cursor.to_websafe_string()))
     return ArtistsResponse(artists=artists, next_page=cursor.to_websafe_string())
Example #2
0
    def get(self):
        # if 'X-AppEngine-Cron' not in self.request.headers:
        # self.error(403)
        artists = Artist.query().fetch()
        myObj = DemoClass()
        myList = []

        myObj.artista = len(artists)
        myList.append(myObj)
        allArtists = " ".join(str(x) for x in myList)

        bucketName = app_identity.get_default_gcs_bucket_name()
        fileName = "/" + bucketName + "/somedir/somefile.txt"

        with cloudstorage.open(fileName, "w") as gcsFile:
            gcsFile.write(allArtists)
Example #3
0
    def get(self):

        empresas = Empresa.query().fetch()

        myList = []
        for i in empresas:
            empObj = DemoClass()
            empObj.nombre = i.nombre_empresa
            empObj.codigo = i.codigo_empresa
            empObj.id_empresa = i.entityKey
            empObj.lat = i.lat
            empObj.lng = i.lng
            myList.append(empObj.nombre)

            emp_key = ndb.Key(urlsafe=empObj.id_empresa)
            objemp = emp_key.get()
            strKey = objemp.key.urlsafe()
            myEmpKey = ndb.Key(urlsafe=strKey)
            myartist = Artist.query(Artist.empresa_key == myEmpKey)

            for i in myartist:
                artObj = DemoClass()
                artObj.nombre = i.nombre
                artObj.urlImage = i.urlImage
                artObj.id_artist = i.entityKey
                myList.append(artObj.nombre)
                myList.append("\n")

        allArtists = "\n".join(str(x) for x in myList)

        fileName = "/" + bucketName + "/artists.txt"

        try:
            with cloudstorage.open(fileName, "r") as gcsFile:
                tempStorage = gcsFile.read()
                tempStorage += "\n"
        except:
            tempStorage = ""

        with cloudstorage.open(fileName, "w") as gcsFile:
            gcsFile.write(str(allArtists))
            # gcsFile.write(tempStorage + str(allArtists))

        with cloudstorage.open(fileName, "r") as gcsFile:
            output = gcsFile.read()
        self.response.out.write(output)
Example #4
0
    def get(self):
        self.response.headers.add_header('Access-Control-Allow-Origin', '*')
        self.response.headers['Content-Type'] = 'application/json'

        id_empresa = self.request.get('empresa')
        emp_key = ndb.Key(urlsafe=id_empresa)
        objemp = emp_key.get()
        strKey = objemp.key.urlsafe()
        myEmpKey = ndb.Key(urlsafe=strKey)
        myartist = Artist.query(Artist.empresa_key == myEmpKey)

        myList = []
        for i in myartist:
            myObj = DemoClass()
            myObj.nombre = i.nombre
            myObj.urlImage = i.urlImage
            myObj.id_artist = i.entityKey
            myList.append(myObj)

        json_string = json.dumps(myList, default=MyClass)
        self.response.write(json_string)
Example #5
0
def begin_fetch_shows():
    for artist in Artist.query().fetch(keys_only=True):
        deferred.defer(fetch_shows, artist)