Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure handler and add black formatter #7

Merged
merged 5 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .github/workflows/black.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Lint

on: [ push, pull_request ]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: psf/black@stable
with:
options: "--check --verbose"
src: "pesuacademy"

File renamed without changes.
36 changes: 18 additions & 18 deletions .github/workflows/python-package-pip.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
name: Python Package using Pip
name: Python Package using Pip

on: [push, pull_request]
on: [ push, pull_request ]

jobs:
build-linux:
runs-on: ubuntu-latest
strategy:
max-parallel: 5
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: [ "3.9", "3.10", "3.11" ]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Lint with flake8
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
34 changes: 17 additions & 17 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name: Upload Python Package

on:
release:
types: [published]
types: [ published ]

permissions:
contents: read
Expand All @@ -21,19 +21,19 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
# PESU Academy API
# pesuacademy-py

![PyPI](https://img.shields.io/pypi/v/pesuacademy?label=pypi%20package)
![GitHub Release](https://img.shields.io/github/v/release/HackerSpace-PESU/pesuacademy-py)
![GitHub Tag](https://img.shields.io/github/v/tag/HackerSpace-PESU/pesuacademy-py)
![PyPI - Status](https://img.shields.io/pypi/status/pesuacademy)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pesuacademy)

![GitHub commit activity](https://img.shields.io/github/commit-activity/w/HackerSpace-PESU/pesuacademy-py)
![GitHub last commit](https://img.shields.io/github/last-commit/HackerSpace-PESU/pesuacademy-py)
![GitHub commits since latest release](https://img.shields.io/github/commits-since/HackerSpace-PESU/pesuacademy-py/latest)

![black.yml](https://github.com/HackerSpace-PESU/pesuacademy-py/actions/workflows/black.yml/badge.svg)
![python-package-pip.yml](https://github.com/HackerSpace-PESU/pesuacademy-py/actions/workflows/python-package-pip.yml/badge.svg)
![python-publish.yml](https://github.com/HackerSpace-PESU/pesuacademy-py/actions/workflows/python-publish.yml/badge.svg)
![build-docs.yml](https://github.com/HackerSpace-PESU/pesuacademy-py/actions/workflows/build-docs.yml/badge.svg)

Python wrapper and APIs for the PESU Academy website.

The wrapper requires the user's credentials to authenticate and provide **read-only** access to all the pages and
information accessible on the PESU Academy website. Without the credentials, the wrapper will only be able to fetch
details from the `Know Your Class and Section` page.
The wrapper provides **read-only** access to all the pages and information accessible on the PESU Academy website.
Without authentication, the wrapper will only be able to fetch details from the `Know Your Class and Section` page.

> :warning: **Warning:** This is not an official API and is not endorsed by PES University. Use at your own risk.

Expand All @@ -30,6 +44,7 @@ python setup.py install
from pesuacademy import PESUAcademy

p = PESUAcademy("PRN_or_SRN", "password")
# p = PESUAcademy() # Without authentication: can only fetch details from the `Know Your Class and Section` page
profile = p.profile()
courses = p.courses(semester=2)
attendance = p.attendance()
Expand Down
2 changes: 1 addition & 1 deletion pesuacademy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = "0.0.1"
__version__ = "0.0.2"

from .pesuacademy import PESUAcademy
2 changes: 1 addition & 1 deletion pesuacademy/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
ParentDetails,
ParentInformation,
AddressDetails,
QualifyingExamination
QualifyingExamination,
)
18 changes: 12 additions & 6 deletions pesuacademy/models/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

class Attendance:
def __init__(
self,
attended_classes: Optional[int] = None,
total_classes: Optional[int] = None,
percentage: Optional[float] = None
self,
attended_classes: Optional[int] = None,
total_classes: Optional[int] = None,
percentage: Optional[float] = None,
):
self.attended_classes = attended_classes
self.total_classes = total_classes
Expand All @@ -17,8 +17,14 @@ def __str__(self):


class Course:
def __init__(self, code: str, title: str, _type: Optional[str] = None, status: Optional[str] = None,
attendance: Optional[Attendance] = None):
def __init__(
self,
code: str,
title: str,
_type: Optional[str] = None,
status: Optional[str] = None,
attendance: Optional[Attendance] = None,
):
self.code = code
self.title = title
self.type = _type
Expand Down
78 changes: 37 additions & 41 deletions pesuacademy/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

class ClassAndSectionInfo:
def __init__(
self,
prn: str,
srn: str,
name: str,
semester: str,
section: str,
department: str,
branch: str,
institute: str,
cycle: Optional[str] = None
self,
prn: str,
srn: str,
name: str,
semester: str,
section: str,
department: str,
branch: str,
institute: str,
cycle: Optional[str] = None,
):
self.prn = prn
self.srn = srn
Expand All @@ -31,18 +31,18 @@ def __str__(self):

class PersonalDetails:
def __init__(
self,
name: str,
prn: str,
srn: str,
branch: str,
semester: str,
section: str,
program: Optional[str] = None,
email: Optional[str] = None,
mobile: Optional[str] = None,
aadhar: Optional[str] = None,
name_as_in_aadhar: Optional[str] = None
self,
name: str,
prn: str,
srn: str,
branch: str,
semester: str,
section: str,
program: Optional[str] = None,
email: Optional[str] = None,
mobile: Optional[str] = None,
aadhar: Optional[str] = None,
name_as_in_aadhar: Optional[str] = None,
):
self.name = name
self.prn = prn
Expand Down Expand Up @@ -83,14 +83,14 @@ def __str__(self):

class ParentInformation:
def __init__(
self,
name: str,
mobile: str,
email: str,
occupation: str,
qualification: str,
designation: str,
employer: str
self,
name: str,
mobile: str,
email: str,
occupation: str,
qualification: str,
designation: str,
employer: str,
):
self.name = name
self.mobile = mobile
Expand All @@ -102,11 +102,7 @@ def __init__(


class ParentDetails:
def __init__(
self,
mother: ParentInformation,
father: ParentInformation
):
def __init__(self, mother: ParentInformation, father: ParentInformation):
self.mother = mother
self.father = father

Expand All @@ -129,12 +125,12 @@ def __str__(self):

class Profile:
def __init__(
self,
personal_details: PersonalDetails,
other_information: OtherInformation,
qualifying_examination: QualifyingExamination,
parent_details: ParentDetails,
address_details: AddressDetails
self,
personal_details: PersonalDetails,
other_information: OtherInformation,
qualifying_examination: QualifyingExamination,
parent_details: ParentDetails,
address_details: AddressDetails,
):
self.personal_details = personal_details
self.other_information = other_information
Expand Down
25 changes: 17 additions & 8 deletions pesuacademy/pages/attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

class AttendancePageHandler:
@staticmethod
def get_attendance_in_semester(session: requests_html.HTMLSession, semester_value: Optional[int] = None):
def get_attendance_in_semester(
session: requests_html.HTMLSession, semester_value: Optional[int] = None
):
try:
url = "https://www.pesuacademy.com/Academy/s/studentProfilePESUAdmin"
query = {
Expand All @@ -31,26 +33,33 @@ def get_attendance_in_semester(session: requests_html.HTMLSession, semester_valu
table_body = table.find("tbody")
for row in table_body.find_all("tr"):
columns = row.find_all("td")
if len(columns) == 1 and columns[0].text.strip() == 'Data Not\n\t\t\t\t\tAvailable':
if (
len(columns) == 1
and columns[0].text.strip() == "Data Not\n\t\t\t\t\tAvailable"
):
break
course_code = columns[0].text.strip()
course_title = columns[1].text.strip()
attended_and_total_classes = columns[2].text.strip()
if '/' in attended_and_total_classes:
attended_classes, total_classes = list(map(int, attended_and_total_classes.split('/')))
if "/" in attended_and_total_classes:
attended_classes, total_classes = list(
map(int, attended_and_total_classes.split("/"))
)
else:
attended_classes, total_classes = None, None
percentage = columns[3].text.strip()
percentage = float(percentage) if percentage != "NA" else None
course = Course(course_code, course_title,
attendance=Attendance(attended_classes, total_classes, percentage))
course = Course(
course_code,
course_title,
attendance=Attendance(attended_classes, total_classes, percentage),
)
attendance.append(course)
return attendance

@staticmethod
def get_page(
session: requests_html.HTMLSession,
semester_ids: dict
session: requests_html.HTMLSession, semester_ids: dict
) -> dict[int, list[Course]]:
attendance = dict()
for semester_number in semester_ids:
Expand Down
16 changes: 11 additions & 5 deletions pesuacademy/pages/courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

class CoursesPageHandler:
@staticmethod
def get_courses_in_semester(session: requests_html.HTMLSession, semester_id: Optional[int] = None):
def get_courses_in_semester(
session: requests_html.HTMLSession, semester_id: Optional[int] = None
):
try:
url = "https://www.pesuacademy.com/Academy/s/studentProfilePESUAdmin"
query = {
Expand All @@ -31,7 +33,10 @@ def get_courses_in_semester(session: requests_html.HTMLSession, semester_id: Opt
table_body = table.find("tbody")
for row in table_body.find_all("tr"):
columns = row.find_all("td")
if len(columns) == 1 and columns[0].text.strip() == 'No\n\t\t\t\t\t\tsubjects found':
if (
len(columns) == 1
and columns[0].text.strip() == "No\n\t\t\t\t\t\tsubjects found"
):
break
course_code = columns[0].text.strip()
course_title = columns[1].text.strip()
Expand All @@ -43,12 +48,13 @@ def get_courses_in_semester(session: requests_html.HTMLSession, semester_id: Opt

@staticmethod
def get_page(
session: requests_html.HTMLSession,
semester_ids: dict
session: requests_html.HTMLSession, semester_ids: dict
) -> dict[int, list[Course]]:
courses = dict()
for semester_number in semester_ids:
courses_in_semester = CoursesPageHandler.get_courses_in_semester(session, semester_ids[semester_number])
courses_in_semester = CoursesPageHandler.get_courses_in_semester(
session, semester_ids[semester_number]
)
courses[semester_number] = courses_in_semester
courses = dict(sorted(courses.items()))
return courses
Loading
Loading