Skip to content

Commit 6daffde

Browse files
committed
2 parents ebbd19f + cf6006b commit 6daffde

28 files changed

+250
-249
lines changed

.all-contributorsrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@
153153
"contributions": [
154154
"code"
155155
]
156+
},
157+
{
158+
"login": "ibhuiyan17",
159+
"name": "Ibtida Bhuiyan",
160+
"avatar_url": "https://avatars1.githubusercontent.com/u/33792969?v=4",
161+
"profile": "http://ibtida.me",
162+
"contributions": [
163+
"code"
164+
]
156165
}
157166
],
158167
"contributorsPerLine": 7,

README.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,16 @@ You will need the following things properly installed on your computer.
398398

399399
* `git clone https://github.com/ExpDev07/coronavirus-tracker-api.git`
400400
* `cd coronavirus-tracker-api`
401-
* `pipenv shell`
402-
* `pipenv install`
401+
402+
1. Make sure you have [`python3.8` installed and on your `PATH`](https://docs.python-guide.org/starting/installation/).
403+
2. [Install the `pipenv` dependency manager](https://pipenv.readthedocs.io/en/latest/install/#installing-pipenv)
404+
* with [pipx](https://pipxproject.github.io/pipx/) `$ pipx install pipenv`
405+
* with [Homebrew/Linuxbrew](https://pipenv.readthedocs.io/en/latest/install/#homebrew-installation-of-pipenv) `$ brew install pipenv`
406+
* with [pip/pip3 directly](https://pipenv.readthedocs.io/en/latest/install/#pragmatic-installation-of-pipenv) `$ pip install --user pipenv`
407+
3. Create virtual environment and install all dependencies `$ pipenv sync --dev`
408+
4. Activate/enter the virtual environment `$ pipenv shell`
409+
410+
And don't despair if don't get the python setup working on the first try. No one did. Guido got pretty close... once. But that's another story. Good luck.
403411

404412
## Running / Development
405413

@@ -408,11 +416,31 @@ You will need the following things properly installed on your computer.
408416

409417
### Running Tests
410418

411-
* `make test`
419+
```bash
420+
pipenv sync --dev
421+
pipenv shell
422+
make test
423+
```
412424

413425
### Linting
414426

415-
* `make lint`
427+
```bash
428+
pipenv sync --dev
429+
pipenv shell
430+
make lint
431+
```
432+
433+
### Formatting
434+
435+
```bash
436+
pipenv run fmt
437+
```
438+
or
439+
```bash
440+
pipenv shell
441+
make fmt
442+
```
443+
416444

417445
### Building
418446

@@ -446,6 +474,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
446474
</tr>
447475
<tr>
448476
<td align="center"><a href="https://github.com/Turreted"><img src="https://avatars2.githubusercontent.com/u/41593269?v=4" width="100px;" alt=""/><br /><sub><b>Turreted</b></sub></a><br /><a href="https://github.com/ExpDev07/coronavirus-tracker-api/commits?author=Turreted" title="Code">💻</a></td>
477+
<td align="center"><a href="http://ibtida.me"><img src="https://avatars1.githubusercontent.com/u/33792969?v=4" width="100px;" alt=""/><br /><sub><b>Ibtida Bhuiyan</b></sub></a><br /><a href="https://github.com/ExpDev07/coronavirus-tracker-api/commits?author=ibhuiyan17" title="Code">💻</a></td>
449478
</tr>
450479
</table>
451480

app/location/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from ..coordinates import Coordinates
2-
from ..utils import countrycodes
2+
from ..utils import countries
33
from ..utils.populations import country_population
44

55

@@ -31,7 +31,7 @@ def country_code(self):
3131
:returns: The country code.
3232
:rtype: str
3333
"""
34-
return (countrycodes.country_code(self.country) or countrycodes.default_code).upper()
34+
return (countries.country_code(self.country) or countries.default_country_code).upper()
3535

3636
@property
3737
def country_population(self):

app/main.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
import uvicorn
1111
from fastapi import FastAPI, Request, Response
1212
from fastapi.middleware.cors import CORSMiddleware
13-
from fastapi.middleware.wsgi import WSGIMiddleware
1413
from fastapi.responses import JSONResponse
1514

1615
from .core import create_app
1716
from .data import data_source
1817
from .models.latest import LatestResponse as Latest
1918
from .models.location import LocationResponse as Location
2019
from .models.location import LocationsResponse as Locations
21-
from .router import router
20+
from .router.v1 import router as v1router
21+
from .router.v2 import router as v2router
2222

2323
# ############
2424
# FastAPI App
@@ -83,11 +83,9 @@ async def handle_validation_error(request: Request, exc: pydantic.error_wrappers
8383

8484

8585
# Include routers.
86-
APP.include_router(router, prefix="/v2", tags=["v2"])
86+
APP.include_router(v1router, prefix="", tags=["v1"])
87+
APP.include_router(v2router, prefix="/v2", tags=["v2"])
8788

88-
# mount the existing Flask app
89-
# v1 @ /
90-
APP.mount("/", WSGIMiddleware(create_app()))
9189

9290
# Running of app.
9391
if __name__ == "__main__":

app/router/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from fastapi import APIRouter
22

3-
# Create the router.
4-
router = APIRouter()
3+
from .v1 import all, confirmed, deaths, recovered
54

65
# The routes.
7-
from . import latest, sources, locations # isort:skip
6+
from .v2 import latest, sources, locations # isort:skip

app/router/v1/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from fastapi import APIRouter
2+
3+
router = APIRouter()

app/router/v1/all.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from ...services.location.jhu import get_category
2+
from . import router
3+
4+
5+
@router.get("/all")
6+
def all():
7+
# Get all the categories.
8+
confirmed = get_category("confirmed")
9+
deaths = get_category("deaths")
10+
recovered = get_category("recovered")
11+
12+
return {
13+
# Data.
14+
"confirmed": confirmed,
15+
"deaths": deaths,
16+
"recovered": recovered,
17+
# Latest.
18+
"latest": {"confirmed": confirmed["latest"], "deaths": deaths["latest"], "recovered": recovered["latest"],},
19+
}

app/router/v1/confirmed.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ...services.location.jhu import get_category
2+
from . import router
3+
4+
5+
@router.get("/confirmed")
6+
def confirmed():
7+
confirmed = get_category("confirmed")
8+
9+
return confirmed

app/router/v1/deaths.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ...services.location.jhu import get_category
2+
from . import router
3+
4+
5+
@router.get("/deaths")
6+
def deaths():
7+
deaths = get_category("deaths")
8+
9+
return deaths

app/router/v1/recovered.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from ...services.location.jhu import get_category
2+
from . import router
3+
4+
5+
@router.get("/recovered")
6+
def recovered():
7+
recovered = get_category("recovered")
8+
9+
return recovered

0 commit comments

Comments
 (0)