def rawPost(self, ballotID, voteID): vote = self.getVote(ballotID, voteID) id = self.request.get('release.id', default_value=None) mbid = self.request.get('release.mbid', default_value=None) if id: vote.release = db.Key.from_path(Release.kind(), int(id)) elif mbid: vote.release = Release.get(mbid) else: id = self.request.get('artist.id', default_value=None) mbid = self.request.get('artist.mbid', default_value=None) if id: artist = db.Key.from_path(Artist.kind(), int(id)) elif mbid: artist = Artist.get(mbid) else: artist = Artist(name=self.request.get('artist'), sortname=self.request.get('sortname')) artisturl = self.request.get('artisturl', default_value=None) if artisturl: artist.url = artisturl artist.put() release = Release(artist=artist, title=self.request.get('title')) releaseurl = self.request.get('releaseurl', default_value=None) if releaseurl: release.url = releaseurl release.put() vote.release = release vote.put() next = Vote.gql('WHERE release = :1 ORDER BY artist', None).get() if next: key = next.key() self.redirect('../%d/%d' % (key.parent().id(), key.id())) else: self.redirect('../..')
def artist_insert(self, request): if request.from_datastore: my_quote = request else: my_quote = Artist(fname=request.fname, lname=request.lname, website_url=request.website_url, description=request.description, image=request.image) my_quote.put() return my_quote
def search_artist_from_name(artist_name, movie=None, director_name=None): """ Retrieve artist info from IMDB by name of artist. :param artist_name: name of the actor to retrieve info :type artist_name: string :return: Actor's key :rtype: ndb.Key :raise RetrieverError: if there is an error from MYAPIFILMS """ url = BASE_URL_MYAPIFILMS + 'imdb?name=' + artist_name + '&format=JSON&filmography=0&limit=1&lang=en-us&exactFilter=0&bornDied=0&starSign=0&uniqueName=0&actorActress=0&actorTrivia=0&token=307cccfe-d20b-4b69-b976-d6a024538864' json_page = get(url).encode('utf-8') json_data = json.loads(json_page) if type(json_data) is not list: # If it is not a list there is a problem raise RetrieverError(json_data['code'], json_data['message']) try: photo = clear_url(json_data[0]['urlPhoto']) except Exception: logging.info("Photo not found") photo = "None" artist = Artist(id=json_data[0]['idIMDB'], name=json_data[0]['name'], photo=photo) if movie is not None: if director_name is not None: movie.add_director(artist) else: movie.add_actor(artist) return artist.put()
def post(self): if self.request.get("entityKey"): artist_key = ndb.Key(urlsafe=self.request.get("entityKey")) artist = artist_key.get() artist.fname = self.request.get("fname") artist.lname = self.request.get("lname") artist.image = self.request.get("image") artist.website_url = self.request.get("website_url") artist.description = self.request.get("description") artist.put() else: new_artist = Artist(fname = self.request.get("fname"), lname = self.request.get("lname"), image = self.request.get("image"), website_url = self.request.get("website_url"), description = self.request.get("description")) new_artist.put() self.redirect(self.request.referer)
def generate_data(): faker = Faker() for i in range(0, 24): name = faker.name() u = User(name=name) u.put() full = faker.lorem() firstbio, secounddis = full[:len(full) / 2], full[len(full) / 2:] a = Artist(name=name, owner=u._key, is_active=True, location=faker.full_address(), bio=firstbio) a.put() cover_art = "http://lorempixel.com/1024/1024/{}".format( random.choice(image_sets)) track_list = [] for i in range(0, 12): t = Track(title=faker.name(), artist_id=a._key, artist_name=a.name, source_file=random.choice(song_set), explicit=False, is_active=True, price=CurrencyValue(amount=0, currency="USD")) t.put() track_list.append(t._key) alb = Album(title=faker.name(), artist_name=a.name, artist_id=a._key, tracks=track_list, cover_art=cover_art, description=secounddis, release_date=datetime.utcnow(), genre_id=random.choice(genres), price=CurrencyValue(amount=0, currency="USD"), is_active=True) alb.put()
def retrieve_artists(movie, actors_list, directors_list, writers_list): """ Retrieve all artist in a movie from actors, directors and writers lists. :param movie: Movie object in order to add actors, directors and writers :type movie: Movie :param actors_list: list of actors :type actors_list: list of dict :param directors_list: list of directors :type directors_list: list of dict :param writers_list: list of writers :type writers_list: list of dict """ for json_data in actors_list: actor = Artist(id=json_data['actorId'], name=json_data['actorName'], photo=clear_url(json_data['urlPhoto'])) actor.put() movie.add_actor(actor) for json_data in directors_list: director = Artist(id=json_data['nameId'], name=json_data['name']) director.put() movie.add_director(director) for json_data in writers_list: writer = Artist(id=json_data['nameId'], name=json_data['name']) writer.put() movie.add_writer(writer)
def retrieve_artist_from_id(artist_id): """ Retrieve artist info from IMDB by id of artist. :param artist_id: id of the artist to retrieve info :type artist_id: string :return: Artist's key :rtype: ndb.Key :raise RetrieverError: if there is an error from MYAPIFILMS """ logging.info('Retrieving %s', artist_id) url = BASE_URL_MYAPIFILMS + 'imdb?idName=' + artist_id + '&format=JSON&filmography=0&lang=en-us&bornDied=0&starSign=0&uniqueName=0&actorActress=0&actorTrivia=0&actorPhotos=N&actorVideos=N&salary=0&spouses=0&tradeMark=0&personalQuotes=0&token=307cccfe-d20b-4b69-b976-d6a024538864' json_page = get(url).encode('utf-8') json_data = json.loads(json_page) artist = Artist(id=json_data["idIMDB"], name=json_data["name"], photo=clear_url(json_data["urlPhoto"]) if ('urlPhoto' in json_data and json_data['urlPhoto'] != "") else None) return artist.put()
from google.appengine.ext import db from google.appengine.ext import ndb from models import Sculpture, Artist, Comment import jinja2 import webapp2 ''' Instructions: Start google app engine server, go to http://localhost:8000/console paste into interactive console click the blue 'Execute' button ''' pprint.pprint(os.environ.copy()) ARTIST_KEY = ndb.Key("Entity", "artist_root") new_artist = Artist(parent = ARTIST_KEY, fname = "fname", lname = "lname", website_url = "website_url", description = "description") new_artist.put() SCULPTURE_KEY = ndb.Key("Entity", "sculpture_root") new_sculpture = Sculpture(parent = SCULPTURE_KEY, title = "title", artist = new_artist.key, location = db.GeoPt(55,55), description = "description", image = "image") new_sculpture.put()