Пример #1
0
 def __init__(self, *args):
     helper = 'unknown error with arguments: ' + str(args)
     if len(args) > 1:
         [name, audio, lyrics] = args
         try:
             song = Song(title=name, audio=audio, text=lyrics)
             song.insert()
         except Exception as e:
             raise Tune_error(' Initializing Object') from e
     elif len(args) > 3:
         [name, audio, lyrics, conductor] = args
         try:
             song = Song(title=name,
                         audio=audio,
                         text=lyrics,
                         conductor=conductor)
             song.insert()
         except Exception as e:
             raise Tune_error(' Initializing Object') from e
     else:
         try:
             song = Song.query.filter_by(id=args[0]).first()
             helper = 'no such song were found on our database '
         except Exception as e:
             raise Tune_error(
                 'Database error while looking for song.') from e
     try:
         self.song = song
         # db.session.close()
     except Exception as e:
         raise Tune_error(helper) from e
Пример #2
0
 def convert(self):
     tune_log.log('converting')
     try:
         converted = Song(title=self.song.title,
                          audio=self.song.audio,
                          text=self.song.text,
                          conductor=self.song.conductor)
         tune_log.log('converting {}'.format(self.song.format()))
         converted.insert()
     except Exception as e:
         raise Tune_error('Test => Database error while converting.') from e
     return json.dumps({'success': self.__str__()})