-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Senior-Capstone-2024/mihaisiia-report-gen
add report generator script
- Loading branch information
Showing
5 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"content": "\n Vivamus aliquam, enim in tincidunt varius, quam libero eleifend ante, ac elementum enim tortor quis est. Aliquam non ornare ligula. Cras eu faucibus ante. Nullam ut auctor est. Vestibulum et dui facilisis, fermentum elit ullamcorper, fringilla magna. Mauris metus mi, rhoncus vitae dui eu, tempor mattis quam. Suspendisse sed sapien vitae leo iaculis mattis. Integer bibendum venenatis ipsum. Donec sed elit sit amet turpis eleifend tincidunt. Etiam consequat lobortis lacus.\n\n Proin quis blandit enim, eget scelerisque magna. In porttitor aliquet magna ut mollis. Etiam eu tempus odio, eget varius augue. Morbi sit amet purus id orci elementum ultrices ut at nunc. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Fusce eget lacus a risus congue blandit nec sit amet enim. Sed vitae laoreet sapien, gravida semper massa. Etiam malesuada ante placerat, blandit nulla id, imperdiet lorem. Integer ut molestie est. In hac habitasse platea dictumst. In dapibus viverra odio in cursus. Aenean eu ex eu enim ultrices feugiat. Fusce consectetur, arcu at tempor mollis, nulla sem tincidunt risus, ut congue purus augue sit amet tellus. Donec tincidunt tellus ante, porta faucibus justo accumsan vel. Sed venenatis bibendum ipsum et dapibus. In scelerisque et magna et pretium.\n\n Quisque ac odio eget justo imperdiet ultricies. Mauris id diam vel purus mollis blandit quis ut odio. Etiam lacinia vestibulum tellus, at convallis augue viverra eu. Nulla pellentesque id urna vel pretium. In venenatis eros enim, vitae porttitor augue pulvinar non. Donec eros tortor, pharetra non libero in, suscipit dictum arcu. Ut ac tristique lacus. Nam non quam sed mi placerat imperdiet eu vitae nulla. Cras et ex sapien. Aliquam non turpis porttitor, posuere est vitae, porta tellus. Suspendisse at sapien sed magna ultrices euismod eget at risus. Pellentesque vulputate sem massa, vel tristique ligula commodo mattis. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum sit amet convallis sapien, at mollis felis. Integer at sem felis. Sed orci ante, egestas nec posuere vitae, venenatis non lorem.\n\n Donec vel sem velit. Vivamus pellentesque bibendum justo, quis pharetra dui fringilla sed. Cras eu leo quis turpis finibus lobortis et a lectus. Maecenas iaculis facilisis dolor, ac porta ante convallis id. Ut sed lorem dignissim, gravida lacus et, consectetur turpis. Cras sed varius ante, nec faucibus ligula. Cras id elementum ligula. Etiam ac orci vitae mi dapibus maximus. Suspendisse a justo sed dolor mollis dignissim. Nunc elit massa, vulputate quis nulla vitae, finibus sodales justo. Vestibulum dignissim placerat nulla, lobortis rhoncus purus rutrum sed." | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
|
||
class Assignment(): | ||
def __init__(self, | ||
student_name='Test Student', | ||
assignment_name='Test Assignment', | ||
class_name='Test Class', | ||
professor_name='Test Professor'): | ||
self.student_name = student_name | ||
self.assignment_name = assignment_name | ||
self.class_name = class_name | ||
self.professor_name = professor_name |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
''' | ||
call with "python3 report_generator/main.py assemble_pdf path/to/json" | ||
''' | ||
from dotenv import load_dotenv | ||
from pylatex import Document, Section, LineBreak, NewPage, PageStyle, Package | ||
from pylatex.utils import bold, NoEscape | ||
|
||
import os | ||
from os import join, dirname | ||
import sys | ||
|
||
from util.parse_json import json_to_dict | ||
# from classes.Assignment import Assignment | ||
|
||
def format_doc(): | ||
|
||
geometry_options = { | ||
'margin': '0.5in' | ||
} | ||
|
||
doc = Document(geometry_options=geometry_options) | ||
doc.change_document_style('empty') | ||
return doc | ||
|
||
def assemble_pdf(data: dict): | ||
print(data) | ||
if (isinstance(data, dict) is False): | ||
data = json_to_dict(data) | ||
|
||
# load path to pdflatex | ||
dotenv_path = join(dirname(__file__), '.env') | ||
load_dotenv(dotenv_path) | ||
PDFLATEX_PATH = os.environ.get('PDFLATEX_PATH') | ||
|
||
doc = format_doc() | ||
|
||
keys = list(data.keys()) | ||
with doc.create(Section(NoEscape(r'\centerline{' + keys[0] + '}'), numbering=False)): | ||
for key in keys: | ||
doc.append(data.get(key)) | ||
|
||
doc.append(NewPage()) | ||
|
||
doc.generate_pdf('out/out', clean_tex=False, compiler=PDFLATEX_PATH) | ||
# doc = format_doc() | ||
# doc.append(NewPage()) | ||
# doc.generate_pdf('out/out', clean_tex=False, compiler='pdflatex', silent=False) | ||
|
||
if __name__ == '__main__': | ||
globals()[sys.argv[1]](sys.argv[2]) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import json | ||
import sys | ||
|
||
def json_to_dict(x: str) -> dict : | ||
data : dict | ||
if (x[-5::] == '.json'): # checking if file extension is json | ||
f = open(x, 'r') | ||
data = json.load(f) | ||
f.close() | ||
else: | ||
data = json.load(x) | ||
|
||
return data | ||
|
||
if __name__ == '__main__': | ||
globals()[sys.argv[1]](sys.argv[2]) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from setuptools import find_packages, setup | ||
|
||
setup( | ||
name='report_generator', | ||
packages=find_packages(include=['report_generator']), | ||
version='0.0.1', | ||
description='Generate pdfs from graded student assignments', | ||
author='Mihai Siia', | ||
install_requires=['pylatex==1.4.2', | ||
'python-dotenv==1.0.1'], | ||
) |