Beispiel #1
0
def index():
    query = request.args.get('id')
    queried_doc = None
    if query is not None:
        queried_doc, docs = as_euclidean(query)
    else:
        docs = get_random_grouping()

    no_image_url = (
        "http://slot1.images.wikia.nocookie.net/__cb62407/" +
        "common/extensions/wikia/Search/images/wiki_image_placeholder.png")
    details = requests.get("http://www.wikia.com/api/v1/Wikis/Details/",
                           params={
                               'ids': ",".join([doc['id'] for doc in docs])
                           }).json().get('items', {})
    for doc in docs:
        if not details.get(doc['id'], {}).get('image', ''):
            details[doc['id']] = dict(
                details.get(doc['id'], {}).items() + [('image', no_image_url)])

    return render_template('index.html',
                           docs=docs,
                           queried_doc=queried_doc,
                           qs=re.sub(r'id=\d+(&)?', '',
                                     request.query_string).replace('&&', '&'),
                           details=details)
def get_recommendations(wiki):
    wiki_id = wiki['id']
    print wiki_id
    try:
        wiki_doc, recommendations = as_euclidean(wiki_id)
        wiki_doc['recommendation_ids'] = [x.get('id', '?') for x in recommendations]
        wiki_doc['recommendation_urls'] = [x.get('url', '?') for x in recommendations]
        wiki_doc['recommendation_sitenames'] = [' '.join(x.get('sitename_txt', ['?'])) for x in recommendations]
        if 'url' not in wiki_doc:
            return None
        return wiki_doc
    except ValueError as e:
        print e
        return None
Beispiel #3
0
def index():
    query = request.args.get('id')
    queried_doc = None
    if query is not None:
        queried_doc, docs = as_euclidean(query)
    else:
        docs = get_random_grouping()

    no_image_url = ("http://slot1.images.wikia.nocookie.net/__cb62407/"
                    + "common/extensions/wikia/Search/images/wiki_image_placeholder.png")
    details = requests.get("http://www.wikia.com/api/v1/Wikis/Details/",
                           params={'ids': ",".join([doc['id'] for doc in docs])}).json().get('items', {})
    for doc in docs:
        if not details.get(doc['id'], {}).get('image', ''):
            details[doc['id']] = dict(details.get(doc['id'], {}).items() + [('image', no_image_url)])

    return render_template('index.html', docs=docs, queried_doc=queried_doc,
                           qs=re.sub(r'id=\d+(&)?', '', request.query_string).replace('&&', '&'), details=details)
def get_recommendations(wiki):
    wiki_id = wiki['id']
    print wiki_id
    try:
        wiki_doc, recommendations = as_euclidean(wiki_id)
        wiki_doc['recommendation_ids'] = [
            x.get('id', '?') for x in recommendations
        ]
        wiki_doc['recommendation_urls'] = [
            x.get('url', '?') for x in recommendations
        ]
        wiki_doc['recommendation_sitenames'] = [
            ' '.join(x.get('sitename_txt', ['?'])) for x in recommendations
        ]
        if 'url' not in wiki_doc:
            return None
        return wiki_doc
    except ValueError as e:
        print e
        return None