From 69cd21e4cd04a1c633a2e9b3316e72abb1276c73 Mon Sep 17 00:00:00 2001 From: encrypt Date: Mon, 9 Oct 2023 17:52:29 +0200 Subject: [PATCH] aggiunto template base --- app.py | 61 +++++++++++++++++++++++ static/flyers/simple/paper.css | 51 ++++++++++++++++++++ static/flyers/simple/style.css | 88 ++++++++++++++++++++++++++++++++++ templates/flyers/simple.html | 40 ++++++++++++++++ templates/index.html | 16 +++++++ 5 files changed, 256 insertions(+) create mode 100755 app.py create mode 100644 static/flyers/simple/paper.css create mode 100644 static/flyers/simple/style.css create mode 100644 templates/flyers/simple.html create mode 100644 templates/index.html diff --git a/app.py b/app.py new file mode 100755 index 0000000..1c1baa0 --- /dev/null +++ b/app.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +import requests +import json +import datetime +from jinja2 import Environment, FileSystemLoader +from flask import Flask +from flask import render_template, request + +app = Flask(__name__) + +gancio_instance = 'balotta.org' +template_name = 'simple' +events_ep = f'https://{gancio_instance}/api/events' + +def day2giorno(day): + days = { + 'Monday': 'Lunedì', + 'Tuesday': 'Martedì', + 'Wednesday': 'Mercoledì', + 'Thursday': 'Giovedì', + 'Friday': 'Venerdì', + 'Saturday': 'Sabato', + 'Sunday': 'Domenica' + } + if day in days: + return days[day] + +def fetch_events(api_endpoint): + events = requests.get(events_ep).json() + for event in events: + start_dt = datetime.datetime.fromtimestamp(event['start_datetime']) + start_day = f"{day2giorno(start_dt.strftime('%A'))} {start_dt.strftime('%d')}" + start_hour = start_dt.strftime("%H:%M") + when = f"{start_day} dalle {start_hour}" + if event['end_datetime']: + end_dt = datetime.datetime.fromtimestamp(event['end_datetime']) + end_day = f"{day2giorno(start_dt.strftime('%A'))} {end_dt.strftime('%d')}" + end_hour = end_dt.strftime("%H:%M") + if event['multidate']: + when = f"da {when} a {end_day}" + when += " alle " + when += end_hour + event['when'] = when + event['media'][0]['thumbnailPosition'] = f"{(event['media'][0]['focalpoint'][0] + 1) * 50}% {(event['media'][0]['focalpoint'][1] + 1) * 50}%" + return events + +@app.route("/") +def main(): + events = fetch_events(events_ep) + return render_template('index.html', events=events) + + +@app.route("/flyer") +def flyer(): + relevant_events = request.args.getlist('events', type=int) + events = fetch_events(events_ep) + events = [ e for e in events if e['id'] in relevant_events ] + return render_template(f'flyers/{template_name}.html', events=events) + + diff --git a/static/flyers/simple/paper.css b/static/flyers/simple/paper.css new file mode 100644 index 0000000..c26473c --- /dev/null +++ b/static/flyers/simple/paper.css @@ -0,0 +1,51 @@ +@page { + margin: 0; +} +body { + margin: 0; + overflow: hidden; + position: relative; + box-sizing: border-box; + page-break-after: always; +} + +body.A3 { + width: 297mm; + height: 420mm; +} +body.A3.landscape .sheet { + width: 420mm; + height: 297mm; +} +body.A4 .sheet { + width: 210mm; + height: 297mm; +} +body.A4.landscape .sheet { + width: 297mm; + height: 210mm; +} +body.A5 .sheet { + width: 148mm; + height: 210mm; +} +body.A5.landscape .sheet { + width: 210mm; + height: 148mm; +} +body.letter .sheet { + width: 216mm; + height: 280mm; +} +body.letter.landscape .sheet { + width: 280mm; + height: 216mm; +} +body.legal .sheet { + width: 216mm; + height: 357mm; +} +body.legal.landscape .sheet { + width: 357mm; + height: 216mm; +} diff --git a/static/flyers/simple/style.css b/static/flyers/simple/style.css new file mode 100644 index 0000000..9d12ab2 --- /dev/null +++ b/static/flyers/simple/style.css @@ -0,0 +1,88 @@ +body { + border: 1px solid yellow; + font: 18px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"; + color: #c9d1d9; + background: #0d1117; +} + +.event { + background-color: #1e1e1e; + border-radius: 5mm 5mm 0 0; +} + +.event_info > h3.title { + margin-top: 2mm; + margin-left: 3mm; +} + +.intestazione { + border: 1px solid black; + height: 10%; + width: 90%; +} + +.titolo > h1 { + font-size: 35mm; + margin-top: -22px; +} + +.subtitle { + margin-top: -50px; +} + +.event { + border: 1px solid black; +o} + +.center { + display: flex; + flex-direction: column; + align-items: center; +} + +#events { + width: 99%; + height: 90%; + display: grid; + grid-template-columns: auto auto auto; + grid-gap: 1em; + border: 1px dotted black; +} + +.event_info svg { + height: 24px; + width: 24px; + fill: white; + margin-right: 0.2em; +} + +.location { + display: grid; + grid-template-columns: auto auto; + justify-content: start; +} +.place_name { + color: #ff6e40; +} + +.flyer { + width: 100%; + object-fit: cover; + max-height: 50mm; +} + +h1,h2,h3 { + line-height: 1.2; +} + +h1 { + margin: 0 0 .2em; + color: #ff6e40; +} + +h3 { + margin-top: 0; + margin-bottom: .2em; + color: #ff6e40; +} + diff --git a/templates/flyers/simple.html b/templates/flyers/simple.html new file mode 100644 index 0000000..590e5a0 --- /dev/null +++ b/templates/flyers/simple.html @@ -0,0 +1,40 @@ + + + + + Balotta - sito in manutenzione + + + + + + + +
+
+

Balotta

+
Agenda condivisa per Bologna
+
+
+ +
+ {% for event in events %} +
+
+

{{ event.title }}

+
{{ event.when }}
+
+
+ {{ event.place.name }} +
+
+
+
+ +
+
+ {% endfor %} +
+ + diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..6353a8d --- /dev/null +++ b/templates/index.html @@ -0,0 +1,16 @@ + +Generatore di volantini +

Generatore di volantini per balotta.org

+
+Scegli gli eventi che vuoi mettere nel volantino e premi genera. +Per stampare fai "File >> Stampa" Scegli come destinazione "Salva come PDF" e seleziona il giusto formato di carta (A3). +
+
+ +
+{% for event in events %} + +
+{% endfor %} + +