-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into crypto906
- Loading branch information
Showing
300 changed files
with
28,871 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## Anime Facts Rest API | ||
|
||
The Anime Facts Rest API is an API written in Node.js to get anime facts. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
""" | ||
Base module for the anime facts rest api. The API documentation can be found at | ||
https://chandan-02.github.io/anime-facts-rest-api/ | ||
Mantainer of the API: Chandan Kumar (https://github.com/chandan-02) | ||
""" | ||
import typing, requests, random | ||
|
||
from anime_api import exceptions | ||
from anime_api.apis.anime_facts_rest_api.objects import Anime, Fact | ||
|
||
|
||
class AnimeFactsRestAPI: | ||
""" | ||
Docs: https://chandan-02.github.io/anime-facts-rest-api/ | ||
""" | ||
|
||
endpoint = "https://anime-facts-rest-api.herokuapp.com/api/v1" | ||
|
||
def get_animes(self) -> typing.List[Anime]: | ||
""" | ||
Returns a list of all animes. | ||
""" | ||
response = requests.get(self.endpoint) | ||
|
||
if response.status_code != 200: | ||
raise exceptions.ServerError( | ||
status_code=response.status_code, | ||
) | ||
|
||
return [ | ||
Anime( | ||
id=anime["anime_id"], | ||
name=anime["anime_name"], | ||
image=anime["anime_img"], | ||
) | ||
for anime in response.json()["data"] | ||
] | ||
|
||
def get_anime_facts(self, anime_name: str) -> typing.List[Fact]: | ||
""" | ||
Returns a list of facts about the given anime (by it's name). | ||
""" | ||
response = requests.get(f"{self.endpoint}/{anime_name}") | ||
|
||
if response.status_code != 200: | ||
raise exceptions.ServerError( | ||
status_code=response.status_code | ||
) | ||
|
||
return [ | ||
Fact(id=fact["fact_id"], fact=fact["fact"]) for fact in response.json()["data"] | ||
] | ||
|
||
def get_anime_random_fact(self, anime_name: str) -> Fact: | ||
""" | ||
Return a random fact about the given anime (by it's name). | ||
""" | ||
return random.choice(self.get_anime_facts(anime_name)) | ||
|
||
def get_fact(self, anime_name: str, fact_id: int) -> Fact: | ||
""" | ||
Returns a specific Fact by it's ID and it's anime's name. | ||
""" | ||
response = requests.get(f"{self.endpoint}/{anime_name}/{fact_id}") | ||
|
||
if response.status_code != 200: | ||
raise exceptions.ServerError( | ||
status_code=response.status_code, | ||
) | ||
|
||
return Fact(id=response.json()["data"]["fact_id"], fact=response.json()["data"]["fact"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from dataclasses import dataclass | ||
|
||
import typing | ||
|
||
|
||
@dataclass | ||
class Anime: | ||
""" | ||
Object representation of an anime | ||
""" | ||
|
||
id: int | ||
name: str | ||
image: str | ||
|
||
@property | ||
def facts(self): | ||
""" | ||
Returns a list of facts about the anime. | ||
""" | ||
from anime_api.apis import AnimeFactsRestAPI | ||
|
||
api = AnimeFactsRestAPI() | ||
|
||
return api.get_anime_facts(self.name) | ||
|
||
def __str__(self): | ||
return self.name.replace('_', ' ').title() | ||
|
||
|
||
@dataclass | ||
class Fact: | ||
""" | ||
Object representation of an anime fact | ||
""" | ||
|
||
id: int | ||
fact: str | ||
|
||
def __str__(self): | ||
return self.fact |
52 changes: 52 additions & 0 deletions
52
Existing_API_Collection/Anime Api/Tests/test_anime_facts_rest_api.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
Run tests for the AnimeFactsRestAPI class. | ||
Usage: | ||
cd tests | ||
poetry run python -m pytest anime_facts_rest_api.py | ||
""" | ||
|
||
import typing | ||
|
||
from anime_api.apis.anime_facts_rest_api import AnimeFactsRestAPI | ||
from anime_api.apis.anime_facts_rest_api.objects import Anime, Fact | ||
|
||
|
||
def test_get_animes(): | ||
""" | ||
Test the get_animes method. Should return a list of animes. | ||
""" | ||
animes: typing.List[Anime] = AnimeFactsRestAPI().get_animes() | ||
|
||
assert isinstance( | ||
animes, list | ||
), "The return type of get_animes() is not a list." | ||
assert len(animes) > 0, "The list of animes is empty." | ||
assert isinstance( | ||
animes[0], Anime | ||
), "The list of animes does not contain objects.Anime objects." | ||
|
||
|
||
def test_get_anime_facts(): | ||
""" | ||
Test the get_anime_facts method. Should return a list of facts. | ||
""" | ||
facts: typing.List[Fact] = AnimeFactsRestAPI().get_anime_facts(anime_name="naruto") | ||
|
||
assert isinstance( | ||
facts, list | ||
), "The return type of get_anime_facts() is not a list." | ||
assert len(facts) > 0, "The list of facts is empty." | ||
assert isinstance( | ||
facts[0], Fact | ||
), "The list of facts does not contain objects.Fact objects." | ||
|
||
def test_get_fact(): | ||
""" | ||
Test the get_fact method. Should return a single fact. | ||
""" | ||
fact: Fact = AnimeFactsRestAPI().get_fact(anime_name="naruto", fact_id=1) | ||
|
||
assert isinstance( | ||
fact, Fact | ||
), "The return type of get_fact() is not a objects.Fact object." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
Sure, here's a README.md template for your COVID-19 Tracker API project: | ||
|
||
````markdown | ||
# COVID-19 Tracker API | ||
|
||
A RESTful API for fetching COVID-19 statistics by country and globally. | ||
|
||
## Getting Started | ||
|
||
To get started with this API, follow the instructions below. | ||
|
||
### Prerequisites | ||
|
||
- Node.js and npm installed on your machine | ||
- API key (optional, depending on the data source used) | ||
|
||
### Installation | ||
|
||
1. Clone the repository: | ||
|
||
```bash | ||
git clone https://github.com/your-username/covid19-tracker-api.git | ||
``` | ||
```` | ||
|
||
2. Navigate to the project directory: | ||
|
||
```bash | ||
cd covid19-tracker-api | ||
``` | ||
|
||
3. Install dependencies: | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
4. Set up environment variables (optional): | ||
|
||
Create a `.env` file in the root directory and add your API key (if required) as follows: | ||
|
||
```env | ||
API_KEY=your-api-key | ||
``` | ||
|
||
### Usage | ||
|
||
1. Start the server: | ||
|
||
```bash | ||
npm start | ||
``` | ||
|
||
2. The API endpoints are available at: | ||
|
||
- `/countries`: Get a list of available countries and their codes. | ||
- `/countries/:countryCode`: Get COVID-19 statistics for a specific country. | ||
- `/global`: Get global COVID-19 statistics. | ||
|
||
### Example Requests | ||
|
||
- Get a list of available countries: | ||
|
||
```http | ||
GET http://localhost:3000/countries | ||
``` | ||
|
||
- Get COVID-19 statistics for a specific country (replace `:countryCode` with the country code, e.g., "US" for the United States): | ||
|
||
```http | ||
GET http://localhost:3000/countries/:countryCode | ||
``` | ||
|
||
- Get global COVID-19 statistics: | ||
```http | ||
GET http://localhost:3000/global | ||
``` | ||
|
||
### Response Format | ||
|
||
The API responses are in JSON format and include fields such as total cases, active cases, deaths, and recoveries. | ||
|
||
Example response for `/countries/:countryCode`: | ||
|
||
```json | ||
{ | ||
"country": "United States", | ||
"cases": 1000000, | ||
"deaths": 50000, | ||
"recovered": 800000 | ||
} | ||
``` | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. | ||
|
||
``` | ||
|
||
Feel free to customize this README template to include additional information or specific instructions relevant to your project setup and usage. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>COVID-19 Tracker</title> | ||
<link rel="stylesheet" href="style.css"> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<h1>COVID-19 Tracker</h1> | ||
<div class="input-container"> | ||
<label for="country">Select Country:</label> | ||
<select id="country"></select> | ||
</div> | ||
<div class="statistics-container"> | ||
<div class="country-statistics"> | ||
<h2><span id="selected-country"></span></h2> | ||
<div class="statistic"> | ||
<span class="label">Total Cases:</span> | ||
<span id="total-cases"></span> | ||
</div> | ||
<div class="statistic"> | ||
<span class="label">Active Cases:</span> | ||
<span id="active-cases"></span> | ||
</div> | ||
<div class="statistic"> | ||
<span class="label">Deaths:</span> | ||
<span id="deaths"></span> | ||
</div> | ||
<div class="statistic"> | ||
<span class="label">Recoveries:</span> | ||
<span id="recoveries"></span> | ||
</div> | ||
</div> | ||
<div class="global-statistics"> | ||
<h2>Global Statistics</h2> | ||
<div class="statistic"> | ||
<span class="label">Total Cases:</span> | ||
<span id="global-total-cases"></span> | ||
</div> | ||
<div class="statistic"> | ||
<span class="label">Active Cases:</span> | ||
<span id="global-active-cases"></span> | ||
</div> | ||
<div class="statistic"> | ||
<span class="label">Deaths:</span> | ||
<span id="global-deaths"></span> | ||
</div> | ||
<div class="statistic"> | ||
<span class="label">Recoveries:</span> | ||
<span id="global-recoveries"></span> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<script src="script.js"></script> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.