ParsWeather 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- parsweather-0.0.1/LICENSE +21 -0
- parsweather-0.0.1/PKG-INFO +35 -0
- parsweather-0.0.1/README.md +1 -0
- parsweather-0.0.1/pyproject.toml +25 -0
- parsweather-0.0.1/setup.cfg +4 -0
- parsweather-0.0.1/src/ParsWeather/ParsWeather.py +439 -0
- parsweather-0.0.1/src/ParsWeather/__init__.py +0 -0
- parsweather-0.0.1/src/ParsWeather.egg-info/PKG-INFO +35 -0
- parsweather-0.0.1/src/ParsWeather.egg-info/SOURCES.txt +10 -0
- parsweather-0.0.1/src/ParsWeather.egg-info/dependency_links.txt +1 -0
- parsweather-0.0.1/src/ParsWeather.egg-info/requires.txt +3 -0
- parsweather-0.0.1/src/ParsWeather.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ali Ayati Qaffari
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: ParsWeather
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Python package for getting Iran's weather data, including temperature and RealFeel.
|
|
5
|
+
Author-email: Ali Ayati Qaffari <ayatiali910@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Ali Ayati Qaffari
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Profile, https://github.com/MrAAQPy
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: beautifulsoup4
|
|
32
|
+
Requires-Dist: lxml
|
|
33
|
+
Requires-Dist: requests
|
|
34
|
+
|
|
35
|
+
Coming soon...
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Coming soon...
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ParsWeather"
|
|
7
|
+
version = "0.0.1"
|
|
8
|
+
description = "A Python package for getting Iran's weather data, including temperature and RealFeel."
|
|
9
|
+
authors = [
|
|
10
|
+
{name = "Ali Ayati Qaffari", email = "ayatiali910@gmail.com"}
|
|
11
|
+
]
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = {file = "LICENSE"}
|
|
14
|
+
dependencies = [
|
|
15
|
+
"beautifulsoup4",
|
|
16
|
+
"lxml",
|
|
17
|
+
"requests"
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
"Profile" = "https://github.com/MrAAQPy"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
[tool.setuptools.packages.find]
|
|
25
|
+
where = ["src"]
|
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
from bs4 import BeautifulSoup
|
|
3
|
+
import random
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
weather_urls = {
|
|
7
|
+
"آذربایجان شرقی": "https://www.accuweather.com/fa/ir/tabriz/207308/weather-forecast/207308",
|
|
8
|
+
"آذربایجان غربی": "https://www.accuweather.com/fa/ir/urmia/207147/weather-forecast/207147",
|
|
9
|
+
"اردبیل": "https://www.accuweather.com/fa/ir/ardabil/206976/weather-forecast/206976",
|
|
10
|
+
"اصفهان": "https://www.accuweather.com/fa/ir/isfahan/208194/weather-forecast/208194",
|
|
11
|
+
"البرز": "https://www.accuweather.com/fa/ir/karaj/211367/weather-forecast/211367",
|
|
12
|
+
"ایلام": "https://www.accuweather.com/fa/ir/ilam/208937/weather-forecast/208937",
|
|
13
|
+
"بوشهر": "https://www.accuweather.com/fa/ir/bandar-bushehr/207502/weather-forecast/207502",
|
|
14
|
+
"تهران": "https://www.accuweather.com/fa/ir/tehran/210841/weather-forecast/210841",
|
|
15
|
+
"چهارمحال و بختیاری": "https://www.accuweather.com/fa/ir/shahr-e-kord/207539/weather-forecast/207539",
|
|
16
|
+
"خراسان جنوبی": "https://www.accuweather.com/fa/ir/birjand/209740/weather-forecast/209740",
|
|
17
|
+
"خراسان رضوی": "https://www.accuweather.com/fa/ir/mashhad/209737/weather-forecast/209737",
|
|
18
|
+
"خراسان شمالی": "https://www.accuweather.com/fa/ir/bojnurd/209467/weather-forecast/209467",
|
|
19
|
+
"خوزستان": "https://www.accuweather.com/fa/ir/ahvaz/210047/weather-forecast/210047",
|
|
20
|
+
"زنجان": "https://www.accuweather.com/fa/ir/zanjan/211728/weather-forecast/211728",
|
|
21
|
+
"سمنان": "https://www.accuweather.com/fa/ir/semnan/210904/weather-forecast/210904",
|
|
22
|
+
"سیستان و بلوچستان": "https://www.accuweather.com/fa/ir/zahedan/211207/weather-forecast/211207",
|
|
23
|
+
"فارس": "https://www.accuweather.com/fa/ir/shiraz/208538/weather-forecast/208538",
|
|
24
|
+
"قزوین": "https://www.accuweather.com/fa/ir/qazvin/210816/weather-forecast/210816",
|
|
25
|
+
"قم": "https://www.accuweather.com/fa/ir/qom/210842/weather-forecast/210842",
|
|
26
|
+
"کردستان": "https://www.accuweather.com/fa/ir/sanandaj/210185/weather-forecast/210185",
|
|
27
|
+
"کرمان": "https://www.accuweather.com/fa/ir/kerman/209375/weather-forecast/209375",
|
|
28
|
+
"کرمانشاه": "https://www.accuweather.com/fa/ir/kermanshah/209439/weather-forecast/209439",
|
|
29
|
+
"کهگیلویه و بویراحمد": "urhttps://www.accuweather.com/fa/ir/yasuj/210096/weather-forecast/210096l",
|
|
30
|
+
"گلستان": "https://www.accuweather.com/fa/ir/gorgan/208708/weather-forecast/208708",
|
|
31
|
+
"گیلان": "https://www.accuweather.com/fa/ir/rasht/208612/weather-forecast/208612",
|
|
32
|
+
"لرستان": "https://www.accuweather.com/fa/ir/khorramabad/210291/weather-forecast/210291",
|
|
33
|
+
"مازندران": "https://www.accuweather.com/fa/ir/sari/210584/weather-forecast/210584",
|
|
34
|
+
"مرکزی": "https://www.accuweather.com/fa/ir/arak/210434/weather-forecast/210434",
|
|
35
|
+
"هرمزگان": "https://www.accuweather.com/fa/ir/bandar-abbas/208929/weather-forecast/208929",
|
|
36
|
+
"همدان": "https://www.accuweather.com/fa/ir/hamedan/208760/weather-forecast/208760",
|
|
37
|
+
"یزد": "https://www.accuweather.com/fa/ir/yazd/211668/weather-forecast/211668"
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
air = {
|
|
41
|
+
"آذربایجان شرقی": "https://www.accuweather.com/fa/ir/tabriz/207308/air-quality-index/207308",
|
|
42
|
+
"آذربایجان غربی": "https://www.accuweather.com/fa/ir/urmia/207147/air-quality-index/207147",
|
|
43
|
+
"اردبیل": "https://www.accuweather.com/fa/ir/ardabil/206976/air-quality-index/206976",
|
|
44
|
+
"اصفهان": "https://www.accuweather.com/fa/ir/isfahan/208194/air-quality-index/208194",
|
|
45
|
+
"البرز": "https://www.accuweather.com/fa/ir/karaj/211367/air-quality-index/211367",
|
|
46
|
+
"ایلام": "https://www.accuweather.com/fa/ir/ilam/208937/air-quality-index/208937",
|
|
47
|
+
"بوشهر": "https://www.accuweather.com/fa/ir/bandar-bushehr/207502/air-quality-index/207502",
|
|
48
|
+
"تهران": "https://www.accuweather.com/fa/ir/tehran/210841/air-quality-index/210841",
|
|
49
|
+
"چهارمحال و بختیاری": "https://www.accuweather.com/fa/ir/shahr-e-kord/207539/air-quality-index/207539",
|
|
50
|
+
"خراسان جنوبی": "https://www.accuweather.com/fa/ir/birjand/209740/air-quality-index/209740",
|
|
51
|
+
"خراسان رضوی": "https://www.accuweather.com/fa/ir/mashhad/209737/air-quality-index/209737",
|
|
52
|
+
"خراسان شمالی": "https://www.accuweather.com/fa/ir/bojnurd/209467/air-quality-index/209467",
|
|
53
|
+
"خوزستان": "https://www.accuweather.com/fa/ir/ahvaz/210047/air-quality-index/210047",
|
|
54
|
+
"زنجان": "https://www.accuweather.com/fa/ir/zanjan/211728/air-quality-index/211728",
|
|
55
|
+
"سمنان": "https://www.accuweather.com/fa/ir/semnan/210904/air-quality-index/210904",
|
|
56
|
+
"سیستان و بلوچستان": "https://www.accuweather.com/fa/ir/zahedan/211207/air-quality-index/211207",
|
|
57
|
+
"فارس": "https://www.accuweather.com/fa/ir/shiraz/208538/air-quality-index/208538",
|
|
58
|
+
"قزوین": "https://www.accuweather.com/fa/ir/qazvin/210816/air-quality-index/210816",
|
|
59
|
+
"قم": "https://www.accuweather.com/fa/ir/qom/210842/air-quality-index/210842",
|
|
60
|
+
"کردستان": "https://www.accuweather.com/fa/ir/sanandaj/210185/air-quality-index/210185",
|
|
61
|
+
"کرمان": "https://www.accuweather.com/fa/ir/kerman/209375/air-quality-index/209375",
|
|
62
|
+
"کرمانشاه": "https://www.accuweather.com/fa/ir/kermanshah/209439/air-quality-index/209439",
|
|
63
|
+
"کهگیلویه و بویراحمد": "urhttps://www.accuweather.com/fa/ir/yasuj/210096/air-quality-index/210096l",
|
|
64
|
+
"گلستان": "https://www.accuweather.com/fa/ir/gorgan/208708/air-quality-index/208708",
|
|
65
|
+
"گیلان": "https://www.accuweather.com/fa/ir/rasht/208612/air-quality-index/208612",
|
|
66
|
+
"لرستان": "https://www.accuweather.com/fa/ir/khorramabad/210291/air-quality-index/210291",
|
|
67
|
+
"مازندران": "https://www.accuweather.com/fa/ir/sari/210584/air-quality-index/210584",
|
|
68
|
+
"مرکزی": "https://www.accuweather.com/fa/ir/arak/210434/air-quality-index/210434",
|
|
69
|
+
"هرمزگان": "https://www.accuweather.com/fa/ir/bandar-abbas/208929/air-quality-index/208929",
|
|
70
|
+
"همدان": "https://www.accuweather.com/fa/ir/hamedan/208760/air-quality-index/208760",
|
|
71
|
+
"یزد": "https://www.accuweather.com/fa/ir/yazd/211668/air-quality-index/211668"
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def get_support_city():
|
|
76
|
+
return list(weather_urls.keys())
|
|
77
|
+
|
|
78
|
+
cities = get_support_city()
|
|
79
|
+
print("شهرهای پشتیبانی شده:")
|
|
80
|
+
for city in cities:
|
|
81
|
+
print(city)
|
|
82
|
+
|
|
83
|
+
def get_temperature(city_name):
|
|
84
|
+
if city_name in weather_urls:
|
|
85
|
+
url = weather_urls[city_name]
|
|
86
|
+
else:
|
|
87
|
+
return "شهر مورد نظر پیدا نشد."
|
|
88
|
+
|
|
89
|
+
headers = {
|
|
90
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
response = requests.get(url, headers=headers)
|
|
94
|
+
|
|
95
|
+
if response.status_code == 200:
|
|
96
|
+
soup = BeautifulSoup(response.text, 'html.parser')
|
|
97
|
+
temp_tag = soup.find(class_='temp')
|
|
98
|
+
if temp_tag:
|
|
99
|
+
return temp_tag.text.strip()
|
|
100
|
+
else:
|
|
101
|
+
return "کلاس 'temp' پیدا نشد."
|
|
102
|
+
else:
|
|
103
|
+
return f"خطا در دریافت صفحه: {response.status_code}"
|
|
104
|
+
|
|
105
|
+
def get_realfeel(city_name):
|
|
106
|
+
if city_name in weather_urls:
|
|
107
|
+
url = weather_urls[city_name]
|
|
108
|
+
else:
|
|
109
|
+
return "شهر مورد نظر پیدا نشد."
|
|
110
|
+
|
|
111
|
+
headers = {
|
|
112
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
response = requests.get(url, headers=headers)
|
|
116
|
+
|
|
117
|
+
if response.status_code == 200:
|
|
118
|
+
soup = BeautifulSoup(response.text, 'html.parser')
|
|
119
|
+
realfeel_label = soup.find('span', class_='label', string='RealFeel Shade™')
|
|
120
|
+
if realfeel_label:
|
|
121
|
+
value_tag = realfeel_label.find_next('span', class_='value')
|
|
122
|
+
if value_tag:
|
|
123
|
+
return value_tag.text.strip()
|
|
124
|
+
else:
|
|
125
|
+
return "مقدار دما پیدا نشد."
|
|
126
|
+
else:
|
|
127
|
+
return "نمیدونم"
|
|
128
|
+
else:
|
|
129
|
+
return f"خطا در دریافت صفحه: {response.status_code}"
|
|
130
|
+
|
|
131
|
+
def get_wind(city_name):
|
|
132
|
+
if city_name in weather_urls:
|
|
133
|
+
url = weather_urls[city_name]
|
|
134
|
+
else:
|
|
135
|
+
return "شهر مورد نظر پیدا نشد."
|
|
136
|
+
|
|
137
|
+
headers = {
|
|
138
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
response = requests.get(url, headers=headers)
|
|
142
|
+
|
|
143
|
+
if response.status_code == 200:
|
|
144
|
+
soup = BeautifulSoup(response.text, 'html.parser')
|
|
145
|
+
wind_label = soup.find('span', class_='label', string='باد')
|
|
146
|
+
if wind_label:
|
|
147
|
+
value_tag = wind_label.find_next('span', class_='value')
|
|
148
|
+
if value_tag:
|
|
149
|
+
return value_tag.text.strip()
|
|
150
|
+
else:
|
|
151
|
+
return "نمیدونم"
|
|
152
|
+
else:
|
|
153
|
+
return "نمیدونم"
|
|
154
|
+
else:
|
|
155
|
+
return f"خطا در دریافت صفحه: {response.status_code}"
|
|
156
|
+
|
|
157
|
+
def get_air_quality(city_name):
|
|
158
|
+
if city_name in weather_urls:
|
|
159
|
+
url = weather_urls[city_name]
|
|
160
|
+
else:
|
|
161
|
+
return "شهر مورد نظر پیدا نشد."
|
|
162
|
+
|
|
163
|
+
headers = {
|
|
164
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
response = requests.get(url, headers=headers)
|
|
168
|
+
|
|
169
|
+
if response.status_code == 200:
|
|
170
|
+
soup = BeautifulSoup(response.text, 'html.parser')
|
|
171
|
+
air_quality_label = soup.find('span', class_='label', string='کیفیت هوا')
|
|
172
|
+
if air_quality_label:
|
|
173
|
+
value_tag = air_quality_label.find_next('span', class_='value')
|
|
174
|
+
if value_tag:
|
|
175
|
+
return value_tag.text.strip()
|
|
176
|
+
else:
|
|
177
|
+
return "مقدار کیفیت هوا پیدا نشد."
|
|
178
|
+
else:
|
|
179
|
+
return "برچسب 'کیفیت هوا' پیدا نشد."
|
|
180
|
+
else:
|
|
181
|
+
return f"خطا در دریافت صفحه: {response.status_code}"
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def get_radar_image_link(city_name):
|
|
186
|
+
if city_name in weather_urls:
|
|
187
|
+
url = weather_urls[city_name]
|
|
188
|
+
else:
|
|
189
|
+
return "شهر مورد نظر پیدا نشد."
|
|
190
|
+
|
|
191
|
+
headers = {
|
|
192
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
response = requests.get(url, headers=headers)
|
|
196
|
+
|
|
197
|
+
if response.status_code == 200:
|
|
198
|
+
soup = BeautifulSoup(response.text, "html.parser")
|
|
199
|
+
radar_link_tag = soup.find("a", class_="base-map-cta card static-radar-map-recommended")
|
|
200
|
+
if radar_link_tag:
|
|
201
|
+
img_tag = radar_link_tag.find("img")
|
|
202
|
+
if img_tag:
|
|
203
|
+
image_url = img_tag.get("data-src")
|
|
204
|
+
if image_url:
|
|
205
|
+
random_param = f"?t={int(time.time())}_{random.randint(1000, 9999)}"
|
|
206
|
+
return image_url + random_param
|
|
207
|
+
else:
|
|
208
|
+
return "مقدار data-src یافت نشد."
|
|
209
|
+
else:
|
|
210
|
+
return "تگ <img> یافت نشد."
|
|
211
|
+
else:
|
|
212
|
+
return "تگ <a> مورد نظر یافت نشد."
|
|
213
|
+
else:
|
|
214
|
+
return f"خطا در بارگذاری صفحه: {response.status_code}"
|
|
215
|
+
|
|
216
|
+
def get_sun_times(city_name):
|
|
217
|
+
if city_name in weather_urls:
|
|
218
|
+
url = weather_urls[city_name]
|
|
219
|
+
else:
|
|
220
|
+
return "شهر مورد نظر پیدا نشد."
|
|
221
|
+
|
|
222
|
+
headers = {
|
|
223
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
try:
|
|
227
|
+
response = requests.get(url, headers=headers)
|
|
228
|
+
response.raise_for_status()
|
|
229
|
+
|
|
230
|
+
soup = BeautifulSoup(response.text, 'html.parser')
|
|
231
|
+
|
|
232
|
+
items = soup.find_all('div', class_='sunrise-sunset__item')
|
|
233
|
+
|
|
234
|
+
sun_times = {}
|
|
235
|
+
|
|
236
|
+
for item in items:
|
|
237
|
+
phrase = item.find('span', class_='sunrise-sunset__phrase').text.strip()
|
|
238
|
+
|
|
239
|
+
if "ساعت" in phrase:
|
|
240
|
+
times = item.find('div', class_='sunrise-sunset__times')
|
|
241
|
+
|
|
242
|
+
if times:
|
|
243
|
+
time_items = times.find_all('div', class_='sunrise-sunset__times-item')
|
|
244
|
+
time_dict = {}
|
|
245
|
+
|
|
246
|
+
for time_item in time_items:
|
|
247
|
+
label = time_item.find('span', class_='sunrise-sunset__times-label').text.strip()
|
|
248
|
+
value = time_item.find('span', class_='sunrise-sunset__times-value').text.strip()
|
|
249
|
+
time_dict[label] = value
|
|
250
|
+
|
|
251
|
+
sun_times[phrase] = time_dict
|
|
252
|
+
|
|
253
|
+
return sun_times
|
|
254
|
+
|
|
255
|
+
except requests.exceptions.RequestException as e:
|
|
256
|
+
return f"خطا در دریافت صفحه: {e}"
|
|
257
|
+
|
|
258
|
+
def get_weather_forecast(city_name):
|
|
259
|
+
if city_name in weather_urls:
|
|
260
|
+
url = weather_urls[city_name]
|
|
261
|
+
else:
|
|
262
|
+
return "شهر مورد نظر پیدا نشد."
|
|
263
|
+
|
|
264
|
+
headers = {
|
|
265
|
+
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:134.0) Gecko/20100101 Firefox/134.0"
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
response = requests.get(url,headers=headers)
|
|
269
|
+
response.raise_for_status()
|
|
270
|
+
|
|
271
|
+
soup = BeautifulSoup(response.text, 'html.parser')
|
|
272
|
+
|
|
273
|
+
daily_list = soup.find('div', class_='daily-list content-module')
|
|
274
|
+
|
|
275
|
+
daily_items = daily_list.find_all('a', class_='daily-list-item')
|
|
276
|
+
|
|
277
|
+
forecast_data = []
|
|
278
|
+
|
|
279
|
+
for item in daily_items:
|
|
280
|
+
date = item.find('div', class_='date').get_text(strip=True)
|
|
281
|
+
temp_hi = item.find('span', class_='temp-hi').get_text(strip=True)
|
|
282
|
+
temp_lo = item.find('span', class_='temp-lo').get_text(strip=True)
|
|
283
|
+
icon_url = item.find('img', class_='icon')['src']
|
|
284
|
+
|
|
285
|
+
forecast_data.append({
|
|
286
|
+
"تاریخ": date,
|
|
287
|
+
"دمای بالا": temp_hi,
|
|
288
|
+
"دمای پایین": temp_lo,
|
|
289
|
+
"آیکن وضعیت آب و هوا": icon_url
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
return forecast_data
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def get_dust_dander_data(city_name):
|
|
296
|
+
if city_name in weather_urls:
|
|
297
|
+
url = weather_urls[city_name]
|
|
298
|
+
else:
|
|
299
|
+
return "شهر مورد نظر پیدا نشد."
|
|
300
|
+
|
|
301
|
+
headers = {
|
|
302
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
response = requests.get(url, headers=headers)
|
|
306
|
+
|
|
307
|
+
if response.status_code == 200:
|
|
308
|
+
soup = BeautifulSoup(response.text, 'html.parser')
|
|
309
|
+
|
|
310
|
+
dust_dander_section = soup.find('a', {'data-slug': 'dust-dander'})
|
|
311
|
+
|
|
312
|
+
if dust_dander_section:
|
|
313
|
+
name = dust_dander_section.find('span', class_='health-activities__item__name').text.strip()
|
|
314
|
+
category = dust_dander_section.find('span', class_='health-activities__item__category').text.strip()
|
|
315
|
+
unsupported_category = dust_dander_section.find('span', class_='health-activities__item__category__unsupported').text.strip()
|
|
316
|
+
|
|
317
|
+
return {
|
|
318
|
+
'name': name,
|
|
319
|
+
'category': category,
|
|
320
|
+
'unsupported_category': unsupported_category
|
|
321
|
+
}
|
|
322
|
+
else:
|
|
323
|
+
return "دادهها پیدا نشدند"
|
|
324
|
+
else:
|
|
325
|
+
return f"خطا در بارگذاری صفحه: {response.status_code}"
|
|
326
|
+
|
|
327
|
+
def get_title(city_name):
|
|
328
|
+
if city_name in weather_urls:
|
|
329
|
+
url = weather_urls[city_name]
|
|
330
|
+
else:
|
|
331
|
+
return "شهر مورد نظر پیدا نشد."
|
|
332
|
+
|
|
333
|
+
headers = {
|
|
334
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
response = requests.get(url, headers=headers)
|
|
338
|
+
|
|
339
|
+
if response.status_code == 200:
|
|
340
|
+
soup = BeautifulSoup(response.text, "html.parser")
|
|
341
|
+
|
|
342
|
+
title = soup.find("title")
|
|
343
|
+
|
|
344
|
+
if title:
|
|
345
|
+
return title.text
|
|
346
|
+
else:
|
|
347
|
+
return "نمیدونم"
|
|
348
|
+
else:
|
|
349
|
+
return f"خطا در دریافت صفحه: {response.status_code}"
|
|
350
|
+
|
|
351
|
+
def get_forecast_details(city_name):
|
|
352
|
+
if city_name in weather_urls:
|
|
353
|
+
url = weather_urls[city_name]
|
|
354
|
+
else:
|
|
355
|
+
return "شهر مورد نظر پیدا نشد."
|
|
356
|
+
|
|
357
|
+
headers = {
|
|
358
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
response = requests.get(url, headers=headers)
|
|
362
|
+
|
|
363
|
+
if response.status_code == 200:
|
|
364
|
+
soup = BeautifulSoup(response.text, "html.parser")
|
|
365
|
+
|
|
366
|
+
forecast_link = soup.find("a", class_="local-forecast-summary")
|
|
367
|
+
|
|
368
|
+
if forecast_link:
|
|
369
|
+
forecast_title = forecast_link.find("h2").text if forecast_link.find("h2") else "عنوان پیدا نشد"
|
|
370
|
+
forecast_description = forecast_link.find("p").text if forecast_link.find("p") else "توضیح پیدا نشد"
|
|
371
|
+
|
|
372
|
+
return forecast_title, forecast_description
|
|
373
|
+
else:
|
|
374
|
+
return "خبر ندارم", ""
|
|
375
|
+
else:
|
|
376
|
+
return "درخواست ناموفق بود", ""
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def get_air_quality_shakes(city_name):
|
|
380
|
+
if city_name in air:
|
|
381
|
+
url = air[city_name]
|
|
382
|
+
else:
|
|
383
|
+
return "شهر مورد نظر پیدا نشد."
|
|
384
|
+
|
|
385
|
+
headers = {
|
|
386
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
response = requests.get(url, headers=headers)
|
|
390
|
+
|
|
391
|
+
if response.status_code == 200:
|
|
392
|
+
soup = BeautifulSoup(response.text, 'html.parser')
|
|
393
|
+
|
|
394
|
+
air_quality_div = soup.find('div', class_='aq-number-wrapper')
|
|
395
|
+
air_quality_details = soup.find('h3', class_='air-quality-data')
|
|
396
|
+
|
|
397
|
+
if air_quality_div and air_quality_details:
|
|
398
|
+
air_quality_value = air_quality_div.find('div', class_='aq-number').text.strip()
|
|
399
|
+
unit = air_quality_div.find('div', class_='aq-unit').text.strip()
|
|
400
|
+
|
|
401
|
+
category_text = air_quality_details.find('p', class_='category-text').text.strip()
|
|
402
|
+
statement = air_quality_details.find('p', class_='statement').text.strip()
|
|
403
|
+
|
|
404
|
+
return air_quality_value, unit, category_text, statement
|
|
405
|
+
else:
|
|
406
|
+
return None, None, "شاخص کیفیت هوا یافت نشد", "توضیحات یافت نشد"
|
|
407
|
+
else:
|
|
408
|
+
return None, None, f"خطا در دریافت دادهها: {response.status_code}", "توضیحات یافت نشد"
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
def get_weather_forecast_air(city_name):
|
|
412
|
+
if city_name in air:
|
|
413
|
+
url = air[city_name]
|
|
414
|
+
else:
|
|
415
|
+
return "شهر مورد نظر پیدا نشد."
|
|
416
|
+
|
|
417
|
+
headers = {
|
|
418
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
response = requests.get(url, headers=headers)
|
|
422
|
+
soup = BeautifulSoup(response.text, 'html.parser')
|
|
423
|
+
|
|
424
|
+
daily_forecast = soup.find_all('div', class_='air-quality-content')
|
|
425
|
+
|
|
426
|
+
forecast_data = []
|
|
427
|
+
|
|
428
|
+
for day in daily_forecast:
|
|
429
|
+
day_of_week = day.find('p', class_='day-of-week').text.strip()
|
|
430
|
+
date = day.find('p', class_='date').text.strip()
|
|
431
|
+
aqi = day.find('div', class_='aq-number').text.strip()
|
|
432
|
+
|
|
433
|
+
forecast_data.append({
|
|
434
|
+
'day_of_week': day_of_week,
|
|
435
|
+
'date': date,
|
|
436
|
+
'aqi': aqi
|
|
437
|
+
})
|
|
438
|
+
|
|
439
|
+
return forecast_data
|
|
File without changes
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: ParsWeather
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A Python package for getting Iran's weather data, including temperature and RealFeel.
|
|
5
|
+
Author-email: Ali Ayati Qaffari <ayatiali910@gmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 Ali Ayati Qaffari
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Profile, https://github.com/MrAAQPy
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Requires-Dist: beautifulsoup4
|
|
32
|
+
Requires-Dist: lxml
|
|
33
|
+
Requires-Dist: requests
|
|
34
|
+
|
|
35
|
+
Coming soon...
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/ParsWeather/ParsWeather.py
|
|
5
|
+
src/ParsWeather/__init__.py
|
|
6
|
+
src/ParsWeather.egg-info/PKG-INFO
|
|
7
|
+
src/ParsWeather.egg-info/SOURCES.txt
|
|
8
|
+
src/ParsWeather.egg-info/dependency_links.txt
|
|
9
|
+
src/ParsWeather.egg-info/requires.txt
|
|
10
|
+
src/ParsWeather.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ParsWeather
|