| import json |
| import re |
| import datasets |
| import requests |
| import time |
| from bs4 import BeautifulSoup |
|
|
| _CITATION = """ |
| @misc{weather-dataset, |
| title = "Weather Dataset", |
| author = "ICE", |
| year = "2025", |
| url = "https://huggingface.co/datasets/FrostIce/weather" |
| } |
| """ |
|
|
| _DESCRIPTION = """ |
| Этот набор данных содержит информацию о погоде, полученную с различных погодных сайтов. |
| Он включает такие данные, как температура, влажность, скорость ветра и погодные условия |
| для разных мест. Набор данных регулярно обновляется, чтобы отражать последние погодные данные.""" |
|
|
| _HOMEPAGE = "https://huggingface.co/ProICE" |
| _LICENSE = "ICE License, Version 2.0" |
|
|
| _URLS = { |
| "weather": "https://weather.com/" |
| } |
|
|
| _VERSION = datasets.Version("1.0.0") |
|
|
| class WeatherDataset(datasets.GeneratorBasedBuilder): |
| """Weather dataset for scraping weather information.""" |
|
|
| def _info(self): |
| features = datasets.Features( |
| { |
| "location": datasets.Value("string"), |
| "temperature": datasets.Value("float32"), |
| "humidity": datasets.Value("float32"), |
| "wind_speed": datasets.Value("float32"), |
| "condition": datasets.Value("string"), |
| "timestamp": datasets.Value("string"), |
| } |
| ) |
|
|
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=features, |
| homepage=_HOMEPAGE, |
| license=_LICENSE, |
| citation=_CITATION, |
| ) |
|
|
| def _split_generators(self, dl_manager): |
| """Returns SplitGenerators.""" |
| downloaded_files = dl_manager.download_and_extract(_URLS) |
| return [ |
| datasets.SplitGenerator(name="weather", gen_kwargs={"filepath": downloaded_files["weather"]}), |
| ] |
|
|
| def _generate_examples(self, filepath): |
| """Yields examples.""" |
| |
| response = requests.get(filepath) |
| soup = BeautifulSoup(response.content, 'html.parser') |
|
|
| |
| |
| for weather_entry in soup.find_all('div', class_='CurrentConditions--primary--2SVPh'): |
| location = soup.find('h1', class_='CurrentConditions--location--1Ayv3').text |
| temperature = float(weather_entry.find('span', class_='CurrentConditions--tempValue--3KcTQ').text.replace('°', '')) |
| humidity = float(weather_entry.find('span', class_='CurrentConditions--humidity--AlSGP').text.replace('Humidity', '').replace('%', '').strip()) |
| wind_speed = float(weather_entry.find('span', class_='CurrentConditions--windValue--3Kx8I').text.replace(' km/h', '').strip()) |
| condition = weather_entry.find('div', class_='CurrentConditions--phraseValue--2xXSr').text |
| timestamp = time.now().isoformat() |
|
|
| yield location, { |
| "location": location, |
| "temperature": temperature, |
| "humidity": humidity, |
| "wind_speed": wind_speed, |
| "condition": condition, |
| "timestamp": timestamp, |
| } |