Exemplo n.º 1
0
def import_show(request):
    this_url = reverse("seriesly-shows-import_show")
    user = users.get_current_user()
    nick = "Anonymous"
    if user:
        nick = user.nickname()
    if user and user.email() in settings.ADMIN_USERS:
        if request.method == "GET":
            return HttpResponse("""Hi %s,<br/>
                <a href="http://services.tvrage.com/feeds/search.php?show=">Search for shows on TVRage</a><br/>
                Enter TV Rage ID: <form action="." method="post">
                <input type="text" name="show"/><input type="submit"/></form><a href="%s">Logout</a>""" % (nick, users.create_logout_url(this_url)))
        else:
            name = request.POST["show"]
            if name.startswith("!"):
                Show.update_or_create(name[1:])
            elif name.startswith("@"):
                show_ids=name[1:].split(',')
                for show_id in show_ids:
                    Show.update_or_create(None, int(show_id))
            else:
                show_id = int(name)
                Show.update_or_create(None, show_id)
            Show.clear_cache()
            Episode.clear_cache()
            return HttpResponseRedirect(this_url+"?status=Done")
    else:
        return HttpResponse("""Hi %s,<a href=\"%s\">Sign in</a>.""" % (nick, users.create_login_url(this_url)))
Exemplo n.º 2
0
def _guide(request, subscription, template="guide.html", public=False, extra_context=None):
    subscription.is_public = public
    sub_settings = subscription.get_settings()
    now = datetime.datetime.now()
    the_shows = subscription.get_shows()
    episodes = Episode.get_for_shows(the_shows, order="date")
    twentyfour_hours_ago = now - datetime.timedelta(hours=24)
    recently = []
    last_week = []
    upcoming = []
    for episode in episodes:
        if episode.date < twentyfour_hours_ago:
            last_week.append(episode)
        elif episode.date <= now:
            recently.append(episode)
        else:
            upcoming.append(episode)
    context = {"subscription":subscription, 
                "recently": recently, 
                "upcoming": upcoming, 
                "last_week": last_week}
    if extra_context is not None:
        context.update(extra_context)
    response = render_to_response(template, RequestContext(request, context))
    if not public:
        response.set_cookie("subkey", subscription.subkey)
    try:
        if subscription.check_beacon_status(now):
            subscription.put() # this put is not highly relevant
    except Exception, e:
        logging.warning(e)
Exemplo n.º 3
0
 def get_icalendar(self, public):
     """Nice hints from here: http://blog.thescoop.org/archives/2007/07/31/django-ical-and-vobject/"""
     the_shows = self.get_shows()
     # two_weeks_ago = now - datetime.timedelta(days=7)
     # five_hours = datetime.timedelta(hours=5)
     sub_settings = self.get_settings()
     episodes = Episode.get_for_shows(the_shows, order="date")
     cal = vobject.iCalendar()
     cal.add('method').value = 'PUBLISH'  # IE/Outlook needs this
     for episode in episodes:
         vevent = episode.create_event_details(cal)
     return cal.serialize()
Exemplo n.º 4
0
 def get_icalendar(self, public):
     """Nice hints from here: http://blog.thescoop.org/archives/2007/07/31/django-ical-and-vobject/"""
     the_shows = self.get_shows()
     # two_weeks_ago = now - datetime.timedelta(days=7)
     # five_hours = datetime.timedelta(hours=5)
     sub_settings = self.get_settings()
     episodes = Episode.get_for_shows(the_shows, order="date")
     cal = vobject.iCalendar()
     cal.add('method').value = 'PUBLISH'  # IE/Outlook needs this
     for episode in episodes:
         vevent = episode.create_event_details(cal)
     return cal.serialize()
Exemplo n.º 5
0
def _feed(request, subscription, template, public=False):
    now = datetime.datetime.now()
    sub_settings = subscription.get_settings()
    subscription.updated = now.strftime('%Y-%m-%dT%H:%M:%SZ')
    subscription.expires = (now + datetime.timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%SZ')
    the_shows = subscription.get_shows()
    wait_time = datetime.timedelta(hours=6)
    episodes = Episode.get_for_shows(the_shows, before=now, order="-date")
    items = []
    for episode in episodes:
        if now > episode.date + wait_time:
            pub_date = episode.date_local
            episode.pub_date = pub_date
            items.append(episode)
    return render_to_string(template, RequestContext(request, {"subscription":subscription, "items": items}))
Exemplo n.º 6
0
 def get_message_context(self):
     the_shows = self.get_shows()
     now = datetime.datetime.now()
     twentyfour_hours_ago = now - datetime.timedelta(hours=24)
     episodes = Episode.get_for_shows(the_shows, after=twentyfour_hours_ago, order="date")
     if not len(episodes):
         return None
     context = {"subscription": self, "items": []}
     for episode in episodes:
         if episode.date > now:
             self.next_airtime = episode.date.date()
             break
         context["items"].append(episode)
     if not context["items"]:
         return None
     return context
Exemplo n.º 7
0
 def get_message_context(self):
     the_shows = self.get_shows()
     now = datetime.datetime.now()
     twentyfour_hours_ago = now - datetime.timedelta(hours=24)
     episodes = Episode.get_for_shows(the_shows,
                                      after=twentyfour_hours_ago,
                                      order="date")
     if not len(episodes):
         return None
     context = {"subscription": self, "items": []}
     for episode in episodes:
         if episode.date > now:
             self.next_airtime = episode.date.date()
             break
         context["items"].append(episode)
     if not context["items"]:
         return None
     return context
Exemplo n.º 8
0
def _feed(request, subscription, template, public=False):
    now = datetime.datetime.now()
    sub_settings = subscription.get_settings()
    subscription.updated = now.strftime('%Y-%m-%dT%H:%M:%SZ')
    subscription.expires = (
        now + datetime.timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%SZ')
    the_shows = subscription.get_shows()
    wait_time = datetime.timedelta(hours=6)
    episodes = Episode.get_for_shows(the_shows, before=now, order="-date")
    items = []
    for episode in episodes:
        if now > episode.date + wait_time:
            pub_date = episode.date_local
            episode.pub_date = pub_date
            items.append(episode)
    return render_to_string(
        template,
        RequestContext(request, {
            "subscription": subscription,
            "items": items
        }))
Exemplo n.º 9
0
def _guide(request,
           subscription,
           template="guide.html",
           public=False,
           extra_context=None):
    subscription.is_public = public
    sub_settings = subscription.get_settings()
    now = datetime.datetime.now()
    the_shows = subscription.get_shows()
    episodes = Episode.get_for_shows(the_shows, order="date")
    twentyfour_hours_ago = now - datetime.timedelta(hours=24)
    recently = []
    last_week = []
    upcoming = []
    for episode in episodes:
        if episode.date < twentyfour_hours_ago:
            last_week.append(episode)
        elif episode.date <= now:
            recently.append(episode)
        else:
            upcoming.append(episode)
    context = {
        "subscription": subscription,
        "recently": recently,
        "upcoming": upcoming,
        "last_week": last_week
    }
    if extra_context is not None:
        context.update(extra_context)
    response = render_to_response(template, RequestContext(request, context))
    if not public:
        response.set_cookie("subkey", subscription.subkey)
    try:
        if subscription.check_beacon_status(now):
            subscription.put()  # this put is not highly relevant
    except Exception, e:
        logging.warning(e)
Exemplo n.º 10
0
def clear_cache(request):
    Show.clear_cache()
    Episode.clear_cache()
    return HttpResponse("Done.")
Exemplo n.º 11
0
def update(request):
    shows = Show.get_all_ordered()
    for show in shows:
        show.add_update_task()
    Episode.add_clear_cache_task("series")
    return HttpResponse("Done: %d" % (len(shows)))
Exemplo n.º 12
0
def update(request):
    shows = Show.get_all_ordered()
    for show in shows:
        show.add_update_task()
    Episode.add_clear_cache_task("series")
    return HttpResponse("Done: %d" % (len(shows)))
Exemplo n.º 13
0
def clear_cache(request):
    Show.clear_cache()
    Episode.clear_cache()
    return HttpResponse("Done.")