Ejemplo n.º 1
0
def _guide(request, subscription, template="subscription/guide.html",
           public=False, extra_context=None):
    subscription.is_public = public
    subscription.get_settings()
    now = timezone.now()
    the_shows = subscription.get_shows()
    episodes = Episode.get_for_shows(the_shows, order="date")
    twentyfour_hours_ago = now - 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(request, template, context)
    if not public:
        response.set_cookie("subkey", subscription.subkey)
    return response
Ejemplo n.º 2
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()
     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:
         episode.create_event_details(cal)
     return cal.serialize()
Ejemplo n.º 3
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
Ejemplo n.º 4
0
def _feed(request, subscription, template, public=False, mimetype="application/atom+xml"):
    now = timezone.now()
    subscription.get_settings()

    subscription.updated = now.strftime('%Y-%m-%dT%H:%M:%SZ')
    subscription.expires = (now + timedelta(days=1)).strftime('%Y-%m-%dT%H:%M:%SZ')

    the_shows = subscription.get_shows()
    wait_time = 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(request, template, {
        "subscription": subscription,
        "items": items
    }, content_type=mimetype)
Ejemplo n.º 5
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)))
Ejemplo n.º 6
0
def clear_cache(request):
    Show.clear_cache()
    Episode.clear_cache()
    return HttpResponse("Done.")