Created
June 3, 2018 19:29
-
-
Save oszo/e2e8270a108b11dc62c526db5944cc00 to your computer and use it in GitHub Desktop.
This file contains 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
import requests | |
import urllib.request | |
import urllib.parse | |
scheduleData = [] | |
OSCP_PHPSESSID = "paste_PHPSESSID_value_here" | |
LINE_ACCESS_TOKEN = "paste_LINE_ACCESS_TOKEN_here" | |
TARGET_MONTH = "1-12-2018" | |
OSCP_URL = "https://www.offensive-security.com/exam.php?datum="+TARGET_MONTH | |
LINE_URL = "https://notify-api.line.me/api/notify" | |
def sendLineNoti(date): | |
message ="new date : " + date | |
msg = urllib.parse.urlencode({"message":message}) | |
LINE_HEADERS = {'Content-Type':'application/x-www-form-urlencoded',"Authorization":"Bearer "+LINE_ACCESS_TOKEN} | |
session = requests.Session() | |
a=session.post(LINE_URL, headers=LINE_HEADERS, data=msg) | |
def setSchedule(allow_date_data_list): | |
global scheduleData | |
tempScheduleData = [] | |
for allow_date_data in allow_date_data_list: | |
mdu, date, datum = allow_date_data.split('&') | |
mdu = mdu.split('=') | |
mdu = mdu[1] | |
date = date.split('=') | |
date = date[1] | |
tempScheduleData.append(mdu) | |
if len(scheduleData) == 0: | |
sendLineNoti(date) | |
scheduleData.append(mdu) | |
print(date, mdu) | |
elif not any(mdu == eachScheduleData for eachScheduleData in scheduleData): | |
sendLineNoti(date) | |
print(date, mdu) | |
scheduleData = tempScheduleData | |
def fetchSchedule(): | |
req = urllib.request.Request(OSCP_URL) | |
req.add_header('Cookie', 'PHPSESSID='+OSCP_PHPSESSID) | |
req.add_header('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36') | |
print('fetching...') | |
with urllib.request.urlopen(req) as response: | |
html = response.read() | |
html = html.decode('utf-8') | |
index = 0 | |
allow_date_data_list=[] | |
while index != -1: | |
index = html.find('<a href="exam.php?mdu=', index) | |
if index != -1: | |
allow_date_data = html[html.find('?', index)+1 : html.find('"', html.find('?', index))] | |
allow_date_data_list.append(allow_date_data) | |
index += 1 | |
setSchedule(allow_date_data_list) | |
while True: | |
try: | |
fetchSchedule() | |
except ValueError: | |
print(ValueError) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment