An open API service indexing awesome lists of open source software.

https://github.com/muhammadrafayasif/labs-to-pdf

A python script that compiles and executes lab programs, captures results, and generates formatted PDF reports ready for submission.
https://github.com/muhammadrafayasif/labs-to-pdf

assignments automation python3 script

Last synced: 3 months ago
JSON representation

A python script that compiles and executes lab programs, captures results, and generates formatted PDF reports ready for submission.

Awesome Lists containing this project

README

          

# 🧾 Automated Lab Report Generator (Python + ReportLab)

This project automatically compiles, runs, and generates PDF lab reports for programming labs.
It handles everything β€” from compiling C++ files to capturing output and formatting it into a professional, university-style PDF with your name, roll number, and department.

---

## πŸ“Έ Sample Output

The generated PDF includes:

- University logo and title page
- Each lab question’s source code
- Automatically captured program output (styled like a terminal)
- Execution time for each task
- Automatic date and metadata

Example PDF: [CT-24000.pdf](/Lab%201/CT-24000_Lab1.pdf)

---

## βš™οΈ Features

- βœ… Automatic Compilation β€” Uses `g++` to compile each `.cpp` file
- πŸ“€ Output Capture β€” Captures console output and formats it like a terminal
- πŸ–‹οΈ Beautiful PDF Generation β€” Uses ReportLab for clean, styled reports
- πŸ§‘β€πŸŽ“ Customizable Branding β€” Add your own logo, name, roll number, department, and degree
- πŸ“‚ Multi-Lab Support β€” Process multiple folders like `"Lab 1"`, `"Lab 2"`, etc.
- ⏱️ Execution Timing β€” Displays how long each program took to run
- πŸ› οΈ Error Handling β€” Gracefully reports compilation or runtime errors

---

## πŸ—‚οΈ Project Structure

```bash
πŸ“¦ labs-to-pdf/
β”‚
β”œβ”€β”€ Lab 1/
β”‚ β”œβ”€β”€ 1.cpp
β”‚ β”œβ”€β”€ 2.cpp
β”‚ └── ...
β”‚
β”œβ”€β”€ logo.png # University logo for the title page
β”œβ”€β”€ make_pdfs.py # Main automation script
└── README.md
```

---

## 🧰 Requirements

You’ll need:

* Python 3.8+
* A C++ compiler (e.g., `g++`)
* ReportLab for PDF generation

Install dependencies with:

```bash
pip install reportlab
```

---

## πŸ§‘β€πŸ’» Usage

1. Place your files inside folders like `Lab 1`, `Lab 2`, etc.
2. Update configuration at the top of `make_pdfs.py`:

```python
EXTENSION = "cpp"
LOGO_PATH = "./logo.png"
PROCESS = ["Lab 1"] # Folder names, must match exactly
KEEP_TOGETHER = True # Skip to next page if the question starts at the end of page
KEEP_EXE = False # Remove or keep the .exe file generated automatically

""" Enter the user inputs for each lab in the following order:
INPUTS = [
[Q1 INPUTS, Q2 INPUTS, Q3 INPUTS, ...], # For Lab 1 (According to the first lab provided in the PROCESS list)
[Q1 INPUTS, Q2 INPUTS, Q3 INPUTS, ...], # For Lab 2 (According to the second lab provided in the PROCESS list)
...
]

For example, If Q2 does not take input, leave it as an empty string
["2 2", "", "1 4"]
"""
INPUTS = [

]

""" The QUESTIONS list follows the same format as the INPUT list provided above """
QUESTIONS = [

]

EXECUTION_TIMEOUT = 5 # seconds

UNIVERSITY = "NED University of Engineering and Technology"
NAME = "NAME"
ROLL_NO = "CT-24000"
DEPARTMENT = "Department of Computer Science and Information Technology"
DEGREE = "Bachelor of Science (BS)"
```

3. Run the generator:

```bash
python make_pdfs.py
```

4. PDFs will be generated inside each lab folder individually.

---

## 🧠 Tips

* A custom font can be used, simply replace `font.ttf` with another font of your choice.
* Ensure your files compile cleanly and produce output.
* Customize fonts, colors, and layout by editing the paragraph and table styles in the script.
* Adjust the `EXECUTION_TIMEOUT` constant in the script if your programs take longer to run.

---

## πŸͺͺ License

This project is released under the [MIT License](LICENSE).

Feel free to modify and adapt it for your institution or personal use.

---