Created
July 25, 2021 14:52
-
-
Save nikhiljohn10/c8a5856ee6cde39b352e29354e7a6cf8 to your computer and use it in GitHub Desktop.
Co-Win Kerala Sputnik Hunt 1.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import requests | |
| import argparse | |
| from time import sleep | |
| from os import system, name | |
| from datetime import datetime | |
| ''' | |
| ============================== | |
| Co-Win Kerala Sputnik Hunt 1.0 | |
| ============================== | |
| API: Co-WIN Public API 1.3.1 | |
| Author: Nikhil John | |
| Limitation: 100 Requests per 5 mins per IP Address | |
| INSTALLTION | |
| ----------- | |
| $ ln -s <location of python file> /home/<username>/.local/bin/cowin | |
| $ cowin -h | |
| DISTRICT LIST: | |
| -------------- | |
| Kasaragod : 295 | |
| Thiruvananthapuram : 296 | |
| Kannur : 297 | |
| Kollam : 298 | |
| Wayanad : 299 | |
| Pathanamthitta : 300 | |
| Alappuzha : 301 | |
| Malappuram : 302 | |
| Thrissur : 303 | |
| Kottayam : 304 | |
| Kozhikode : 305 | |
| Idukki : 306 | |
| Ernakulam : 307 | |
| Palakkad : 308 | |
| ''' | |
| class Cowin: | |
| def __init__(self) -> None: | |
| self.vaccine = 'SPUTNIK V' | |
| self.base_url = 'https://cdn-api.co-vin.in/api/v2/appointment/sessions/public' | |
| self.headers = {'accept': 'application/json', | |
| 'accept-language': 'en_IN'} | |
| self.date = datetime.now() | |
| def all(self) -> None: | |
| for district_id in range(295, 309): | |
| self.district(district_id) | |
| def district(self, id: int) -> None: | |
| url = self.base_url + '/calendarByDistrict' | |
| parameters = {'district_id': str( | |
| id), 'date': self.date.strftime('%d-%m-%Y')} | |
| req = requests.get(url, params=parameters, headers=self.headers) | |
| res = req.json() | |
| centers = res['centers'] | |
| if centers: | |
| for center in centers: | |
| sessions = center['sessions'] | |
| if sessions: | |
| for session in sessions: | |
| if session['vaccine'] == 'SPUTNIK V': | |
| print( | |
| '\n[', | |
| session['date'], | |
| ']:', | |
| center['district_name'], | |
| '\n', | |
| ) | |
| print('\t', center['name']) | |
| print('\t\tAvailable shots:', | |
| session['available_capacity']) | |
| print('\t\tVaccine:', session['vaccine']) | |
| print('\t\tAddress:', center['address']) | |
| print('\t\tSlots:', session['slots'], '\n') | |
| def clear(): | |
| if name == 'nt': | |
| _ = system('cls') | |
| else: | |
| _ = system('clear') | |
| def loop(func): | |
| def task(*args, **kwargs): | |
| clear() | |
| try: | |
| while True: | |
| func(*args, **kwargs) | |
| print('(Use Ctrl+C to exit)') | |
| sleep(5) | |
| clear() | |
| except KeyboardInterrupt: | |
| print('\rThank you for using CoWin') | |
| return task | |
| @loop | |
| def sputnik_in_ekm(cowin: Cowin): | |
| cowin.district(307) | |
| def load_args(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument( | |
| '-a', '--all', help='display all district', action='store_true') | |
| return parser.parse_args() | |
| if __name__ == '__main__': | |
| args = load_args() | |
| cowin = Cowin() | |
| if args.all: | |
| cowin.all() | |
| else: | |
| sputnik_in_ekm(cowin=cowin) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment