parent
f2c527ee2c
commit
7703bbf66f
@ -0,0 +1,26 @@
|
||||
from http import HTTPStatus
|
||||
from urllib.parse import urlparse, unquote
|
||||
from pathlib import PurePosixPath
|
||||
import requests
|
||||
from dashscope import ImageSynthesis
|
||||
from WxMini.Milvus.Config.MulvusConfig import *
|
||||
|
||||
prompt = "高山,直上云端。少年,御剑飞行。怪物,紧追不放,大战,一触即发。"
|
||||
|
||||
|
||||
print('----sync call, please wait a moment----')
|
||||
rsp = ImageSynthesis.call(api_key=MODEL_API_KEY,
|
||||
model="wanx2.1-t2i-turbo",
|
||||
prompt=prompt,
|
||||
n=1,
|
||||
size='1024*1024')
|
||||
print('response: %s' % rsp)
|
||||
if rsp.status_code == HTTPStatus.OK:
|
||||
# 在当前目录下保存图片
|
||||
for result in rsp.output.results:
|
||||
file_name = PurePosixPath(unquote(urlparse(result.url).path)).parts[-1]
|
||||
#with open('./%s' % file_name, 'wb+') as f:
|
||||
# f.write(requests.get(result.url).content)
|
||||
else:
|
||||
print('sync_call Failed, status_code: %s, code: %s, message: %s' %
|
||||
(rsp.status_code, rsp.code, rsp.message))
|
@ -0,0 +1,74 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
def get_weather():
|
||||
url = "https://www.weather.com.cn/textFC/db.shtml"
|
||||
response = requests.get(url)
|
||||
html_content = response.content
|
||||
|
||||
soup = BeautifulSoup(html_content, 'html.parser')
|
||||
|
||||
# 获取日期
|
||||
day_tabs = soup.find('ul', class_='day_tabs')
|
||||
days = [day.text.strip() for day in day_tabs.find_all('li')][:3] # 只取前三天
|
||||
|
||||
# 获取天气信息
|
||||
weather_data = []
|
||||
tables = soup.find_all('table', width="100%") # 找到所有天气表格
|
||||
for table in tables:
|
||||
rows = table.find_all('tr')
|
||||
for row in rows:
|
||||
cells = row.find_all('td')
|
||||
if len(cells) >= 8: # 确保是天气数据行
|
||||
city = cells[1].text.strip()
|
||||
weather_info = {
|
||||
'city': city,
|
||||
'today': {
|
||||
'day': {
|
||||
'weather': cells[2].text.strip(),
|
||||
'wind': cells[3].text.strip(),
|
||||
'temp': cells[4].text.strip()
|
||||
},
|
||||
'night': {
|
||||
'weather': cells[5].text.strip(),
|
||||
'wind': cells[6].text.strip(),
|
||||
'temp': cells[7].text.strip()
|
||||
}
|
||||
}
|
||||
}
|
||||
# 检查是否有明天和后天的数据
|
||||
if len(cells) >= 15:
|
||||
weather_info['tomorrow'] = {
|
||||
'day': {
|
||||
'weather': cells[9].text.strip(),
|
||||
'wind': cells[10].text.strip(),
|
||||
'temp': cells[11].text.strip()
|
||||
},
|
||||
'night': {
|
||||
'weather': cells[12].text.strip(),
|
||||
'wind': cells[13].text.strip(),
|
||||
'temp': cells[14].text.strip()
|
||||
}
|
||||
}
|
||||
if len(cells) >= 22:
|
||||
weather_info['day_after_tomorrow'] = {
|
||||
'day': {
|
||||
'weather': cells[16].text.strip(),
|
||||
'wind': cells[17].text.strip(),
|
||||
'temp': cells[18].text.strip()
|
||||
},
|
||||
'night': {
|
||||
'weather': cells[19].text.strip(),
|
||||
'wind': cells[20].text.strip(),
|
||||
'temp': cells[21].text.strip()
|
||||
}
|
||||
}
|
||||
weather_data.append(weather_info)
|
||||
|
||||
return days, weather_data
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
days, weather_data = get_weather()
|
||||
|
||||
print(weather_data)
|
Loading…
Reference in new issue