ubccsss / ubccsss.org

Website for the UBC CSSS
https://ubccsss.org/
MIT License
14 stars 46 forks source link

Add first batch of 2024 officers #647

Closed kewbish closed 1 month ago

kewbish commented 1 month ago

This PR adds the first batch of 2024 officers.

Script for reference:

from collections import defaultdict
from datetime import datetime
import gdown
import subprocess

with open("form_responses.csv", "r") as x:
    lines = x.readlines()
    lines = [l.strip().split(",") for l in lines[1:]]

year = 2024

result = f"""---
title: Current Officers—{year}–{year+1}
date: {datetime.now().strftime("%Y-%m-%d")}
aliases:
  - /club/about/officers
---"""

officers = defaultdict(list)

for line in lines:
    if line[-1] == "-":
        continue
    name = line[2]
    if name == "":
        name = line[1]
    filename_without_extension = line[1].replace(" ", "_").lower() + f"_{year}"

    find_cmd = subprocess.run(["find", "img"], capture_output=True, check=True)
    grep_cmd = subprocess.run(
        ["grep", filename_without_extension], input=find_cmd.stdout, capture_output=True
    )
    files = grep_cmd.stdout.decode().strip().split("\n")
    if len(files) > 0 and files[0] != "":
        filename = files[0].replace("img/", "")
    else:
        gdown.download(line[6], filename_without_extension, fuzzy=True)
        filetype_cmd = subprocess.run(
            ["file", "--mime-type", filename_without_extension], stdout=subprocess.PIPE
        )
        file_type = filetype_cmd.stdout.decode().split()[-1]
        if "jpeg" in file_type:
            filename = filename_without_extension + ".jpg"
        elif "png" in file_type:
            filename = filename_without_extension + ".png"
        else:
            print("Manually resolve:", filename_without_extension)
            filename = filename_without_extension
        subprocess.run(["mv", filename_without_extension, "img/" + filename])
    officers[line[-1]].append(
        f'{{{{<officers "{name}" "{line[-1]}" "images/officers/{filename}">}}}}'
    )

for officer_type in sorted(officers.keys()):
    result += f"\n\n<br/>\n\n## {officer_type + 's'}\n"
    result += "\n<br/>\n\n"
    result += "\n\n---\n\n".join(officers[officer_type])

with open(f"{year}.md", "w") as x:
    x.write(result)

Instructions: