Skip to content

Commit

Permalink
add create duplicate flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nimarion committed May 22, 2024
1 parent 02d4315 commit 74d9fe5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Binary file removed data.xlsx
Binary file not shown.
18 changes: 14 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import argparse
import pandas as pd
from bib import main as bib_generator
from bib import generate_image
from PIL import Image
import io

if __name__ == "__main__":
argparse = argparse.ArgumentParser(
Expand All @@ -13,18 +15,19 @@
argparse.add_argument('--font', '-F', help='Font file name', required=True)
argparse.add_argument(
'--footer', '-he', help='Footer file name', default="rehlingen.png", required=False)
argparse.add_argument(
'--create-duplicate', '-D', help='Create the same image two times with suffix', default=False, required=False, action='store_true')

args = argparse.parse_args()

data_file = args.data
output_folder = args.output
font_file = args.font
footer_file = args.footer
create_duplicate = args.create_duplicate

df = pd.read_csv(data_file, sep=args.seperator)

df = df.drop_duplicates()

for index, row in df.iterrows():

firstname = str(row['firstname'])
Expand All @@ -40,4 +43,11 @@
header_file = row['header']
output_file = output_folder + "/" + lastname + "_" + firstname + ".png"
print("Generating image", text, header_file, footer_file, font_file)
bib_generator(text, output_file, header_file, footer_file, font_file)
bytes = generate_image(text, header_file, footer_file, font_file)
image=Image.open(io.BytesIO(bytes))
if(create_duplicate == True):
image.save(output_file.replace(".png", "_1.png"))
image.save(output_file.replace(".png", "_2.png"))
else:
image.save(output_file)

6 changes: 1 addition & 5 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from fastapi import FastAPI, Response, HTTPException
from typing import Optional
from os import walk
from fastapi.staticfiles import StaticFiles
from bib import generate_image
Expand All @@ -13,6 +12,7 @@

app.mount("/" + header_folder, StaticFiles(directory="header"), name="header")
app.mount("/" + footer_folder, StaticFiles(directory="footer"), name="footer")
app.mount("/" + font_folder, StaticFiles(directory="font"), name="font")


def headers():
Expand Down Expand Up @@ -55,17 +55,13 @@ def generate_bib(
header: str,
footer: str,
font: str,
header_offset: Optional[int] = 60,
):
print("hi")
if header not in headers():
raise HTTPException(status_code=404, detail="Header not found")
if footer not in footers():
raise HTTPException(status_code=404, detail="Footer not found")
print(font)
if font not in fonts():
raise HTTPException(status_code=404, detail="Font not found")
print("hi")
image = generate_image(text, header_folder + "/" + header, footer_folder + "/" + footer,
font_folder + "/" + font)
return Response(content=image, media_type="image/png", headers={"Content-Disposition": "filename=" + text + ".png"})
Expand Down

0 comments on commit 74d9fe5

Please sign in to comment.