MCPcopy
hub / github.com/geekcomputers/Python / get_headlines

Function get_headlines

alexa_news_headlines.py:13–27  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11
12
13def get_headlines():
14 user_pass_dict = {"user": "USERNAME", "passwd": "PASSWORD", "api_type": "json"}
15 sess = requests.Session()
16 sess.headers.update({"User-Agent": "I am testing Alexa: nobi"})
17 sess.post("https://www.reddit.com/api/login/", data=user_pass_dict)
18 time.sleep(1)
19 url = "https://reddit.com/r/worldnews/.json?limit=10"
20 html = sess.get(url)
21 data = json.loads(html.content.decode("utf-8"))
22 titles = [
23 unidecode.unidecode(listing["data"]["title"])
24 for listing in data["data"]["children"]
25 ]
26 titles = "... ".join([i for i in titles])
27 return titles
28
29
30@app.route("/")

Callers 1

share_headlinesFunction · 0.85

Calls 2

updateMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected