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/" # Replace with actual weather page URL } _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.""" # Scrape weather data from the specified URL response = requests.get(filepath) soup = BeautifulSoup(response.content, 'html.parser') # Example parsing logic (this will depend on the actual HTML structure of the page) # You will need to inspect the weather.com page to find the correct classes/IDs for weather_entry in soup.find_all('div', class_='CurrentConditions--primary--2SVPh'): # Adjust class name location = soup.find('h1', class_='CurrentConditions--location--1Ayv3').text # Adjust class name temperature = float(weather_entry.find('span', class_='CurrentConditions--tempValue--3KcTQ').text.replace('°', '')) # Adjust class name humidity = float(weather_entry.find('span', class_='CurrentConditions--humidity--AlSGP').text.replace('Humidity', '').replace('%', '').strip()) # Adjust class name wind_speed = float(weather_entry.find('span', class_='CurrentConditions--windValue--3Kx8I').text.replace(' km/h', '').strip()) # Adjust class name condition = weather_entry.find('div', class_='CurrentConditions--phraseValue--2xXSr').text # Adjust class name timestamp = time.now().isoformat() # Use current timestamp or extract from the page if available yield location, { "location": location, "temperature": temperature, "humidity": humidity, "wind_speed": wind_speed, "condition": condition, "timestamp": timestamp, }