Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b69435a

Browse files
Merge branch 'master' of github.com:talkpython/100daysofweb-with-python-course
2 parents a18b641 + 341a64b commit b69435a

File tree

266 files changed

+19771
-43
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

266 files changed

+19771
-43
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
click==6.7
22
Flask==1.0.2
33
itsdangerous==0.24
4-
Jinja2==2.10
4+
Jinja2>=2.10.1
55
MarkupSafe==1.0
66
python-dotenv==0.9.1
7-
Werkzeug==0.14.1
7+
werkzeug>=0.15.3

‎days/005-008-html5/your-turn/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ While I made fun of Yahoo! for being nothing but a glamorized Yellow Pages, the
1414

1515
But their web design was decidedly not special. Check it out in the way back machine (choose 1998 for your time frame):
1616

17-
[https://web.archive.org/web/19981202230410/http://www.google.com/](https://web.archive.org/web/19981202230410/http://www.google.com/)
17+
[http://web.archive.org/web/19981202230410/http://www.google.com/](http://web.archive.org/web/19981202230410/http://www.google.com/)
1818

1919
Here's the design with a few visual notes on what is required for each part of the page (yes, tables make a comeback). No really, view the source, it's tables and the center tag even!
2020

‎days/009-012-modern-apis-starred/demo/app.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def list_cars() -> List[Car]:
3636

3737

3838
def create_car(car: Car) -> JSONResponse:
39-
car_id = len(cars) +1
39+
car_id = max(cars.keys())+1
4040
car.id = car_id
4141
cars[car_id] = car
4242
return JSONResponse(Car(car), status_code=201)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
apistar
1+
apistar>=0.5.41,<0.5.1000
22
pytest

‎days/009-012-modern-apis-starred/demo/test_app.py‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ def test_list_cars():
1010
assert response.status_code == 200
1111

1212
json_resp = response.json()
13-
assert len(json_resp) == 1000
13+
car_count = len(cars)
14+
assert len(json_resp) == car_count
1415

1516
expected = {'id': 1, 'manufacturer': 'Mercedes-Benz',
1617
'model': '500SEC', 'year': 1993,
@@ -19,13 +20,14 @@ def test_list_cars():
1920

2021

2122
def test_create_car():
23+
car_count = len(cars)
2224
data = {'manufacturer': 'Honda',
2325
'model': 'some_model',
2426
'year': 2018}
2527

2628
response = client.post('/', data=data)
2729
assert response.status_code == 201
28-
assert len(cars) == 1001
30+
assert len(cars) == car_count+1
2931

3032
response = client.get('/1001/')
3133
expected = {'id': 1001, 'manufacturer': 'Honda',
@@ -44,7 +46,21 @@ def test_create_car():
4446

4547
response = client.get('/1002/')
4648
assert response.json() == expected
47-
assert len(cars) == 1002
49+
assert len(cars) == car_count + 2
50+
51+
52+
def test_create_car_after_delete():
53+
"""Test to fail create_car's len(cars)+1 (fix max(cars.keys())+1)"""
54+
car_count = len(cars)
55+
response = client.delete(f'/99/')
56+
assert response.status_code == 204
57+
assert len(cars) == car_count - 1
58+
data = {'manufacturer': 'Honda',
59+
'model': 'blabla',
60+
'year': 2019}
61+
response = client.post('/', data=data)
62+
assert response.status_code == 201
63+
assert len(cars) == car_count
4864

4965

5066
def test_create_car_missing_fields():
@@ -129,7 +145,6 @@ def test_update_car_validation():
129145

130146
def test_delete_car():
131147
car_count = len(cars)
132-
133148
for i in (11, 22, 33):
134149
response = client.delete(f'/{i}/')
135150
assert response.status_code == 204

‎days/009-012-modern-apis-starred/readme.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Days 09-12 Building APIs with Api Star
1+
# Days 09-12 Building APIs with Api Star (0.5.x)
22

33
Now you have seen the videos from this chapter, you're ready to build an API using API Star!
44

@@ -12,7 +12,7 @@ For this day, you will get a data set from [Mockaroo](https://mockaroo.com/) or
1212

1313
Data is everywhere, but if you don't get inspiration maybe you can use this [Marvel dataset](https://raw.githubusercontent.com/pybites/marvel_challenge/master/marvel-wikia-data.csv) we used for one of our code challenges. If you don't know how to parse CSV, no worries: the same repo [has code for this](https://github.com/pybites/marvel_challenge/blob/solution/marvel.py).
1414

15-
Next make a virtual env, activate it and `pip install apistar` as shown in the videos (of course you can also use `pipenv` or `Anaconda`).
15+
Next make a virtual env, activate it and `pip install apistar==0.5.41` as shown in the videos (of course you can also use `pipenv` or `Anaconda`).
1616

1717
Then start to build your API using the skeleton from my demo. Try to implement the `GET` endpoint today (both all items and single item).
1818

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
from program import app
2+
3+
if __name__ == '__main__':
4+
app.run(load_dotenv=False)
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
from flask import render_template, request
2-
from program import app
31
from datetime import datetime
4-
frompprintimportpprint
2+
53
import requests
4+
from flask import render_template, request
5+
6+
from program import app
7+
8+
time_now = str(datetime.today())
69

7-
timenow = str(datetime.today())
810

911
@app.route('/')
1012
@app.route('/index')
1113
def index():
12-
return render_template('index.html', title='Template Demo', time=timenow)
14+
return render_template('index.html', title='Template Demo', time=time_now)
15+
1316

1417
@app.route('/100Days')
1518
def p100days():
1619
return render_template('100Days.html')
1720

21+
1822
@app.route('/chuck')
1923
def chuck():
2024
joke = get_chuck_joke()
2125
return render_template('chuck.html',
22-
joke=joke)
26+
joke=joke)
27+
2328

2429
@app.route('/pokemon', methods=['GET', 'POST'])
2530
def pokemon():
@@ -28,19 +33,21 @@ def pokemon():
2833
colour = request.form.get('pokecolour')
2934
pokemon = get_poke_colours(colour)
3035
return render_template('pokemon.html',
31-
pokemon=pokemon)
36+
pokemon=pokemon)
37+
3238

3339
def get_chuck_joke():
3440
r = requests.get('https://api.chucknorris.io/jokes/random')
3541
data = r.json()
3642
return data['value']
3743

44+
3845
def get_poke_colours(colour):
3946
r = requests.get('https://pokeapi.co/api/v2/pokemon-color/' + colour.lower())
4047
pokedata = r.json()
4148
pokemon = []
4249

4350
for i in pokedata['pokemon_species']:
4451
pokemon.append(i['name'])
45-
52+
4653
return pokemon

‎days/017-020-flask-call-apis/code/requirements.txt‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Click==7.0
44
Flask==1.0.2
55
idna==2.7
66
itsdangerous==0.24
7-
Jinja2==2.10
7+
Jinja2>=2.10.1
88
MarkupSafe==1.0
99
python-dotenv==0.9.1
10-
requests==2.19.1
11-
urllib3==1.23
12-
Werkzeug==0.14.1
10+
requests>=2.21.0
11+
urllib3==1.24.2
12+
werkzeug>=0.15.3
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
PY?=python3
2+
PELICAN?=pelican
3+
PELICANOPTS=
4+
5+
BASEDIR=$(CURDIR)
6+
INPUTDIR=$(BASEDIR)/content
7+
OUTPUTDIR=$(BASEDIR)/output
8+
CONFFILE=$(BASEDIR)/pelicanconf.py
9+
PUBLISHCONF=$(BASEDIR)/publishconf.py
10+
11+
12+
DEBUG ?= 0
13+
ifeq ($(DEBUG), 1)
14+
PELICANOPTS += -D
15+
endif
16+
17+
RELATIVE ?= 0
18+
ifeq ($(RELATIVE), 1)
19+
PELICANOPTS += --relative-urls
20+
endif
21+
22+
help:
23+
@echo 'Makefile for a pelican Web site '
24+
@echo ' '
25+
@echo 'Usage: '
26+
@echo ' make html (re)generate the web site '
27+
@echo ' make clean remove the generated files '
28+
@echo ' make regenerate regenerate files upon modification '
29+
@echo ' make publish generate using production settings '
30+
@echo ' make serve [PORT=8000] serve site at http://localhost:8000'
31+
@echo ' make serve-global [SERVER=0.0.0.0] serve (as root) to $(SERVER):80 '
32+
@echo ' make devserver [PORT=8000] serve and regenerate together '
33+
@echo ' make ssh_upload upload the web site via SSH '
34+
@echo ' make rsync_upload upload the web site via rsync+ssh '
35+
@echo ' '
36+
@echo 'Set the DEBUG variable to 1 to enable debugging, e.g. make DEBUG=1 html '
37+
@echo 'Set the RELATIVE variable to 1 to enable relative urls '
38+
@echo ' '
39+
40+
html:
41+
$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)
42+
43+
clean:
44+
[ ! -d $(OUTPUTDIR) ] || rm -rf $(OUTPUTDIR)
45+
46+
regenerate:
47+
$(PELICAN) -r $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)
48+
49+
serve:
50+
ifdef PORT
51+
$(PELICAN) -l $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS) -p $(PORT)
52+
else
53+
$(PELICAN) -l $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)
54+
endif
55+
56+
serve-global:
57+
ifdef SERVER
58+
$(PELICAN) -l $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS) -p $(PORT) -b $(SERVER)
59+
else
60+
$(PELICAN) -l $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS) -p $(PORT) -b 0.0.0.0
61+
endif
62+
63+
64+
devserver:
65+
ifdef PORT
66+
$(PELICAN) -lr $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS) -p $(PORT)
67+
else
68+
$(PELICAN) -lr $(INPUTDIR) -o $(OUTPUTDIR) -s $(CONFFILE) $(PELICANOPTS)
69+
endif
70+
71+
publish:
72+
$(PELICAN) $(INPUTDIR) -o $(OUTPUTDIR) -s $(PUBLISHCONF) $(PELICANOPTS)
73+
74+
75+
.PHONY: html help clean regenerate serve serve-global devserver stopserver publish

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /