在Python使用 covin 跟踪 Covid-19 疫苗槽
印度最近发起了最大的疫苗接种活动,让每个人都接种 COVID-19 疫苗。 CoWin 是处理空位可用性的官方网站。出去的过程可能是乏味的项目。这个站点的Python API 包装器 CoWin 提供了一些方法,可以帮助我们根据 Pincode 和地区找到我们附近的可用性。
安装:
要安装此模块,请在终端中键入以下命令。
pip install cowin
获取所有状态的列表
这里将使用 get_states() 方法获取所有状态。首先,我们将导入模块,然后我们使用 coWinAPI() 访问 get_state() 对象。此方法获取当前状态列表及其 ID
代码:
Python3
from cowin_api import CoWinAPI
from pprint import pprint
cowin = CoWinAPI()
states = cowin.get_states()
print("All States List : ")
print(states)
Python3
from cowin_api import CoWinAPI
from pprint import pprint
cowin = CoWinAPI()
state_id = '24'
districts = cowin.get_districts(state_id)
print("Districts by State Id : ")
pprint(districts)
Python3
from cowin_api import CoWinAPI
from pprint import pprint
cowin = CoWinAPI()
district_id = '425'
date = '14-05-2021'
available_centers = cowin.get_availability_by_district(district_id, date)
print("All Available Centers [ By district ] : ")
pprint(available_centers)
Python3
from cowin_api import CoWinAPI
from pprint import pprint
cowin = CoWinAPI()
pin_code = "796014"
date = '14-05-2021'
min_age_limit = 18
available_centers = cowin.get_availability_by_pincode(pin_code, date)
print("All Available Centers [ By Pincode ] : ")
pprint(available_centers)
输出 :
获取一个州的所有地区
这里我们将使用 get_districts(),它返回区名,将整数传递给 get_districts()。 get_districts(state_id) 将上述 API 返回的状态 ID 作为参数,并返回所有带有 ID 的地区。
代码:
蟒蛇3
from cowin_api import CoWinAPI
from pprint import pprint
cowin = CoWinAPI()
state_id = '24'
districts = cowin.get_districts(state_id)
print("Districts by State Id : ")
pprint(districts)
输出 :
获取地区所有中心的可用性信息
这里我们将获取该地区的中心信息,get_availability_by_district() 方法能够返回该地区内的所有中心信息。
Syntax: get_availability_by_district(district_id, date, min_age_limit)
Parameters :
- district_id : ID optained using above API.
- date(optional) : Date in dd-mm-YYYY format. Defaults to today.
- min_age_limit(optional) : Minimum age to be queried, since slots get open in different age group brackets. If not given, all ages are used as filter.
代码:
蟒蛇3
from cowin_api import CoWinAPI
from pprint import pprint
cowin = CoWinAPI()
district_id = '425'
date = '14-05-2021'
available_centers = cowin.get_availability_by_district(district_id, date)
print("All Available Centers [ By district ] : ")
pprint(available_centers)
输出 :
通过密码获取所有中心的可用性信息
这里我们会根据Pincode获取所有的中心可用性信息,get_availability_by_pincode可以通过Pincode返回中心信息。
Syntax: get_availability_by_pincode(pin_code, date, min_age_limit)
Parameter:
- pin_code : Pincode of area to find centers.
- date(optional) : Date in dd-mm-YYYY format. Defaults to today.
- min_age_limit(optional) : Minimum age to be queried, since slots get open in different age group brackets. If not given, all ages are used as filter.
代码:
蟒蛇3
from cowin_api import CoWinAPI
from pprint import pprint
cowin = CoWinAPI()
pin_code = "796014"
date = '14-05-2021'
min_age_limit = 18
available_centers = cowin.get_availability_by_pincode(pin_code, date)
print("All Available Centers [ By Pincode ] : ")
pprint(available_centers)
输出 :