예제 #1
0
def gpodder_request():

    from mygpoclient import public
    client = public.PublicClient()
    if client.get_toplist():
        toplist_results = client.get_toplist()

    return toplist_results
예제 #2
0
def results():
    if request.form.get('tag'):
        search_term = request.form.get('tag')
    else:
        search_term = request.form.getlist('search_term')[0]
    client = public.PublicClient()
    search_results = client.search_podcasts(search_term)
    search_results = shortenDescriptions(search_results)
    return render_template('results.html', search_results = search_results, search_term = search_term)
예제 #3
0
def newsfeed(request):
    response = []
    devices = client.get_devices()
    device = None
    for d in devices:
        if d.device_id == request.user.profile.device_id: device = d

    subscriptions = []

    public_client = public.PublicClient()
    toplist = public_client.get_toplist()
    for index, entry in enumerate(toplist):
        response.append((entry.logo_url, entry.url,
                         ['%s' % (entry.title), entry.description]))
        subscriptions.append(entry.url)

    response2 = []
    errors = []

    try:
        sublist = client.get_subscriptions(device)
    except http.NotFound:  #device does not exist
        errors.append(
            'Device does not exist or you are not a registered user with gPodder.net.'
        )
        response2 = []
        sublist = []

    if device == None:
        print 'error'
        if len(errors) == 0:
            errors.append(
                'Device does not exist or you are not a registered user with gPodder.net.'
            )
        response2 = []
        sublist = []

    for i in range(len(sublist)):
        entry = public_client.get_podcast_data(sublist[i])
        sublist[i] = entry

    #sublist.sort(cmp_num_episodes)
    for index, entry in enumerate(sublist):
        response2.append((entry.logo_url, entry.url,
                          ['%s' % (entry.title), entry.description]))

    return render(
        request,
        'newsfeed.html',
        context={
            'sublist': response2,
            'errors': errors
        },
    )
예제 #4
0
def subscriptions():
    username = session['username']
    password = session['password']
    device_id = session['device_id']
    client = simple.SimpleClient(username, password)
    links = client.get_subscriptions(device_id)
    pub_client = public.PublicClient()
    subscriptions = []
    for link in links:
        subscriptions.append(pub_client.get_podcast_data(link))
    subscriptions = shortenDescriptions(subscriptions) #some descriptions are way too long
    return render_template('subscriptions.html', subscriptions = subscriptions)
예제 #5
0
def get_top_rated():
    """ Returns a list of the 50 top podcasts and number of subscribers. """

    client = public.PublicClient()
    top_podcasts = {}

    if client.get_toplist():
        toplist_results = client.get_toplist()
        for index, entry in enumerate(toplist_results):
            top_podcasts[(index + 1)] = [entry.title, entry.logo_url]

    return render_template("top_podcasts.html", top_podcasts=top_podcasts)
예제 #6
0
def search(request):
    if request.method == 'POST':
        print request.POST
        search_term = request.POST['search_term']
        client = public.PublicClient()
        pods = []
        for entry in client.search_podcasts(search_term):
            pods.append((entry.logo_url, entry.url,
                         ['%s' % (entry.title), entry.description]))
        pods = list(set(pods))
        return render(request, 'search.html', {
            'heading': 'Your results:',
            'pods': pods
        })
    return render(request, 'search.html')
예제 #7
0
def genres(request):
    public_client = public.PublicClient()
    toptags = public_client.get_toptags(10)
    tags = [tag.tag for tag in toptags]
    pods = []
    for tag in tags:
        tag_resp = []
        tag_pods = public_client.get_podcasts_of_a_tag(tag)
        tag_pods = list(set(tag_pods))
        for index, entry in enumerate(tag_pods):
            tag_resp.append((entry.logo_url, entry.url,
                             ['%s' % (entry.title), entry.description]))
        pods.append(tag_resp)
    tags = [tag.capitalize() for tag in tags]
    return render(
        request, 'genres.html', {
            'tag0': tags[0],
            'tag1': tags[1],
            'tag2': tags[2],
            'tag3': tags[3],
            'tag4': tags[4],
            'tag5': tags[5],
            'tag6': tags[6],
            'tag7': tags[7],
            'tag8': tags[8],
            'tag9': tags[9],
            'pods0': pods[0],
            'pods1': pods[1],
            'pods2': pods[2],
            'pods3': pods[3],
            'pods4': pods[4],
            'pods5': pods[5],
            'pods6': pods[6],
            'pods7': pods[7],
            'pods8': pods[8],
            'pods9': pods[9],
        })
예제 #8
0
 def __init__(self):
     self.client = public.PublicClient()
예제 #9
0
def podcasts_by_genre(query):
    client = public.PublicClient()
    genre_list = client.get_podcasts_of_a_tag(query)
    return genre_list
예제 #10
0
def toptags():
    client = public.PublicClient()
    tags = client.get_toptags()
    return tags
예제 #11
0
def search(query):
    client = public.PublicClient()
    search_list = client.search_podcasts(query)
    return search_list
예제 #12
0
# Abhishek Shinde
# The dependencies used for this project and for the functions listed below
from mygpoclient import public, testing, locator
import requests
import json
import pprint

client = public.PublicClient()

# ** Functions **


# searches for podcasts based on user input into search bar, and returns a list object
def search(query):
    client = public.PublicClient()
    search_list = client.search_podcasts(query)
    return search_list


# provided a client object, function returns a list of top podcasts (live data)
def top(client):
    return client.get_toplist()


# returns a list of top tags from the website (live data)
def toptags():
    client = public.PublicClient()
    tags = client.get_toptags()
    return tags

예제 #13
0
 def setUp(self):
     self.fake_client = testing.FakeJsonClient()
     self.client = public.PublicClient(client_class=self.fake_client)
예제 #14
0
def browse():
    client = public.PublicClient()
    toplist = client.get_toplist(9)
    toplist = shortenDescriptions(toplist)
    top_tags = client.get_toptags()
    return render_template('browse.html', toplist = toplist, top_tags = top_tags)
예제 #15
0
def search_podcasts():
    """ Search podcasts by name/keyword. """

    search_input = request.args.get('q')
    search_list = search_input.split()
    search_terms = "+".join(search_list)

    # -------------------ITUNES REQUEST--------------------------

    response = get_podcasts(search_terms)

    results = response['results']

    # Parse xml file returned to retrieve individual track info
    for result in results:
        if (result.get('feedUrl')):
            xml_url = result['feedUrl']
            doc = requests.get(xml_url)

            if doc.text:
                root = xml.etree.ElementTree.fromstring(doc.text)[0]

                enclosures = []
                titles = []
                elems = []

                for item in root.findall('item'):
                    enclosures.extend(item.findall('enclosure'))
                    titles.extend(item.findall('title'))

                count = 0
                if (len(titles) == len(enclosures)):
                    for i in range(len(titles)):
                        count += 1
                        elems.append((enclosures[i].attrib['url'],
                                      titles[i].text, count))

                src_lst = []

                for enclosure in enclosures:
                    audio_src = enclosure.attrib['url']

                result['elements'] = elems
            else:
                results = []

    collections = []

    for result in results:
        if result['collectionName'] not in collections:
            collections.append(result['collectionName'])

    # --------------------GPODDER REQUEST------------------------

    client = public.PublicClient()
    gpo_objects = client.search_podcasts(search_input)

    gpo_response = []
    titles = []

    for obj in gpo_objects:
        if obj.title not in collections and obj.title not in titles:
            gpo_response.append(obj)
            titles.append(obj.title)

    if show_playlists():
        playlists = show_playlists()
    else:
        playlists = []

    return render_template("search_results.html",
                           results=results,
                           playlists=playlists)