File size: 3,696 Bytes
c726302
 
 
 
 
 
 
 
 
 
 
 
176b92e
c726302
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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,
            }