-
-
Save Grace-Amondi/817bc380e8fa2be2a35c2af1428d4cf4 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
FNAME='<firstname>' | |
LNAME='<lastname' | |
LEVEL='students' | |
PASSWORD= '<password>' |
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
.env |
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
#!/usr/bin/env python | |
import os | |
from os.path import join, dirname | |
from dotenv import load_dotenv | |
import mechanize | |
import ssl | |
# Create .env file path. | |
dotenv_path = join(dirname(__file__), '.env') | |
# Load file from the path. | |
load_dotenv(dotenv_path) | |
fname = os.getenv('FNAME') | |
lname = os.getenv('LNAME') | |
level = os.getenv('LEVEL') | |
username = fname + '.' + lname + '@' + level | |
password = os.getenv('PASSWORD') | |
try: | |
_create_unverified_https_context = ssl._create_unverified_context | |
except AttributeError: | |
# Legacy Python that doesn't verify HTTPS certificates by default | |
pass | |
else: | |
# Handle target environment that doesn't support HTTPS verification | |
ssl._create_default_https_context = _create_unverified_https_context | |
br = mechanize.Browser() | |
br.set_handle_robots(False) | |
name='grace' | |
if(name=='grace'): | |
br.open('https://portal.jkuat.ac.ke/') | |
def select_form(form): | |
return form.attrs.get('id', None) == 'login-form' | |
br.select_form(predicate=select_form) | |
br.form['LoginForm[username]'] = username | |
br.form['LoginForm[password]'] = password | |
br.submit() | |
response = br.response() | |
if(response.code == 200): | |
br.open('https://portal.jkuat.ac.ke/Api/evaluation') | |
successful = br.response() | |
if(successful.code== 200): | |
br.open('https://evaluation.jkuat.ac.ke/student/evaluate/start/25') | |
evaluation = br.response() | |
print evaluation.read() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment