def __init__(self, subAlbum, picName, control, start_response): templateLines = open(Setup.pathToTemplate) writer = start_response('200 OK',[('Content-type','text/html; charset=utf-8')]) self.writer = writer self.start_response = start_response currDir = os.path.join(Setup.albumLoc,subAlbum) album = Album(currDir,start_response) if (control == ''): if (picName != ''): pic = Pic(start_response,os.path.join(currDir,picName)) else: pic = Pic(start_response,'') else: if (control == 'first'): pic = Pic(start_response,os.path.join(currDir,album.getFirstPic())) if (control == 'previous'): pic = Pic(start_response,os.path.join(currDir,album.getPreviousPic(picName))) if (control == 'next'): pic = Pic(start_response,os.path.join(currDir,album.getNextPic(picName))) if (control == 'last'): pic = Pic(start_response,os.path.join(currDir,album.getLastPic())) #self.printMetaData(currDir, pic, control) line = ''.join(templateLines) line = line.replace('@path@', Setup.webPathToStatic) line = line.replace('@breadcrumb@', self.formatBreadCrumb(album, pic )) line = line.replace('@title@', self.formatTitle( album, pic )) line = line.replace('@albums@', self.formatAlbums( album )) line = line.replace('@pics@', self.formatPics( album, pic )) line = line.replace('@meta@', '') # line = line.replace('@meta@', self.formatMeta( album )) line = line.replace('@control@', self.formatControl( album, pic )) line = self.formatContent(line, album, currDir, pic) self.content = line.encode('utf-8')
def saveAlbum(self, album): name = album['albumName'].replace('/', '_') #替换不满足路径规则的字符 path = Config.DATAPATH + '/' + self.ownerID + '/' + Config.ALBUMLISTPATH + '/' + album[ 'albumId'] + '_' + name CommonFunction.CreatePath(path) album = Album(self.spider, self.userID, self.ownerID, album['albumId'], name, album['photoCount'], path) album.work()
def saveAlbum(self, album): name = album['albumName'].replace('/', '__') path = config.PATH + '/' + self.ownerID + '/' + config.ALBUMLISTPATH + '/' + album[ 'albumId'] + ' ' + name Common.checkPath(path) album = Album(self.userID, self.spider, self.ownerID, album['albumId'], name, album['photoCount'], path) album.work()
def addAlbum(inDict, dbFilePath): name = input('Please enter the name of the album: ') while True: try: year = int(input('Please enter release year: ')) except: print('Year must be an integer!') continue break artist = input('Please enter the artist: ') newAlbum = Album(name, artist, year) while True: newSong = input('Please add a song or type "q" to stop: ') if (newSong == 'q'): break else: newAlbum.appendSong(newSong) if (newAlbum.getArtist() not in inDict): inDict[newAlbum.getArtist()] = [] inDict[newAlbum.getArtist()].append(newAlbum) else: albumFound = False for album in inDict[newAlbum.getArtist()]: if (album.getName() == newAlbum.getName()): albumFound = True if (albumFound): print('Album already exists! Aborting.') else: inDict[newAlbum.getArtist()].append(newAlbum) dict2File(inDict, dbFilePath)
def init_db(): file = read_file("./Albums.txt") if not file: print("File Does Not Exist. Make Sure 'Albums.txt' is in the same folder") album = None for line in file: if line.strip() == '': continue elif line.__contains__('/') or line.strip() == '': tokens = line.split('/') artist = tokens[0].strip() title = tokens[1].strip() year = tokens[2].strip() album = Album(artist, title, year) album_list.append(album) elif album: tokens = line.split('-') title = tokens[0].strip() duration = get_duration_seconds(tokens[1].strip()) track = Track(title, duration) album.track_list.append(track)
def add(self): newAlbum = [] for field in self.fieldList: msg = f'\tEnter album {field}:\n\t' # newAlbum.append("test") newAlbum.append(input(msg)) # print(Album(newAlbum).__dict__) self.database.add(Album(newAlbum))
def administrador(self): break_while = True while (break_while): print(""" CHEAPY Menu Administrador 1. Ver usuarios 2. Crear usuario 3. Eliminar Usuario 4. Crear playlist 5. Eliminar playlist 6. Crear albúm 7. Eliminar albúm 8. Crear artista 9. Eliminar artista 10. Agregar comentario 11. Eliminar comentario 12. Salir """) op = int(input("ingrese opcion: ")) if (op == 1): print("La cantidad de usarios registrados es: \n", User.CONTADOR_USERS) elif (op == 2): User.registrar_usuario() elif (op == 3): User.eliminarUsuario() elif (op == 4): Lista.crearLista() elif (op == 5): Lista.eliminarLista() elif (op == 6): Album.rearAlbum() elif (op == 7): Album.eliminarAlbum() elif (op == 8): Artista.crearArtista() elif (op == 9): Artista.eliminarArtista() elif (op == 10): Comentarios.agregarComentario() elif (op == 11): Comentarios.eliminarComentario() elif (op == 12): break_while = False
def file2Dict(filePath): d = dict() dbFile = open(filePath, 'r') dbText = dbFile.read() dbtext = dbText.strip() dbList = dbText.split("\n\n") for album in dbList: albumLines = album.split("\n") i = 0 for albumLine in albumLines: if (i == 0): artist = albumLine.strip() elif (i == 1): words = albumLine.split() year = words[0].strip() name = albumLine.strip(year) name = name.strip() year = int(year) newAlbum = Album(name, artist, year) else: song = albumLine.strip('-') song = song.strip() if (song == ''): continue #splitting on last line will create blank song, ignore this else: newAlbum.appendSong(song) i += 1 if (newAlbum.getArtist() in d): d[newAlbum.getArtist()].append(newAlbum) else: d[newAlbum.getArtist()] = [] d[newAlbum.getArtist()].append(newAlbum) return d
def read(self): with open(self.description_path, 'r', encoding='utf-8') as dfile: data = dfile.read() md = markdown(data) self.html = lxml.html.fromstring(md) # ALBUM try: album_title = self.html.xpath('.//h1/a/text()')[0] album_uri = self.html.xpath('.//h1/a/@href')[0] except: raise Exception('Cannot read album title/uri') # COURSE try: course_title = self.html.xpath('.//p/a/text()')[0] course_uri = self.html.xpath('.//p/a/@href')[0] except: raise Exception('Cannot read course title/uri') # TEACHER teacher = lxml_utils.get_text_following_by_tag(self.html, 'em', "Преподаватель") teacher = re.sub(r'\s', '', teacher) if teacher not in settings.teachers_names: raise Exception('Teacher %s is not found' % teacher) teacher_name = settings.teachers_names[teacher] # DATE date = self.get_date() if date is None: raise Exception('Date field is empty') # PRODUCT content = self.get_drawings() a = Album(type='1', title=album_title, uri=album_uri, course=course_title, course_uri=course_uri, date=date, teacher=teacher_name, comment=None) for p in content: author_name, author_age, filename, product_title = p product = self.create_product(a, author_name, author_age, filename, product_title) product.image_original_path = os.path.join(self.dir_path, filename) a.add_product(product) return a
def get_album_information(self, album_id): cursor = self.con.cursor() query = '''SELECT albumTitle, bandName FROM Album WHERE albumID = ?''' cursor.execute(query, (album_id, )) self.con.commit() album_info = cursor.fetchall() album = Album(*album_info[0]) query = '''SELECT songURL, songName, songLength FROM Song WHERE albumID = ?''' cursor.execute(query, (album_id)) self.con.commit() songs_list = cursor.fetchall() for item in songs_list: song = Song(url=item[0], name=item[1], length=item[2]) album.add_song(song) return album
class ABB: """docstring for ABB""" def __init__(self): self.raiz = None def insertar(self, nombre): if self.raiz == None: self.raiz = Album(nombre) else: self.raiz.insertar(nombre) def graficar(self): return self.raiz.getCodigoGraphviz() def inorden(self): print u"Recorrido inorden del arbol binario de busqueda" self.inordenAux(self.raiz) print "\n" def getAlbum(self, nombre): return self.getAlbumAux(self.raiz, nombre) def getAlbumAux(self, actual, nombre): if actual == None: return nombre elif nombre.lower() == actual.getNombre().lower(): return actual elif nombre.lower() < actual.getNombre().lower(): return self.getAlbumAux(nombre, actual.getIzquierdo()) else: return self.getAlbumAux(nombre, actual.getDerecho()) return None def inordenAux(self, a): if a == None: return self.inordenAux(a.izquierdo) print a.nombre + "," self.inordenAux(a.derecho)
def createAlbum(self, user, albumName, albumUrl): album = Album(user, albumName, albumUrl) print(album) print(user) userAlbums = user.albums if not userAlbums: print("No albums yet") userAlbums = UserAlbums(user, [album]) print(userAlbums) return userAlbums print("already found albums") userAlbums.addAlbum(album) print(userAlbums) return userAlbums
class ABB: """docstring for ABB""" def __init__(self): self.raiz = None def insertar(self, nombre, listaCanciones): if self.raiz == None: self.raiz = Album(nombre, listaCanciones) else: self.raiz.insertar(nombre, listaCanciones) def graficar(self): return self.raiz.getCodigoGraphviz() def inorden(self): print u"Recorrido inorden del arbol binario de busqueda" self.inordenAux(self.raiz) print "\n" def getAlbum(self, nombre): return self.inordenAux(self.raiz) def getAlbumAux(self, actual, nombre): if actual == None: return self.inordenAux(actual.izquierdo) if actual.nombre == nombre: return actual self.inordenAux(actual.derecho) def inordenAux(self, a): if a == None: return self.inordenAux(a.izquierdo) print a.nombre + "," self.inordenAux(a.derecho)
def _retrieve_albums(self, limit=20, offset=0, session=None): user_id = self._get_safe('user_id') if user_id: albums = api.request('/user/' + user_id + '/albums', session, method='GET', params=dict( limit=limit, offset=offset, )) if albums: for album in albums['albums']: yield (Album(meta={'album': album}), albums['page']['total'])
def retrieveAlbums(self): sql = "SELECT * from album" cur.execute(sql) self.myAlbums = [] for row in cur: a = Album() a.album_id = row[0] a.title = row[1] a.band_name = row[2] a.band_id = row[3] self.myAlbums.append(a)
def retrieveBandAlbums(self): albums = [] sql = "SELECT * from album where band_id = '" + str(self.band_id) + "'" cur.execute(sql) for row in cur: a = Album() a.album_id = row[0] a.title = row[1] a.band_name = row[2] a.band_id = row[3] albums.append(a) return albums
def getAblumInfo(self, url): try: response = requests.get(url).json() albumObj = Album() albumObj.setAlbumName(response["album"]["name"]) albumObj.setArtistName(response["album"]["artist"]) if "wiki" in response["album"]: albumObj.setPublishDate(response["album"]["wiki"]["published"]) elif "tags" in response["album"]: albumObj.setPublishDate( response["album"]["tags"]["tag"][0]["name"]) for x in response["album"]["image"]: if (x["size"] == "large"): albumObj.setImageUrl(x["#text"]) break return albumObj except requests.exceptions.RequestException as e: print("Error.") print(e)
def insertar(self, nombre, listaCanciones): if self.raiz == None: self.raiz = Album(nombre, listaCanciones) else: self.raiz.insertar(nombre, listaCanciones)
import os import sys sys.path.append(os.path.join(os.path.dirname(__file__), '../src/')) from Photo import Photo from Album import Album GROUP_PHOTO_1_PATH = os.path.join(os.path.dirname(__file__), './static/group1.jpg') GROUP_PHOTO_2_PATH = os.path.join(os.path.dirname(__file__), './static/group2.jpg') GROUP_PHOTO_3_PATH = os.path.join(os.path.dirname(__file__), './static/group3.jpg') my_album = Album() group1_photo = Photo(GROUP_PHOTO_1_PATH) group2_photo = Photo(GROUP_PHOTO_2_PATH) group3_photo = Photo(GROUP_PHOTO_3_PATH) my_album.insert_photo(group1_photo) my_album.insert_photo(group2_photo) my_album.insert_photo(group3_photo) my_album.facial_classification() print(group1_photo.id_to_face) print(group2_photo.id_to_face) print(group3_photo.id_to_face) assert(group1_photo.id_to_face.keys()==group2_photo.id_to_face.keys()==group3_photo.id_to_face.keys()) #todo: test facial classification where different people change
else: artistSongs[songNum].playSong() if choice2 == "4": MP.retrieveArtists() MP.viewArtists() if choice2 == "5": break if choice == "3": while True: choice2 = input("1. add new Album 2. Delete Album 3. Play Songs to a certain Album" + " 4. View all Albums 5. back:\n") if choice2 == "1": album = Album() album.title = input("Enter album title:") MP.retrieveBands() MP.viewBands() bandNum = int(input("Enter band #:"))-1 album.band_name = MP.myBands[bandNum].name album.band_id = MP.myBands[bandNum].band_id album.addAlbum() if choice2 == "2": aID = int(input("Enter # of album:")) MP.retrieveAlbums() MP.myAlbums[aID-1].deleteAlbum() if choice2 == "3": MP.retrieveAlbums()
p = Artista('NULL','NULL','NULL') z = p.LeerArt() for a in z: print(a.idArtista, " - ", a.Nombre, " - ", a.Conciertos) elif a =='3': p = Artista('NULL','NULL','NULL') id_borrar = input ("Ingrese ID a Borrar: ") p.BorrarArt(id_borrar) elif a =='4': p = Artista('NULL','NULL','NULL') id_update = input("Ingrese ID a Actualizar: ") nombre_nuevo = input("Ingrese Nombre a Actualizar: ") concierto_nuevo = input("Ingrese Concierto a Actualizar: ") p.ActualizarArt(nombre_nuevo,concierto_nuevo,id_update) elif a =='5': p = Album('NULL','NULL','NULL') nom_al = input("Ingrese Nombre Album: ") fech_lan = input("Ingresar Fecha de Lanazamiento: ") p.InsertAl(nom_al,fech_lan) elif a == '6': p = Album('NULL','NULL','NULL') z = p.LeerAl() for a in z: print(a.idAlbum, ' - ',a.Nombre_Album, " - ", a.Fecha_Lanzamiento) elif a =='7': p = Album('NULL','NULL','NULL') id_borrar = input ("Ingrese ID a Borrar: ") p.BorrarAl(id_borrar) elif a =='8': p = Album('NULL','NULL','NULL') id_update = input("Ingrese ID a Actualizar: ")
""" author : Jagepard <*****@*****.**> license https://mit-license.org/ MIT """ from Album import Album from Interpreter import Interpreter interpreter = Interpreter() interpreter.addAlbumToRegistry(Album("Untouchables", "Korn")) interpreter.addAlbumToRegistry(Album("Adrenaline", "Deftones")) interpreter.interpret("album 2") interpreter.interpret("album author 2") interpreter.interpret("album author 1") interpreter.interpret("author 1")
def getAlbumInfo(token_info, songList): name = token_info['name'] artistList = [] for x in token_info['artists']: artistList.append(x['name']) imageList = [] for x in token_info['images']: imageList.append(x['url']) album = Album() if (len(imageList) >= 1): album.setImageLarge(imageList[0]) if (len(imageList) >= 2): album.setImageSmall(imageList[1]) album.setName(name) album.setArtists(artistList) album.setTracks(songList) return album
with open("albumid.txt", encoding="utf-8") as file: l_artistid = [] # (obj) List kus on kõik "Artist" objektid l_albumid = [] # (obj) List kus on kõik "Album" objektid l_laulud = [] # (obj) List kus on kõik "Laul" objektid l_art_nimed = [] # (str) List kus on kõikide "Artist" objektide nimed sees for line in file: artist, albumi_pealkiri, ilmumis_aasta, laulu_pealkiri = line.strip( "\n").split("\t") if artist not in l_art_nimed: l_artistid.append(Artist(artist)) l_art_nimed.append(artist) l_albumid.append( Album(albumi_pealkiri, ilmumis_aasta, l_artistid[-1])) l_artistid[-1].lisa_album(l_albumid[-1]) elif l_artistid[l_art_nimed.index( artist)].albumid[-1].nimi != albumi_pealkiri: l_albumid.append( Album(albumi_pealkiri, ilmumis_aasta, l_artistid[-1])) l_artistid[l_art_nimed.index(artist)].lisa_album(l_albumid[-1]) else: pass l_laulud.append(Laul(laulu_pealkiri, l_artistid[-1], l_albumid[-1])) l_artistid[-1].albumid[-1].lisa_laul(l_laulud[-1]) # Üldine otsing #while True:
import os import sys sys.path.append(os.path.join(os.path.dirname(__file__), '../src/')) from Photo import Photo from Album import Album BLINK_PHOTO_PATH = os.path.join(os.path.dirname(__file__), './static/johnny_blink6.jpg') NOBLINK_PHOTO_PATH = os.path.join(os.path.dirname(__file__), './static/johnny_noblink1.jpg') # BLINK_PHOTO_PATH = os.path.join(os.path.dirname(__file__), './static/jeff_test/Jeff_blink.PNG') # NOBLINK_PHOTO_PATH = os.path.join(os.path.dirname(__file__), './static/jeff_test/jeff_noblink.PNG') my_album = Album() blink_photo = Photo(BLINK_PHOTO_PATH) noblink_photo = Photo(NOBLINK_PHOTO_PATH) my_album.insert_photo(blink_photo) my_album.insert_photo(noblink_photo) my_album.facial_classification() # blink_photo.blink_detect() # noblink_photo.blink_detect() my_album.update_base_photo_index(0) my_album.blink_detection() # person_id and photo_id of new face # my_album.face_swap(swap_person_id = 0, newFace_photo_id = 1)
def saveAlbum(self,album): name = album['albumName'].replace('/','__') path = config.PATH + '/' + self.ownerID + '/' + config.ALBUMLISTPATH + '/' + album['albumId'] + ' ' + name Common.checkPath(path) album = Album(self.userID,self.spider,self.ownerID,album['albumId'],name,album['photoCount'],path) album.work()
def upload_file(): # check for numFiles entry if 'numFiles' not in request.form or request.form['numFiles'] == "": content = {"Error": "Missing 'numFiles' in POST request"} return content, 400 numFiles = int(request.form['numFiles']) if numFiles == 0: content = {"Error": "No files added in POST request"} return content, 400 if 'basePhotoIndex' not in request.form or request.form[ 'basePhotoIndex'] == "": content = {"Error": "Missing 'basePhotoIndex' in POST request"} return content, 400 basePhotoIndex = int(request.form['basePhotoIndex']) # Error check for i in range(numFiles): entry = 'file[' + str(i) + ']' if entry not in request.files: content = {"Error": "Missing " + entry + " in POST request"} return content, 400 file = request.files[entry] if file.filename == '': content = {"Error": "File field is empty in POST request"} return content, 400 if not (file and allowed_file(file.filename)): content = { "Error": "File is wrong format (only accepts png, jpg, jpeg)" } return content, 400 # Create a new session scale_percent = 0 newAlbum = Album(scale_percent) new_session_id = appSessions.new_session(newAlbum) session_path = os.path.join(uploadFolder, new_session_id) os.mkdir(session_path) output_photo_path = "" # Save file in path for i in range(numFiles): entry = 'file[' + str(i) + ']' file = request.files[entry] filename = secure_filename(file.filename) if (i == basePhotoIndex): output_photo_path = os.path.join(session_path, "retouched_" + filename) file.save(os.path.join(session_path, filename)) newAlbum.insert_photo(Photo(os.path.join(session_path, filename))) newAlbum.facial_classification() newAlbum.update_base_photo_index(basePhotoIndex) newAlbum.blink_detection() newAlbum.remove_blinking_faces() newAlbum.write_output_photo(output_photo_path) newAlbum.status = "READY" content = {"session_id": new_session_id} return content, 200
def insertar(self, nombre): if self.raiz == None: self.raiz = Album(nombre) else: self.raiz.insertar(nombre)
def createAlbum(self, song, id, dirpath): """Crea un objeto album""" album = Album(song, id, dirpath) return album