This project is a backend service built with FastAPI that provides web scraping functionality for PSG Connect. It offers a RESTful API for clients to fetch student data from the PSG Tech website.
- Web scraping API endpoint
- Student profile, attendance, exam results, and CA marks retrieval
- Error handling for various scenarios
- CORS middleware for cross-origin requests
- Python 3.7+
- FastAPI
- Uvicorn (ASGI server)
- Pydantic
- Custom scraping module (
dataFetchFunctions
)
-
Clone the repository:
git clone https://github.com/yourusername/psg-connect-backend.git cd psg-connect-backend
-
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
Run the FastAPI server:
uvicorn main:app --reload
The API will be available at http://localhost:8000
. You can access the interactive API documentation at http://localhost:8000/docs
.
GET /
: Welcome messageGET /online
: Check if the service is onlinePOST /fetch_data
: Fetch student data (requires username and password)
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
import uvicorn
from dataFetchFunctions import CAMarksWebScrapper
from dataExceptions import InvalidUsernameOrPasswordException, ScrappingError, NoSemResultsAvailable, NoCAMarksAvailable, AttendanceUpdateInProcessException, NoTimeTableDataException
app = FastAPI()
# CORS middleware configuration
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class Credentials(BaseModel):
username: str
password: str
# API endpoints implementation
# ...
This project is designed to be deployed using a Heroku-style Procfile. Make sure to configure your deployment environment accordingly.
The backend handles various exceptions:
- Invalid username or password
- Scraping errors
- No semester results available
- No CA marks available
- Attendance update in process
- No timetable data available
- Fork the repository
- Create your feature branch:
git checkout -b feature/my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin feature/my-new-feature
- Submit a pull request