Ejemplo n.º 1
0
    def update_show(self):
        status = 'success'
        try:

            data = cherrypy.request.json
            show_id = data['showid']
            action = data['action']

            if action == 'refresh':
                Utils.add_episodes(show_id)

            if action == 'remove':
                s = cherrypy.request.db.query(Show).filter(Show.show_id == show_id).first()
                ActionLog.log('"%s" removed.' % s.show_name)
                cherrypy.request.db.delete(s)
                cherrypy.request.db.commit()

        except Exception as ex:
            # logger.exception(ex)
            status = 'error'

        return json.dumps(status)
Ejemplo n.º 2
0
    def add_show(self):
        status = 'success'
        try:
            data = cherrypy.request.json
            series_id = data['seriesid']
            t = tvdb_api.Tvdb()
            s = t[series_id]
            # db = models.connect()
            if cherrypy.request.db.query(Show).filter(Show.show_id == series_id).first() is None:
                # save new show to db
                first_aired_date = datetime.strptime(s['firstaired'], "%Y-%m-%d")
                new_show = Show(show_id=series_id, show_name=s['seriesname'], first_aired=first_aired_date,
                                is_active=s.data['status'] == 'Continuing', banner=s['banner'])

                if new_show.banner == None:
                    new_show.banner = ''

                # create folder based on show name:
                new_show.show_directory = '/' + new_show.show_name.replace('.', '').strip()
                phys_directory = cherrypy.request.db.query(Config).first().tv_parent_directory + new_show.show_directory
                if not os.path.exists(phys_directory):
                    os.makedirs(phys_directory)

                cherrypy.request.db.add(new_show)
                cherrypy.request.db.commit()
                ActionLog.log('"%s" added.' % new_show.show_name)
                Utils.add_episodes(series_id, t, cherrypy.request.db)
            else:
                status = 'duplicate'
                # http://stackoverflow.com/questions/7753073/jquery-ajax-post-to-django-view
        except Exception as ex:
            # logger.exception(ex)
            ActionLog.log(ex)
            status = 'error'

        return json.dumps(status)