FrostIce commited on
Commit
c726302
·
verified ·
1 Parent(s): 42ab83e

Update weather.py

Browse files
Files changed (1) hide show
  1. weather.py +84 -0
weather.py CHANGED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import re
3
+ import datasets
4
+ import requests
5
+ import time
6
+ from bs4 import BeautifulSoup
7
+
8
+ _CITATION = """
9
+ @misc{weather-dataset,
10
+ title = "Weather Dataset",
11
+ author = "ICE",
12
+ year = "2025",
13
+ url = "https://huggingface.co/datasets/FrostIce/Weather"
14
+ }
15
+ """
16
+
17
+ _DESCRIPTION = """
18
+ Этот набор данных содержит информацию о погоде, полученную с различных погодных сайтов.
19
+ Он включает такие данные, как температура, влажность, скорость ветра и погодные условия
20
+ для разных мест. Набор данных регулярно обновляется, чтобы отражать последние погодные данные."""
21
+
22
+ _HOMEPAGE = "https://huggingface.co/ProICE"
23
+ _LICENSE = "ICE License, Version 2.0"
24
+
25
+ _URLS = {
26
+ "weather": "https://weather.com/" # Replace with actual weather page URL
27
+ }
28
+
29
+ _VERSION = datasets.Version("1.0.0")
30
+
31
+ class WeatherDataset(datasets.GeneratorBasedBuilder):
32
+ """Weather dataset for scraping weather information."""
33
+
34
+ def _info(self):
35
+ features = datasets.Features(
36
+ {
37
+ "location": datasets.Value("string"),
38
+ "temperature": datasets.Value("float32"),
39
+ "humidity": datasets.Value("float32"),
40
+ "wind_speed": datasets.Value("float32"),
41
+ "condition": datasets.Value("string"),
42
+ "timestamp": datasets.Value("string"),
43
+ }
44
+ )
45
+
46
+ return datasets.DatasetInfo(
47
+ description=_DESCRIPTION,
48
+ features=features,
49
+ homepage=_HOMEPAGE,
50
+ license=_LICENSE,
51
+ citation=_CITATION,
52
+ )
53
+
54
+ def _split_generators(self, dl_manager):
55
+ """Returns SplitGenerators."""
56
+ downloaded_files = dl_manager.download_and_extract(_URLS)
57
+ return [
58
+ datasets.SplitGenerator(name="weather", gen_kwargs={"filepath": downloaded_files["weather"]}),
59
+ ]
60
+
61
+ def _generate_examples(self, filepath):
62
+ """Yields examples."""
63
+ # Scrape weather data from the specified URL
64
+ response = requests.get(filepath)
65
+ soup = BeautifulSoup(response.content, 'html.parser')
66
+
67
+ # Example parsing logic (this will depend on the actual HTML structure of the page)
68
+ # You will need to inspect the weather.com page to find the correct classes/IDs
69
+ for weather_entry in soup.find_all('div', class_='CurrentConditions--primary--2SVPh'): # Adjust class name
70
+ location = soup.find('h1', class_='CurrentConditions--location--1Ayv3').text # Adjust class name
71
+ temperature = float(weather_entry.find('span', class_='CurrentConditions--tempValue--3KcTQ').text.replace('°', '')) # Adjust class name
72
+ humidity = float(weather_entry.find('span', class_='CurrentConditions--humidity--AlSGP').text.replace('Humidity', '').replace('%', '').strip()) # Adjust class name
73
+ wind_speed = float(weather_entry.find('span', class_='CurrentConditions--windValue--3Kx8I').text.replace(' km/h', '').strip()) # Adjust class name
74
+ condition = weather_entry.find('div', class_='CurrentConditions--phraseValue--2xXSr').text # Adjust class name
75
+ timestamp = time.now().isoformat() # Use current timestamp or extract from the page if available
76
+
77
+ yield location, {
78
+ "location": location,
79
+ "temperature": temperature,
80
+ "humidity": humidity,
81
+ "wind_speed": wind_speed,
82
+ "condition": condition,
83
+ "timestamp": timestamp,
84
+ }