好友
阅读权限10
听众
最后登录1970-1-1
|
丹佛斯阿胶
发表于 2020-11-16 20:03
代码
import json
import requests
import wordcloud
import matplotlib
url = 'https://api.yimian.xyz/coro'
city_dict = {}
data = requests.get(url).text
json_data = json.loads(data)
for p in json_data:
if 'cities' in p:
for c in p['cities']:
city_name = c['cityName']
ccount = c['confirmedCount']
sCount = c['suspectedCount']
total = int(ccount) + int(sCount)
city_dict[city_name] = total
else:
city_name = p['provinceName']
ccount = p['confirmedCount']
sCount = p['suspectedCount']
total = int(ccount) + int(sCount)
city_dict[city_name] = total
with open('city.txt', 'w')as f:
for k, v in city_dict.items():
f.write(f'{k}:{v}\n')
ccloud = wordcloud.WordCloud(font_path='\Windows\Fonts\msyh.ttf')
ccloud.generate_from_frequencies(frequencies=city_dict)
matplotlib.figure()
matplotlib.imshow(ccloud, interpolation='bilinear')
matplotlib.axis('off')
matplotlib.show()
报错
|
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|