-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
71 lines (61 loc) · 1.69 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import requests
from flask import Flask , render_template
from flask_mail import Mail, Message
app = Flask(__name__)
# hackernews api
# r = requests.get('https://hacker-news.firebaseio.com/v0/newstories.json?print=pretty')
# data = r.json()
# url = []
# title = []
# for x in range(0,100):
# news = data[x]
# z = f'https://hacker-news.firebaseio.com/v0/item/{news}.json?print=pretty'
# d = requests.get(z)
# v = d.json()
# if v['type'] == 'story':
# try:
# url.append(v['url'])
# title.append(v['title'])
# except KeyError:
# pass
# json_data = dict(zip(title,url))
# print(json_data)
mail_settings = {
"MAIL_SERVER": 'YOUR STMP SERVER',
"MAIL_PORT": 465,
"MAIL_USE_TLS": False,
"MAIL_USE_SSL": True,
"MAIL_USERNAME": '',
"MAIL_PASSWORD": ''
}
app.config.update(mail_settings)
mail = Mail(app)
@app.route("/")
def home():
# hackernews api
r = requests.get('https://hacker-news.firebaseio.com/v0/newstories.json?print=pretty')
data = r.json()
url = []
title = []
for x in range(0,100):
news = data[x]
z = f'https://hacker-news.firebaseio.com/v0/item/{news}.json?print=pretty'
d = requests.get(z)
v = d.json()
if v['type'] == 'story':
try:
url.append(v['url'])
title.append(v['title'])
except KeyError:
pass
json_data = dict(zip(title,url))
# print(json_data)
return render_template('index.html',data=json_data.items())
# Email logic
# msg = Message(subject="Hacker News",
# sender=app.config.get("MAIL_USERNAME"),
# recipients=[""], # replace with your email for testing
# html=render_template('index.html',data=json_data.items()))
# mail.send(msg)
if __name__ == '__main__':
app.run()