Browse Source

aggiunto template base

encrypt 11 months ago
commit
69cd21e4cd
5 changed files with 256 additions and 0 deletions
  1. 61 0
      app.py
  2. 51 0
      static/flyers/simple/paper.css
  3. 88 0
      static/flyers/simple/style.css
  4. 40 0
      templates/flyers/simple.html
  5. 16 0
      templates/index.html

+ 61 - 0
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)
+    
+    

+ 51 - 0
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;
+}

+ 88 - 0
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;
+}
+

+ 40 - 0
templates/flyers/simple.html

@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html lang="it">
+  <head>
+    <meta charset="utf-8">
+    <title>Balotta - sito in manutenzione</title>
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <link rel="stylesheet" href="{{ url_for('static', filename='flyers/simple/style.css') }}">
+    <link rel="stylesheet" href="{{ url_for('static', filename='flyers/simple/paper.css') }} ">    
+    <link rel="icon" type="image/x-icon" href="favicon.ico">
+  </head>
+  <body class="A3 center">
+
+    <div class="intestazione">
+      <div class="titolo center">
+        <h1>Balotta</h1>
+        <div class="subtitle">Agenda condivisa per Bologna</div>
+      </div>
+    </div>
+
+    <div id="events">
+    {% for event in events %}
+       <div class="event">
+      	<div class="event_info">
+          <h3 class="title">{{ event.title }}</h3>
+          <div class="flex"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" role="img" aria-hidden="true" class="v-icon__svg"><path d="M19,19H5V8H19M16,1V3H8V1H6V3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3H18V1M17,12H12V17H17V12Z"></path></svg><span class="time">{{ event.when }}</span></div>
+          <div class="location">
+            <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" role="img" aria-hidden="true" class="v-icon__svg"><path d="M12,11.5A2.5,2.5 0 0,1 9.5,9A2.5,2.5 0 0,1 12,6.5A2.5,2.5 0 0,1 14.5,9A2.5,2.5 0 0,1 12,11.5M12,2A7,7 0 0,0 5,9C5,14.25 12,22 12,22C12,22 19,14.25 19,9A7,7 0 0,0 12,2Z"></path>
+            <div class="">
+              </span><strong><span class="place_name">{{ event.place.name }}</span></strong>
+            </div>
+          </div>
+        </div>
+       <div class="center flyer-container">
+         <img class="flyer" src="https://balotta.org/media/thumb/{{event.media[0].url}}" style="object-position: {{ event.media[0].thumbnailPosition }}"></img> 
+       </div>
+      </div>
+  {% endfor %}
+  </div>
+  </body>
+</html>

+ 16 - 0
templates/index.html

@@ -0,0 +1,16 @@
+<!doctype html>
+<title>Generatore di volantini</title>
+<h3> Generatore di volantini per balotta.org</h3>
+<div>
+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).
+<br>
+</div>
+
+<form action="/flyer" target="_blank">
+{% for event in events %}
+<input type="checkbox" {% if loop.index <= 12 %} checked {% endif %} id="{{event.id}}" name="events" value="{{event.id}}">
+<label for="{{event.id}}"> {{loop.index}} [ {{event.when}} ] {{ event.title }}</label><br>
+{% endfor %}
+<input type="submit" value="Genera volantino">
+</form>