def update_show(name): print '\n' + name try: show = Show.objects.get(name=name) show_id = show.id except: print name + " could not be found" return cur_eps_full = Episode.objects.filter(show_name=name) cur_eps = [] for ep in cur_eps_full: cur_eps.append(int(ep.id)) tvdb = TVDBConn() series = tvdb.initseriesbyid(str(show.id)) new_eps = series['Episode'] new_eps_ids = [] for ep in new_eps: new_eps_ids.append(int(ep['id'])) # identify removed eps for ep in cur_eps: if ep not in new_eps_ids: ep_full = Episode.objects.get(id=ep) print ep_full.name + ' removed' if not ep_full.path: ep_full.delete() else: print 'has file' for ep in new_eps: # identify new eps if int(ep['id']) not in cur_eps: print repr(ep['EpisodeName']) + ' new' Episode.create(ep, show_id, name) # update existing eps else: existing = Episode.objects.get(id=int(ep['id'])) existing.update(ep)
from django.core.management import setup_environ from mediaserver import settings setup_environ(settings) from dashboard.models import ServerTime, Show, Episode from dashboard.tvdb_api import TVDBConn serverTime = ServerTime.objects.get(pk=1) time = serverTime.time tvdb = TVDBConn() updates_day = tvdb.getupdates_day() newTime = updates_day['@time'] print "Updating TVDB..." print "Updating series info:" for series in updates_day['Series']: if(int(series['time']) > time): if(Show.objects.filter(id=series['id']).count() > 0): s = Show.objects.get(id=series['id']) print s.name s.update() print "Updating episode info:" for episode in updates_day['Episode']: if(int(episode['time']) > time): if(Episode.objects.filter(id=episode['id']).count() > 0): e = Episode.objects.get(id=episode['id']) print e.show_name + ": " + e.name e.update()