Last active
November 22, 2019 15:10
-
-
Save harshil93r/972c1a6cef10dd371d74f1a1d51d6225 to your computer and use it in GitHub Desktop.
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/local/bin/python | |
''' | |
Main page for UI : https://www.ustraveldocs.com/in/in-niv-waittimeinfo.asp#waittime | |
Check center codes : https://travel.state.gov/etc/designs/travel/TSGglobal_libs/data/PostsVWT.js | |
To allow SMTP client to authenticate and send email allow less secure here https://myaccount.google.com/lesssecureapps | |
configure here for center and type of visa | |
''' | |
centerId = 'P48' | |
presentSlot = '02/12/19' #dd/mm/yy | |
gmailId = '[email protected]' | |
gmailPassword = 'XXXXXXXX' | |
purpose = 'visitor' # visitor/student/other | |
import requests | |
import datetime | |
import smtplib | |
TYPE_INDEX_REL = { | |
'visitor': 0, | |
'student': 1, | |
'other': 2 | |
} | |
def get_days(content): | |
content = content.decode("utf-8").replace(',','') | |
days = content.split(' Days') | |
return int(days[TYPE_INDEX_REL[purpose]]) | |
def get_present_wait_time(): | |
present_date_obj = datetime.datetime.strptime(presentSlot, '%d/%m/%y') | |
delta = present_date_obj - datetime.datetime.now() | |
return delta.days | |
def send_alert(): | |
s = smtplib.SMTP('smtp.gmail.com', 587) | |
s.starttls() | |
s.login(gmailId, gmailPassword) | |
message = "New Visa Slot available after %d days " % (new_wait_time) | |
s.sendmail(gmailId, gmailId, message) | |
print('trying to send email') | |
s.quit() | |
wait_time_api = 'https://travel.state.gov/content/travel/resources/database/database.getVisaWaitTimes.html?cid={cid}&aid=VisaWaitTimesHomePage'.format(cid=centerId) | |
r = requests.get(wait_time_api) | |
new_wait_time = get_days(r.content.strip()) | |
present_wait_time = get_present_wait_time() | |
print('Present wait time : ', present_wait_time) | |
print('New wait time : ', new_wait_time) | |
if new_wait_time<present_wait_time: | |
send_alert() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment