0

I implemented articles in application.py Pset8. Everything seems ok except i only get articles from theonion and not from actual google news.Here's the code :

def articles():
"""Look up articles for geo."""

#retrieving geo value from HTML form
location = request.args.get("geo")
if not location:
    raise RuntimeError("geo value not sent")

#lookup
article = lookup(location)

#jsonify
return jsonify(article[0:5])

Here's the code for lookup function ,given in the distribution code.

def lookup(geo):
"""Looks up articles for geo."""

# check cache for geo
if geo in lookup.cache:
    return lookup.cache[geo]

# get feed from Google
feed = feedparser.parse("http://news.google.com/news?geo={}&output=rss".format(urllib.parse.quote(geo, safe="")))

# if no items in feed, get feed from Onion
if not feed["items"]:
    feed = feedparser.parse("http://www.theonion.com/feeds/rss")

# cache results
lookup.cache[geo] = [{"link": item["link"], "title": item["title"]} for item in feed["items"]]

# return results
return lookup.cache[geo]

# initialize cache
lookup.cache = {}

Even if i use different values for geo, it returns theonion RSS feed.Is there any problem in the code? Help me with this. Thanks :)

2
  • What "geo" have you tried in the request line? Jul 11 '17 at 11:46
  • I have tried "geo" values explicitly like geo=02138,06511 ., It worked now anyways :) didnt change anything but worked when tried after few hours. Jul 11 '17 at 13:41
0

I'm guessing the problem is as depicted in this post (first answer) as I had the same problem myself:

https://www.reddit.com/r/cs50/comments/4clxp0/pset_8_articles_are_showing_but_the_onion/

Basically the code is fine, but google detects spam so stops returning articles to the user (at least according to delipity).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .