Created
June 4, 2020 15:46
-
-
Save grant-h/68f04a9aa18ea6838ad49b687bf818b9 to your computer and use it in GitHub Desktop.
Watch Black Hat's session API for changes.
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 | |
""" | |
BlackHat USA session watcher | |
by Grant Hernandez. | |
Monitor sessions (briefings) to see when new ones are added. | |
Tested: Thu Jun 4 11:41:59 EDT 2020 | |
""" | |
import requests | |
import time | |
import subprocess | |
import json | |
import os | |
from datetime import datetime | |
def get_sessions(): | |
res = requests.get('https://www.blackhat.com/us-20/briefings/schedule/sessions.json') | |
return res.json() | |
def notify(text): | |
# add some notifcation thing here | |
#subprocess.call(["say", text]) # for macOS | |
pass | |
def check_session(sdata): | |
title = sdata["title"] | |
ltitle = title.lower() | |
# add some parameters to check if YOUR briefing was accepted | |
if False: | |
while True: | |
print("\aACCEPTED!") | |
notify("Accepted") | |
time.sleep(5) | |
if os.access("watch.state", os.R_OK): | |
with open("watch.state") as fp: | |
last_data = json.load(fp) | |
else: | |
last_data = get_sessions() | |
with open("watch.state", "w") as fp: | |
json.dump(last_data, fp) | |
print("%s: Got %d initial briefings" % (datetime.now(), len(last_data["sessions"]))) | |
for sid, v in last_data["sessions"].items(): | |
print("%s: %s" % (v["published_date"], v["title"])) | |
check_session(v) | |
print("Watching for new sessions...") | |
while True: | |
try: | |
data = get_sessions() | |
except requests.exceptions.ConnectionError: | |
print("Connection error. Trying again later") | |
time.sleep(60) | |
continue | |
if last_data: | |
last_sessions = last_data["sessions"] | |
sessions = data["sessions"] | |
sessions_now = set(sessions.keys()) | |
sessions_before = set(last_sessions.keys()) | |
if len(sessions_now) != len(sessions_before): | |
with open("watch.state", "w") as fp: | |
json.dump(data, fp) | |
new_sessions = sessions_now - sessions_before | |
print("\a%d NEW SESSIONS!" % (len(new_sessions))) | |
notify("%d new sessions!" % len(new_sessions)) | |
for sid in new_sessions: | |
sdata = sessions[sid] | |
title = sdata["title"] | |
ltitle = title.lower() | |
print("%s: NEW SESSION: %s" % (datetime.now(), title)) | |
check_session(sdata) | |
last_data = data | |
time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment