()
| 11 | |
| 12 | |
| 13 | def 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("/") |
no test coverage detected