功能介绍
支持全球疫情数据获取以及对应的国家、省份、城市数据获取
具体操作
import violetSpider as spider
from violetSpider.core.model import Word, Nation, Province
# 1.获取全球数据
word: Word = spider.find_word()
print(word, type(word))
# <violetSpider.core.model.World object at 0x0000021DD6FC3AC8> <class 'violetSpider.core.model.World'>
# 2.获取对应数据
# 获取该对象上所有的存储数据的 Key,drop=True【默认删除值为 None 的 Key】
keys = word.keys(drop=True)
values = word.values(drop=True)
value = word.name
print(keys, values, value)
# dict_keys(['name', 'nowConfirm', 'confirm', 'heal', 'dead', 'lastUpdateTime'])
# dict_values(['地球', 46987153, 217021468, 165524088, 4510227, '2021-10-20 13:43:34'])
# 地球
获取国家数据
# 根据全球数据获取国家数据
# 如果不指定具体国家,会获取所有国家
# 所有数据对象都包含 keys() 和 values()
nations: list = word.searchNation('美国', '法国', '西班牙')
nation: Nation = nations[0]
print(nations)
print(nation.keys(), nation.values())
# [<violetSpider.core.model.Nation object at 0x000002245C37AD30>,
# <violetSpider.core.model.Nation object at 0x000002245C37ACF8>,
# <violetSpider.core.model.Nation object at 0x000002245C37AC88>]
# dict_keys(['name', 'continent', 'y', 'date', 'confirmAdd', 'confirmAddCut', 'confirm', 'suspect', 'dead', 'heal', 'nowConfirm', 'confirmCompare', 'nowConfirmCompare', 'healCompare', 'deadCompare'])
# dict_values(['美国', '北美洲', '2021', '08.31', 0, 0, 39668541, 0, 654696, 30826478, 8187367, 0, 0, 0, 0])
获取某个国家下的省份数据
# 先获取具体国家
nation: Nation = word.searchNation_one('美国')
# 获取指定省份,如果不指定则获取所有
provinces = nation.searchProvince()
for province in provinces[:3]:
print(province.name)
# 加利福尼亚
# 德克萨斯
# 佛罗里达
获取省份下面的城市
nation: Nation = word.searchNation_one('美国')
province: Province = nation.searchProvince_one('德克萨斯')
# 获取指定城市,如果不指定则获取所有
citys = province.searchCity()
for city in citys[:3]:
print(city)
# 当然,有些省份是没有公布城市数据的
# violetSpider.core.error.WorldData: 很抱歉, 德克萨斯, 并未开放城市数据
# 所有你可以这样写
# 不过别报太大希望,城市一般不会获取到数据
nation: Nation = word.searchNation_one('美国')
provinces = nation.searchProvince()
for province in provinces:
try:
c = province.searchCity()[:3]
for city in c:
print(city.name)
print(province.name)
break
except Exception as e:
print(e)
保存数据
# 目前支持 mysql 和 csv 保持
# 具体 API 如下
import violetSpider as spider
spider.save_csv(
path: str, # 存储路径,必须
data: list, # 数据,装有 Nation、Province、City 对象的列表
fields=None, # 存储指定,不指定则全选
drop=True # 是否删除空值字段
)
spider.save_mysql(
username: str,
password: str,
host: str,
port: int,
databases: str,
data: list, # 数据,装有 Nation、Province、City 对象的列表
table=None, # 是否指定表
fields=None, # 指定保存的字段
drop=True # 只要有一个字段的值为空, 那么便不保存这个字段
)
更新内容
1.1.0 -> 基本功能实现
1.1.3 -> 修复了 china 数据无法获取
Metadata
Release files for violetSpider 1.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| violetSpider-1.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Release files / violetSpider-1.1.3-py3-none-any.whl
| Download URL | violetSpider-1.1.3-py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7e4f88e3c6c605110ae10b66228835e44e5e830c7fc687beabfa35899cf4306e
|
|
BLAKE2b-256 checksum How to use checksums |
2da54dbb6bb27fe625ae13e6a4f101b575a32660851d8cacf65559c8047deac8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.13
|
Security for violetSpider 1.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.