Example #1
0
def import_show_task(request):
    show_id = None
    try:
        show_id = request.POST.get("show", None)
        if show_id is None:
            raise Http404
        Show.update_or_create(None, int(show_id))
    except Http404:
        raise Http404
    except Exception, e:
        logging.error("Error Importing Show %s: %s" % (show_id, e))
        return HttpResponse("Done (with errors, %s))" % (show_id))
Example #2
0
def import_show_task(request):
    show_id = None
    try:
        show_id = request.POST.get("show", None)
        if show_id is None:
            raise Http404
        Show.update_or_create(None, int(show_id))
    except Http404:
        raise Http404
    except Exception, e:
        logging.error("Error Importing Show %s: %s" % (show_id, e))
        return HttpResponse("Done (with errors, %s))" % (show_id))
Example #3
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)))
Example #4
0
def get_choices():
    shows = Show.get_all_ordered()
    return [(str(show.idnr), {
        "name": show.ordered_name,
        "new": show.is_new,
        "tvrage_id": show.tvrage_id
    }) for show in shows]
Example #5
0
def subscribe(request):
    form = SubscriptionForm(request.POST)
    if not form.is_valid():
        return index(request, form=form)
    editing = False
    if form.cleaned_data["subkey"] == "":
        subkey = Subscription.generate_subkey()
        subscription = Subscription(last_changed=datetime.datetime.now(), subkey=subkey)
    else:
        editing = True
        subkey = form.cleaned_data["subkey"]
        subscription = form._subscription
    sub_settings = {}
    subscription.set_settings(sub_settings)

    try:
        selected_shows = Show.get_by_id(map(int, form.cleaned_data["shows"]))
    except ValueError:
        return index(request, form=form)

    old_shows = []
    if editing:
        old_shows = subscription.get_shows()

    subscription.reset_cache(selected_shows)
    subscription.put()  # stay here, need key for setting shows!

    if editing:
        subscription.set_shows(selected_shows, old_shows=old_shows)
    else:
        subscription.set_shows(selected_shows)

    response = HttpResponseRedirect(subscription.get_absolute_url())
    response.set_cookie("subkey", subkey, max_age=31536000)
    return response
Example #6
0
def redirect_to_amazon(request, show_id):
    show = Show.get_by_id(int(show_id))
    if show is None:
        raise Http404
    if not show.amazon_url:
        raise Http404
    return HttpResponseRedirect(show.amazon_url)
Example #7
0
def redirect_to_amazon(request, show_id):
    show = Show.get_by_id(int(show_id))
    if show is None:
        raise Http404
    if not show.amazon_url:
        raise Http404
    return HttpResponseRedirect(show.amazon_url)
Example #8
0
 def get_shows_old(self):
     show_dict = Show.get_all_dict()
     return [
         show_dict[str(sub_item._show)]
         for sub_item in self.subscriptionitem_set
         if str(sub_item._show) in show_dict
     ]
Example #9
0
def import_shows(request):
    from series_list import series_list
    show_names = series_list.split("\n")
    Show.clear_cache()
    for show_name in show_names:
        Show.update_or_create(show_name)
    Show.clear_cache()
    return HttpResponse("Done")
Example #10
0
def update_show(request):
    key = None
    show = None
    try:
        key = request.POST.get("key", None)
        if key is None:
            raise Http404
        show = Show.get_all_dict().get(key, None)
        if show is None:
            raise Http404
        show.update()
    except Http404:
        raise Http404
    except Exception, e:
        logging.error("Error Updating Show (%s)%s: %s" % (show, key, e))
        return HttpResponse("Done (with errors, %s(%s))" % (show, key))
Example #11
0
def update_show(request):
    key = None
    show = None
    try:
        key = request.POST.get("key", None)
        if key is None:
            raise Http404
        show = Show.get_all_dict().get(key, None)
        if show is None:
            raise Http404
        show.update()
    except Http404:
        raise Http404
    except Exception, e:
        logging.error("Error Updating Show (%s)%s: %s" % (show, key, e))
        return HttpResponse("Done (with errors, %s(%s))" % (show,key))
Example #12
0
def subscribed_shows(request):
    subcount = 0
    show_ranking = {}
    user_ranking = {}
    for subitem in SubscriptionItem.all():
        # if subscription.last_visited is not None and subscription.last_visited > threshold:
        subcount += 1
        show_ranking.setdefault(subitem._show, 0)
        show_ranking[subitem._show] += 1
        user_ranking.setdefault(subitem._subscription, 0)
        user_ranking[subitem._subscription] += 1
    tops = []
    top_users = user_ranking.items()
    for show in Show.all():
        if show.active:
            tops.append((show.name, show_ranking.get(show.key(), 0)))
    tops.sort(key=lambda x: x[1], reverse=True)
    top_users.sort(key=lambda x: x[1], reverse=True)
    return HttpResponse("Done: <br/>%s" % "<br/>".join(map(lambda x: "%s: %d" % (x[0], x[1]), tops)) + "<hr/>" + "<br/>".join(map(lambda x: "%s: %d" % (x[0], x[1]), top_users)))
Example #13
0
def subscribed_shows(request):
    subcount = 0
    show_ranking = {}
    user_ranking = {}
    for subitem in SubscriptionItem.all():
        # if subscription.last_visited is not None and subscription.last_visited > threshold:
        subcount += 1
        show_ranking.setdefault(subitem._show, 0)
        show_ranking[subitem._show] += 1
        user_ranking.setdefault(subitem._subscription, 0)
        user_ranking[subitem._subscription] += 1
    tops = []
    top_users = user_ranking.items()
    for show in Show.all():
        if show.active:
            tops.append((show.name, show_ranking.get(show.key(), 0)))
    tops.sort(key=lambda x: x[1], reverse=True)
    top_users.sort(key=lambda x: x[1], reverse=True)
    return HttpResponse(
        "Done: <br/>%s" %
        "<br/>".join(map(lambda x: "%s: %d" % (x[0], x[1]), tops)) + "<hr/>" +
        "<br/>".join(map(lambda x: "%s: %d" % (x[0], x[1]), top_users)))
Example #14
0
def subscribe(request):
    form = SubscriptionForm(request.POST)
    if not form.is_valid():
        return index(request, form=form)
    editing = False
    if form.cleaned_data["subkey"] == "":
        subkey = Subscription.generate_subkey()
        subscription = Subscription(last_changed=datetime.datetime.now(),
                                    subkey=subkey)
    else:
        editing = True
        subkey = form.cleaned_data["subkey"]
        subscription = form._subscription
    sub_settings = {}
    subscription.set_settings(sub_settings)

    try:
        selected_shows = Show.get_by_id(map(int, form.cleaned_data["shows"]))
    except ValueError:
        return index(request, form=form)

    old_shows = []
    if editing:
        old_shows = subscription.get_shows()

    subscription.reset_cache(selected_shows)
    subscription.put()  # stay here, need key for setting shows!

    if editing:
        subscription.set_shows(selected_shows, old_shows=old_shows)
    else:
        subscription.set_shows(selected_shows)

    response = HttpResponseRedirect(subscription.get_absolute_url())
    response.set_cookie("subkey", subkey, max_age=31536000)
    return response
Example #15
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)))
Example #16
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)))
Example #17
0
def get_choices():
    shows = Show.get_all_ordered()
    return [(str(show.idnr), "%s%s" % (show.ordered_name, int(show.is_new)), show.tvrage_id) for show in shows]
Example #18
0
 def get_shows_old(self):
     show_dict = Show.get_all_dict()
     return [show_dict[str(sub_item._show)] for sub_item in self.subscriptionitem_set if str(sub_item._show) in show_dict]
Example #19
0
 def get_shows(self):
     show_dict = Show.get_all_dict()
     return [
         show_dict[show_key] for show_key in self.get_show_cache()
         if show_key in show_dict
     ]
Example #20
0
def clear_cache(request):
    Show.clear_cache()
    Episode.clear_cache()
    return HttpResponse("Done.")
Example #21
0
 def get_shows(self):
     show_dict = Show.get_all_dict()
     return [show_dict[show_key] for show_key in self.get_show_cache() if show_key in show_dict]
Example #22
0
def get_choices():
    shows = Show.get_all_ordered()
    return [(str(show.idnr),
            {"name": show.ordered_name, "new": show.is_new,
            "tvrage_id": show.tvrage_id}) for show in shows]
Example #23
0
def clear_cache(request):
    Show.clear_cache()
    Episode.clear_cache()
    return HttpResponse("Done.")