Skip to content

Commit d625ea0

Browse files
authored
Add files via upload
1 parent cf2bf82 commit d625ea0

File tree

11 files changed

+118
-0
lines changed

11 files changed

+118
-0
lines changed
603 Bytes
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from flask import Flask
2+
3+
app = Flask(__name__)
4+
5+
@app.route("/", methods=["GET"])
6+
def hello():
7+
return "hello CS 41"
8+
9+
if __name__ == "__main__":
10+
app.run()
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from flask import Flask
2+
3+
app = Flask(__name__)
4+
5+
SECRET_NUMBER = 41
6+
7+
@app.route("/", methods=["GET"])
8+
def hello():
9+
return "hello CS 41"
10+
11+
@app.route("/<guess>", methods=["GET"])
12+
def guess_check(guess):
13+
try:
14+
guess = int(guess)
15+
except ValueError:
16+
return {"error": "Hey! Thats not a number"}
17+
18+
output = {'correct' : guess == SECRET_NUMBER}
19+
if guess < SECRET_NUMBER:
20+
output["message"] = "too low!"
21+
elif guess > SECRET_NUMBER:
22+
output["message"] = "too high"
23+
else:
24+
output["message"] = "congrats!!"
25+
return output
26+
27+
if __name__ == "__main__":
28+
app.run()
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from flask import Flask, request, render_template
2+
3+
app = Flask(__name__)
4+
items = []
5+
6+
#{"to_add: apples"}
7+
@app.route("/", methods=["GET", "POST"])
8+
def hello():
9+
if request.method == "POST":
10+
data = request.get_json()
11+
items.append(data["to_add"])
12+
return render_template("list.html", items=items)
13+
else:
14+
return render_template("list.html", items=items)
15+
16+
17+
18+
if __name__ == "__main__":
19+
app.run()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import requests
2+
3+
url = "http://127.0.0.1:4000/"
4+
#{"to_add: apples"}
5+
6+
user_input = input("What do you want to add to the list: ")
7+
while user_input:
8+
requests.post(url, json={"to_add" : user_input})
9+
user_input = input("What do you want to add to the list: ")
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>ITEMS:</title>
5+
</head>
6+
<body>
7+
<h1>Items:</h1>
8+
<ul>
9+
{% for item in items %}
10+
<li>{{item}}</li>
11+
{% endfor %}
12+
</ul>
13+
14+
</body>
15+
16+
17+
</html>
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#query-pages-page_id->extract
2+
from flask import Flask, render_template
3+
import requests
4+
from wordcloud import WordCloud
5+
6+
app = Flask(__name__)
7+
wc = WordCloud(
8+
background_color="white",
9+
max_words=100,
10+
colormap='plasma',
11+
width=1000,
12+
height=800
13+
)
14+
15+
16+
17+
@app.route("/<wiki_slug>", methods=["GET"])
18+
def hello(wiki_slug):
19+
r = requests.get(f"https://en.wikipedia.org/w/api.php?action=query&format=json&titles={wiki_slug}&prop=extracts&explaintext")
20+
data = r.json()
21+
page_id, page_data = data["query"]["pages"].popitem()
22+
if page_id == -1:
23+
return "sorry, no wiki page for that"
24+
img_data = wc.generate(page_data["extract"]).to_svg()
25+
return render_template("display.html", img=img_data)
26+
27+
if __name__ == "__main__":
28+
app.run()

0 commit comments

Comments
 (0)