Exemplo n.º 1
0
def search_results():
    search_input = request.form.get("search")

    r = requests.get('http://thetvdb.com/api/GetSeries.php?seriesname='+search_input)
    xml_doc = r.text
    xml_doc = xml_doc.encode('utf-8')
    pyQ = pq(xml_doc, parser='xml')

    series_search_results = pyQ('Series')
    series_list = []
    for s in series_search_results:
        single_series_id =(pyQ(s).find('id').text())
        single_series = model.parse_series(single_series_id)

        external_id = int(single_series('id').text())
        title = single_series('SeriesName').text()

        if single_series('poster').text() != '':
            poster = "http://thetvdb.com/banners/"+single_series('poster').text()
            series_obj = model.Series(external_id=external_id, poster=poster, title=title) 
            series_list.append(series_obj)
        
    series_list=series_tuple_list(series_list)
    print series_list
    
    return render_template("search.html", series_list=series_list, 
                                            search_input=search_input) 
Exemplo n.º 2
0
 def get(self):
     r = requests.get(
         "http://tmi.twitch.tv/group/user/shaflumbles/chatters")
     r.encoding
     jsonr = r.json()
     return jsonr['chatters']['viewers'] + jsonr['chatters']['moderators']
Exemplo n.º 3
0
def display_series_info(external_series_id):

    # Check to see if series is already in database. If not, adds it to the database
    count = DB.query(Series).filter_by(external_id = external_series_id).count()

    if count == 0:
        add_series(external_series_id)
    series = DB.query(Series).filter_by(external_id = external_series_id).one()
    banner = requests.get(series.banner).content

    count2 = DB.query(UserSeries).filter_by(
                                    series_id=series.id, 
                                    user_id=current_user.id).count()

    # Check to see what state the series had (watched, to-watch, watching)
    if count2 != 0:
        state = DB.query(UserSeries).filter_by(
                                        series_id=series.id, 
                                        user_id=current_user.id).one().state
    else:
        state = '';

    favorite_series = DB.query(model.Favorite).filter_by(series_id=series.id, user_id=current_user.id).first()

    if favorite_series != None:
        favorite = True
    else:
        favorite = False
    
    # all episodes of series organized by season
    #{1:[ep, ep, ep], 2:[ep,ep,ep], ...}

    eps_list = DB.query(Episode).filter_by(series_id=series.id).order_by(Episode.season_num).all()
    season_dict = {}
   
    for e in eps_list:
        if season_dict.get(e.season_num) == None:
            season_dict[e.season_num]=[e]
        else:
            season_dict[e.season_num].append(e)

    # in each episode list per season key, sort by episode number
    for key, val in season_dict.iteritems():
        val.sort(key=operator.attrgetter("ep_num"))

    rating_count = DB.query(model.Rating).filter_by(series_id=series.id, user_id=current_user.id).count()
    if rating_count != 0:
        rating_value = DB.query(model.Rating).filter_by(series_id=series.id, user_id=current_user.id).one().value
    else:
        rating_value = 0

    # Find the number of watched episodes for that series and current_user
    # Used to calculate %percent of show watched for progress bar
    watched_count = DB.query(model.WatchedEpisode).\
        join(model.WatchedEpisode.episode).\
        filter(model.Episode.series_id == series.id).\
        filter(model.WatchedEpisode.user_id == current_user.id).count()

    # Used to determine initial watch button status
    watched_eps = DB.query(model.WatchedEpisode).\
        join(model.WatchedEpisode.episode).\
        filter(model.Episode.series_id == series.id).\
        filter(model.WatchedEpisode.user_id == current_user.id).all()

    watched_ep_ids=[]

    for ep in watched_eps:
        watched_ep_ids.append(ep.episode_id)

    percent_watched = round(100 * float(watched_count)/float(len(eps_list)), 1)

    return render_template("series_page.html", state=state, 
                                                series = series, 
                                                current_user=current_user,
                                                season_dict=season_dict,
                                                watched_ep_ids=watched_ep_ids,
                                                rating=rating_value,
                                                favorite=favorite,
                                                percent_watched=percent_watched)