This is a quick and script to generate BBC weather reports on the command as weather cards. It uses web scraping for the daily forecasts and intercepts the API calls for the hourly ones. You can navigate and explore each forecast with the keyboard. Yes, the code is bad because I just wanted to quickly whip up something that works.
First, install all necessary packages:
pip install -r requirements.txt
Some minimal changes are required to calibrate it for you location. If you don't live in one of the
existing cities in file city_ids.dat
, search your city at BBC's page and append the name
and city ID from the URL, e.g. https://www.bbc.com/weather/3169070 -> ID 3169070
in the file, such as:
Rome: 3169070
You can optionally append the city's latitude and longitude (to make the lookup faster) in a third colon-separated field as:
Rome: 3169070: 41.8967, 12.4822
If you run scraper.py
without arguments, it will autodetect your location and generate the forecast of
the closest city in city_ids.dat
:
python scraper.py # <- auto detect city
If you run it with an argument, it will apply fuzzing matching to find the best match of your entered city in
city_ids.dat
:
python scraper London
python scraper.py nw yrk # <- New York
- 14-day forecast with terminal graphics and keyvoard controls
- Daily weather including caching
- Hourly weather including caching
- Seamlessly switch between daily and hourly
- Fuzzy matching of input city
- Closest city to your input
- Some predefined cities to find best match
-
Caching of city geolocations in-> Replaced by listing coordinatescity_ids.dat
- Imperial units
- Automatically find each city's ID from BBC's API if possible
Any pull requests to implement the missing features are welcome!
Q: Why does the temperature range between the daily forecast and hourly forecast differ?
A: Because BBC measures the daily range from 6am current day to 6am next day. The API request for the hourly weather measures exactly that day.
