Skip to content

Instantly share code, notes, and snippets.

@blueset
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blueset/6ed86cfde367729078c1 to your computer and use it in GitHub Desktop.
Save blueset/6ed86cfde367729078c1 to your computer and use it in GitHub Desktop.
AJINC Attendance checker

AJINC Attendance checker

This is an attendance checker dedicated to AJINC. When running it, it sends a notice to your Pushbullet account with your attendance status of the day.

Recommended usage

It is recommended to run this script as a corn job every work day at around 0930, as your attendance is most likely confirmed by then.

Suggested cronjob line:

30 9 * * 1-5 python3 /path/to/script/ajinc_attendance.py

Requirement

  • A server supports scheduled tasks and with internet connection
  • Python 3 with requests and beautifulsoup4 packages
  • A mobile device with a working Pushbullet App

Install the above mentioned packages

pip3 install requests beautifulsoup4

How to use it

  1. Replace username and password with your own one.
  2. Obtain PushBullet Access Token from your setting page, and paste it into pushbullet_auth_code.
  3. Save the script, upload it and set up scheduled task on your server
  4. Enjoy your notifications

License

Copyright (c) 2015 Eana Hufwe

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import requests
from bs4 import BeautifulSoup
from datetime import date
import base64
import json
username = 'S1234567A'
password = 'Here goes the password'
pushbullet_auth_code = 'code'
s = requests.Session()
r = s.get("http://ajinc.wizlearn.com/ajinc")
sp = BeautifulSoup(r.text)
inputs = sp.find_all('input')
payload = {
'Login1$UserName': username,
'Login1$Password': password,
'Login1$LoginButton': 'Log In',
'__EVENTTARGET': '',
'__EVENTARGUMENT': '',
'PasswordRecovery1$UserNameContainerID$UserName': '',
}
for item in inputs:
if ("value" in item.attrs and item['name'].startswith('__')):
payload[item['name']] = item['value']
login = s.post('http://ajinc.wizlearn.com/AjInc/login.aspx', data=payload)
attendance = s.get('http://ajinc.wizlearn.com/ajinc/Student/Attendance/default.aspx')
at = BeautifulSoup(attendance.text)
atsp = at.find(id='ctl00_ContentArea_tblAttendance')
status = atsp.find_all('tr')[date.today().month].find_all('td')[date.today().day]['title']
formatted_today = date.today().strftime("%a, %d %b")
push_title = "Your attendance today is " + status + "."
push_text = "Your attendance on " + formatted_today + " is " + status + "\n" + \
base64.b85decode("W^!+BAVEq=PD3C;baZ8IWMOV&WgtUnWn*h)av&`rLTq(qb7gcOQ*?D?X>TBCbaZe!FE24cGBYk?Z*2").decode('ascii')
push_headers={
"Content-Type": "application/json",
"Authorization": "Bearer "+pushbullet_auth_code,
}
push_payload = {
"type": "link",
"title": push_title,
"body": push_text,
"url": base64.a85decode('BQS?83\\N-@@59Vk@rH2').decode('ascii')
}
push_payload_json = json.dumps(push_payload)
requests.post("https://api.pushbullet.com/v2/pushes", data=push_payload_json, headers=push_headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment