Skip to content

Instantly share code, notes, and snippets.

@Steve-Tech
Last active August 13, 2021 07:59
Show Gist options
  • Save Steve-Tech/89a41764e1baaacd1b15456d18884d25 to your computer and use it in GitHub Desktop.
Save Steve-Tech/89a41764e1baaacd1b15456d18884d25 to your computer and use it in GitHub Desktop.
Python TASS Scraper
import requests
class TASS:
def __init__(self, baseurl):
self.baseurl = baseurl
self.session = requests.Session()
def login(self, username, password):
url = self.baseurl + "remote-json.cfm?do=ui.web.user.loginAttempt"
setup_data = {'intent': 'setup', 'required': '', 'viewstate': 'add', 'username': '', 'username_previous': '', 'password': '', 'password_previous': '', 'redirect': 'true', 'redirect_previous': 'true', 'captcha': '', 'captcha_previous': '', 'go': '', 'go_previous': '', 'id': '', 'id_previous': '', '__target': '', '__base': '', '__token': ''}
setup = self.session.post(url, data = setup_data)
login_data = {'intent': 'save', 'required': 'username%2Cpassword', 'viewstate': 'add', 'username': username, 'username_previous': '', 'password': password, 'password_previous': '', 'redirect': 'true', 'redirect_previous': 'true', 'captcha': '', 'captcha_previous': '', 'go': '', 'go_previous': '', 'id': '', 'id_previous': '', '__target': '', '__base': '', '__token': setup.json()['__token']}
login = self.session.post(url, data = login_data)
assert login.json()['__status'] == 'success', "Login Failed"
def timetable(self):
timetable = self.session.post(self.baseurl + "remote-json.cfm?do=studentportal.timetable.main.fullTimetable.grid")
return timetable.json()
def timetable_day(self, **kwargs):
timetable_url = self.baseurl + "remote-json.cfm?do=studentportal.timetable.main.todaysTimetable.grid"
timetable = self.session.post(timetable_url, data={'start': kwargs.get('date', '')})
#timetable = self.session.post(timetable_url, data={'start': '2020-11-17'})
return timetable.json()
def notices(self):
notices = self.session.post(self.baseurl + "remote-json.cfm?do=studentportal.calendar.main.dailynotices.grid")
return notices.json()
from TASS_Scraper import TASS
from getpass import getpass
#url = "https://example.school/studentcafe/"
url = input("Enter URL for Student Cafe: ")
username = input("Enter Username: ")
password = getpass("Enter Password: ")
tass = TASS(url)
print("Logging in...")
tass.login(username, password)
print("Loading data...")
print("Timetable", tass.timetable())
print("Timetable Daily", tass.timetable_day())
print("Notices", tass.notices())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment