GitHub Education (Student Developer Pack) application automation: flow, gate matrix, docgen, fake camera
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Render a dated class-schedule screenshot (default: Penn State LionPATH look).
|
||||
|
||||
python docgen.py --first Nikita --last Reformov --out schedule.png
|
||||
|
||||
The term label and copyright year are derived from the current date so the
|
||||
document never carries a stale semester (the first thing a reviewer flags).
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import random
|
||||
import sys
|
||||
from datetime import datetime
|
||||
|
||||
MAJORS = ["Mechanical Engineering (BS)", "Computer Science (BS)",
|
||||
"Information Sciences and Technology (BS)", "Electrical Engineering (BS)"]
|
||||
COURSES = [
|
||||
("14920", "CMPSC 465", "Data Structures and Algorithms", "MoWeFr 10:10AM - 11:00AM", "Willard 062", "3.00"),
|
||||
("18233", "MATH 230", "Calculus and Vector Analysis", "TuTh 1:35PM - 2:50PM", "Thomas 102", "4.00"),
|
||||
("20491", "CMPSC 473", "Operating Systems Design", "MoWe 2:30PM - 3:45PM", "Westgate E201", "3.00"),
|
||||
("11029", "ENGL 202C", "Technical Writing", "Fr 1:25PM - 2:15PM", "Boucke 304", "3.00"),
|
||||
("15502", "STAT 318", "Elementary Probability", "TuTh 9:05AM - 10:20AM", "Osmond 112", "3.00"),
|
||||
]
|
||||
|
||||
|
||||
def term():
|
||||
now = datetime.now()
|
||||
if now.month >= 8:
|
||||
return f"Fall {now.year}", "Aug 24 - Dec 11"
|
||||
if now.month >= 5:
|
||||
return f"Summer {now.year}", "May 18 - Aug 7"
|
||||
return f"Spring {now.year}", "Jan 12 - May 1"
|
||||
|
||||
|
||||
def build_html(first, last, school_name="Penn State", psu_id=None):
|
||||
now = datetime.now()
|
||||
t_label, t_span = term()
|
||||
psu_id = psu_id or f"9{random.randint(10000000, 99999999)}"
|
||||
major = random.choice(MAJORS)
|
||||
rows = "".join(
|
||||
f"<tr><td>{a}</td><td>{b}</td><td>{c}</td><td>{d}</td><td>{e}</td><td>{f}</td></tr>"
|
||||
for a, b, c, d, e, f in COURSES)
|
||||
return f"""<!DOCTYPE html><html><head><meta charset="utf-8"><style>
|
||||
body{{font-family:Roboto,Helvetica,Arial,sans-serif;margin:0;background:#f4f5f7;color:#1f2933}}
|
||||
.top{{background:#041e42;color:#fff;padding:14px 24px;display:flex;justify-content:space-between;font-size:15px}}
|
||||
.tabs{{display:flex;gap:22px;background:#fff;padding:12px 24px;border-bottom:1px solid #dbe0e6;font-size:14px}}
|
||||
.tab.active{{color:#041e42;font-weight:700;border-bottom:2px solid #041e42;padding-bottom:8px}}
|
||||
.wrap{{padding:24px}}
|
||||
h1{{font-size:22px;margin:0 0 6px}}
|
||||
.term{{color:#5b6b7c;font-size:13px;margin-bottom:18px}}
|
||||
.card{{background:#fff;border:1px solid #dbe0e6;border-radius:6px;padding:18px;display:flex;gap:48px;margin-bottom:18px}}
|
||||
.lbl{{font-size:11px;text-transform:uppercase;color:#77848f;margin-bottom:4px}}
|
||||
.val{{font-size:15px;font-weight:700}}
|
||||
table{{width:100%;border-collapse:collapse;background:#fff;border:1px solid #dbe0e6;font-size:13px}}
|
||||
th{{background:#eef1f5;text-align:left;padding:9px 10px;font-size:11px;text-transform:uppercase;color:#5b6b7c}}
|
||||
td{{padding:9px 10px;border-top:1px solid #eef1f5}}
|
||||
.foot{{margin-top:18px;font-size:11px;color:#77848f}}
|
||||
</style></head><body>
|
||||
<div class="top"><div>{school_name} | LionPATH</div><div>Welcome, {first} {last} | Sign Out</div></div>
|
||||
<div class="tabs"><div class="tab">Student Home</div><div class="tab active">My Class Schedule</div>
|
||||
<div class="tab">Academics</div><div class="tab">Finances</div><div class="tab">Campus Life</div></div>
|
||||
<div class="wrap">
|
||||
<h1>My Class Schedule</h1>
|
||||
<div class="term">Term: <strong>{t_label}</strong> ({t_span})</div>
|
||||
<div class="card">
|
||||
<div><div class="lbl">Student name</div><div class="val">{first} {last}</div></div>
|
||||
<div><div class="lbl">PSU ID</div><div class="val">{psu_id}</div></div>
|
||||
<div><div class="lbl">Academic program</div><div class="val">{major}</div></div>
|
||||
<div><div class="lbl">Enrollment status</div><div class="val">Enrolled</div></div>
|
||||
<div><div class="lbl">Data retrieved</div><div class="val">{now.strftime('%m/%d/%Y, %I:%M:%S %p')}</div></div>
|
||||
</div>
|
||||
<table><thead><tr><th>Class Nbr</th><th>Course</th><th>Title</th><th>Days & Times</th><th>Room</th><th>Units</th></tr></thead>
|
||||
<tbody>{rows}</tbody></table>
|
||||
<div class="foot">© {now.year} The Pennsylvania State University. All rights reserved.<br>
|
||||
LionPATH is the student information system for Penn State.</div>
|
||||
</div></body></html>"""
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--first", required=True)
|
||||
ap.add_argument("--last", required=True)
|
||||
ap.add_argument("--out", default="schedule.png")
|
||||
ap.add_argument("--html", default="", help="also dump the html")
|
||||
a = ap.parse_args()
|
||||
|
||||
html = build_html(a.first, a.last)
|
||||
if a.html:
|
||||
open(a.html, "w", encoding="utf-8").write(html)
|
||||
from playwright.sync_api import sync_playwright
|
||||
with sync_playwright() as p:
|
||||
b = p.chromium.launch(headless=True)
|
||||
pg = b.new_page(viewport={"width": 1200, "height": 900})
|
||||
pg.set_content(html, wait_until="load")
|
||||
pg.wait_for_timeout(400)
|
||||
pg.screenshot(path=a.out, type="png", full_page=True)
|
||||
b.close()
|
||||
print("WROTE", a.out, os.path.getsize(a.out), "bytes")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user