Package: vaccinewatcher
Vaccine WatcherMonitor Vaccine Availability from your Local CVS and Walgreens (US Only).Disclaimer: This library is provided as is. It involves some minor browser tricks in order to properly get the availability data. Use at your own risk.Originally inspired fromVaccine-hunter.js, I wanted to write a pythonic version of it. Somewhat ironically, right after publishing and running it, availability popped up.What does it doYou can run it as a command line program.You can run it pythonically through the VaccineWatcher object class - either with real-time polling, or on-demand.It currently polls CVS and Walgreen's Website through a modified Selenium calledSelenium-wireto be able to access the headers and parse the response data. Both CVS and Walgreens use different detectors/cookies in order to determine your location, so using plain requests/sessions was a bit problematic.This method was the one that ensured consistency no matter which location.Hopefully, you'll see something like this:[VaccineWatcher]info:CVShasAvailableAppointmentsinHOUSTON,TXPrerequisitesYou should have chromedriver installed and in your paths, which a typical install will do.# linuxapt-getinstallchromedriver# macos - this may cause issues if your Chrome Browser =/= to your Chromedriver version.brewinstallchromedriver# windows - sorry, I don't know.Installationvaccinewatcheris on currently only available on Github since it's not stable yet:pipinstall--upgradegit+https://github.com/trisongz/vaccinewatcherQuick StartThe below is the minimum required variables to run the CLI version, with optional flags for additional control.If you have a lower-spec device, I would suggest increasing the frequency, since due to the modified Selenium, it can tend to be more memory intensive.# --no-cvs / disables CVS polling# --no-wg / disables Walgreens polling# --freq / how many secs between polling. default = 600 secs / 10 mins# --zapier / provide a Zapier Webhook URL to send notifications to# --verbose / enable logging for all results, regardless of options.# make sure if you have multiple words in any variable to have them in quotations.vaccinewatcher--city"Houston"--state"Texas"--abbr"TX"--zip"77056"The Pythonic API can be accessed with more ease. Rather than importing theVaccineWatcherobject directly, it's recommended to useget_vaccine_watcherwhich prevents multiple instances from spawning through threading.Lock.fromvaccinewatcherimportget_vaccine_watcherfreq=600hook=Nonecheck_wg=Truecheck_cvs=Trueparams={'city':'San Francisco','state':'California','state_abbr':'CA','zipcode':'94117'}watcher=get_vaccine_watcher(config=params,freq_secs=freq,hook=hook,check_walgreens=check_wg,check_cvs=check_cvs))# if you want to poll on demand:res=watcher(check_cvs=False,check_walgreens=True)# > {'walgreens': False}## NOTE - It is not recommended to run both a service daemon and on-demand, since the process in polling the websites is sensitive to the steps in which the data is queried. If the browser is interrupted by another call, it will likely mess up.# to run as a thread daemonwatcher.run()# to kill the servicewatcher.close()# Access the last captured datares=watcher.last_check()# results of res# {'cvs': {'available': False, 'data': None, 'timestamp': None},# 'walgreens': {'available': False, 'data': {'appointmentsAvailable': False, 'availabilityGroups': [], 'days': 4, 'radius': 25,# 'stateCode': 'CA', 'stateName': 'California', 'zipCode': '94117'}, 'timestamp': '03-30-2021 07:17:24'}}More Advanced StuffThere are a few additional settings available for the adventurous.The Hook FunctionThe hook function is expected to receive two parameters,messageanddata. Below is the included example Zapier Webhook Listener. Message will only be included when availability changes - i.e. is available, rather than all the time. However, you can choose to send the data that is polled through the daemon by includingsend_data=Trueandalways_send=Truein the initial params, which will then always send the data to your webhook, regardless of status change.classZapierWebhook:def__init__(self,url):self.url=urlself.s=requests.Session()logger.log(f'Initialized Zapier Webhook at{self.url}')def__call__(self,message=None,data=None):ifnotmessageordata:returnparams={}ifmessage:params['message']=messageifdata:params.update(data)params['timestamp']=create_timestamp()r=self.s.post(self.url,json=params)ifr.status_code==200:logger.log(f'Successfully sent to Zapier Webhook:{params}')else:logger.log(f'Potential Error sending to Zapier Webhook')Final NotesIf you found this library helpful, please do share it with others. This is what is within my capabilities to help provide a resource and tool to allow others to find vaccine availibility, and help bring an end to the pandemic. If you end up using some parts of this library for something bigger, let me know! I'd love to check it out.