https://github.com/pedrohcleal/timeapi
API for querying the temperature of any city in real time. Use the 'Time and Date' website to obtain information about the weather.
https://github.com/pedrohcleal/timeapi
api beatifulsoup beatifulsoup4 fastapi meterologia meterology python requests selenium weather-api webscraping
Last synced: 10 months ago
JSON representation
API for querying the temperature of any city in real time. Use the 'Time and Date' website to obtain information about the weather.
- Host: GitHub
- URL: https://github.com/pedrohcleal/timeapi
- Owner: pedrohcleal
- Created: 2024-08-12T01:05:47.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-15T16:15:35.000Z (about 1 year ago)
- Last Synced: 2025-01-14T00:28:15.237Z (12 months ago)
- Topics: api, beatifulsoup, beatifulsoup4, fastapi, meterologia, meterology, python, requests, selenium, weather-api, webscraping
- Language: Python
- Homepage: https://www.timeanddate.com/
- Size: 451 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README





# Temperature API
This is an API that retrieves the current temperature of cities around the world. The API uses the [Time and Date](https://www.timeanddate.com) website to get weather information.
## Technologies Used
- **FastAPI**: Web framework for creating the API.
- **BeautifulSoup**: For parsing and extracting data from HTML pages.
- **requests**: For making HTTP requests.
## Features
- **/all/countries**: Returns a list of all available countries for queries.
- **/all/cities**: Returns a list of all available cities for queries.
- **/{country}/{city}**: Returns the current temperature of the specified city in the specified country.
## Installation
Clone this repository and install the dependencies:
```bash
git clone https://github.com/pedrohcleal/timeAPI.git
cd timeAPI
pip install -r requirements.txt
```
## Usage
1. **Update Cities**:
To update the list of available cities, run the `handler.py` script. This will use Selenium to collect data from Time and Date.
```bash
python handler.py
```
2. **Run the FastAPI Server**:
To start the API server, run the following command:
```bash
cd app
fastapi dev main.py
```
The server will be available at [http://127.0.0.1:8000](http://127.0.0.1:8000).
## Project Structure
- **handler.py**: Contains functions for collecting and processing city and temperature data.
- **main.py**: Defines the API endpoints using FastAPI.
- **crud.py**: Helper functions for text sanitization and data saving.
## Dependencies
Make sure to keep the `requirements.txt` file updated with all the necessary libraries. The `requirements.txt` file can be generated with:
```bash
pip freeze > requirements.txt
```
## Contribution
If you would like to contribute to the project, feel free to submit pull requests. For issues or questions, open an issue on GitHub.