-
Notifications
You must be signed in to change notification settings - Fork 2
/
calcheck.py
37 lines (31 loc) · 1.34 KB
/
calcheck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sys
import requests
# Disable all warnings from urllib3
requests.packages.urllib3.disable_warnings()
def verify_email(email):
"""Verify the given email address."""
# Replace *** in the URL with the email address
url = f"https://calendar.google.com/calendar/ical/{email}/public/basic.ics"
try:
# Make an HTTP call to the URL without SSL certificate verification
response = requests.get(url, verify=False)
# Check the response headers for the presence of the "x-frame-options: SAMEORIGIN" string
if 'x-frame-options' in response.headers and response.headers['x-frame-options'].upper() == 'SAMEORIGIN':
# Append an asterisk if the HTTP response code is 200
asterisk = " *" if response.status_code == 200 else ""
print(f"{email}{asterisk}")
# If the header is not present, nothing is printed
except requests.exceptions.RequestException as e:
print(f"An error occurred with {email}: {e}")
def main():
if len(sys.argv) > 1:
# If there are command-line arguments, verify each email address
for email in sys.argv[1:]:
verify_email(email.strip())
else:
# Otherwise, read from sys.stdin
for line in sys.stdin:
email = line.strip()
verify_email(email)
if __name__ == "__main__":
main()