diff --git a/.gitignore b/.gitignore index 94bbb6c..c8ca245 100644 --- a/.gitignore +++ b/.gitignore @@ -58,4 +58,5 @@ ENV/ .idea/**/uiDesigner.xml .idea/**/gradle.xml .idea/**/libraries +.idea/** *.iws /out/ \ No newline at end of file diff --git a/.tmp b/.tmp new file mode 100644 index 0000000..e69de29 diff --git a/Dockerfile b/Dockerfile index c7937a3..24f0179 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ FROM tiangolo/uwsgi-nginx-flask -ENV STATIC_URL /static -ENV STATIC_PATH /var/www/app/static -ENV cal_id 9E2AC562-4328-4CA0-B4D1-D730D9F5E9EF -ENV username a@correa.co -ENV password jyxq-avwz-qxfd-dklo -ENV caldav_url https://caldav.icloud.com/ +# Install system dependencies and wkhtmltoimage +RUN apt-get update && apt-get install -y \ + wkhtmltopdf \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* COPY ./requirements.txt /var/www/requirements.txt +COPY ./server ./app RUN pip install -r /var/www/requirements.txt \ No newline at end of file diff --git a/app/__init__.py b/app/__init__.py deleted file mode 100644 index 8f5986d..0000000 --- a/app/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from flask import Flask -app = Flask(__name__) -from app import views \ No newline at end of file diff --git a/app/static/style.css b/app/static/style.css deleted file mode 100644 index 767dcf8..0000000 --- a/app/static/style.css +++ /dev/null @@ -1,95 +0,0 @@ -@import url('fonts/dinpro/dinpro.css'); -@import url('fonts/noto-emoji.css'); -@import url('fonts/openmoji.css'); -@import url('fonts/weather-icons/weather-icons.css'); - -@font-face { - font-family: "Hellovetica"; - src: url("fonts/hellovetica.ttf") format("truetype"); -} - -@font-face { - font-family: "Helvetica"; -} - -.dashboard { - font-family: "Helvetica", sans-serif; - height: 699px; - width: 600px; - text-align: left; - font-size: 17px; -} - -.panel { - position: relative; - height: 50%; - verical-align: top; - /* height: 250px; */ - width: 100%; -} - -.panel.top { - height: 35%; -} - -.panel.bottom { - height: 65%; -} - -.subpanel { - position: relative; - height:100%; - width:48%; - display: inline-block; - text-align: center; -} - -.weather-icon { - - position: relative; - height: 100%; - width: 100%; - object-fit: scale-down; -} - -.week { - text-align: center; -} - -.day { - border-style: solid; - display: inline-block; - min-height: 220px; - max-height: 220px; - width: 135px; - vertical-align: top; - margin: 1px; - align-items: center; - text-align: left; -} - -.day-title{ - background-color: black; - text-align: center; - color: white; - text-transform: uppercase; - font-weight: bold; - -} - -.event { - margin: 3pt; - background-color: white; - border-style: solid; - border-radius: 5px; - padding: 2px; - font-family: "Helvetica"; -} - -.daterange { - font-size: smaller; -} - -.weather-icon { - font-size: 200px; -} \ No newline at end of file diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..5886898 --- /dev/null +++ b/compose.yml @@ -0,0 +1,10 @@ +services: + webcal: + build: . + env_file: + - .env + ports: + - "56733:80" + volumes: + - ./server:/app + \ No newline at end of file diff --git a/main.py b/main.py deleted file mode 100644 index e524e69..0000000 --- a/main.py +++ /dev/null @@ -1 +0,0 @@ -from app import app \ No newline at end of file diff --git a/out.png b/out.png new file mode 100644 index 0000000..75ee7b9 Binary files /dev/null and b/out.png differ diff --git a/requirements.txt b/requirements.txt index b0097ee..d9076af 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,7 @@ caldav~=0.9.0 requests~=2.27.1 icalendar~=4.0.9 -Flask~=2.1.2 \ No newline at end of file +Flask~=2.1.2 +Werkzeug==2.2.2 +imgkit +pillow \ No newline at end of file diff --git a/server/app/__init__.py b/server/app/__init__.py new file mode 100644 index 0000000..a7ee582 --- /dev/null +++ b/server/app/__init__.py @@ -0,0 +1,8 @@ +# app/__init__.py +from flask import Flask + +# Create Flask app +app = Flask(__name__,static_url_path='', static_folder='static') + +# Import views to register routes +from app import views \ No newline at end of file diff --git a/server/app/main.py b/server/app/main.py new file mode 100644 index 0000000..e69de29 diff --git a/app/models.py b/server/app/models.py similarity index 100% rename from app/models.py rename to server/app/models.py diff --git a/app/templates/dashboard.html b/server/app/templates/dashboard.html similarity index 89% rename from app/templates/dashboard.html rename to server/app/templates/dashboard.html index c877c27..6f6e555 100644 --- a/app/templates/dashboard.html +++ b/server/app/templates/dashboard.html @@ -2,10 +2,12 @@ Dashboard ({{today.strftime('%-m/%-d, %-H:%M')}}) - + +
+
diff --git a/server/app/templates/dashboard_static.html b/server/app/templates/dashboard_static.html new file mode 100644 index 0000000..367cf7f --- /dev/null +++ b/server/app/templates/dashboard_static.html @@ -0,0 +1,42 @@ + + + + Dashboard ({{today.strftime('%-m/%-d, %-H:%M')}}) + + + + +
+
+
+
+
+
{{weather.main}}
+
+
+ {{ today.strftime('%a') }}
+ {{ today.strftime('%b %-d') }}
+ {{ today.strftime('%Y') }}
+
+
+
+ + {% for day, events in days %} +
+
+ {{ day.strftime('%A') }} +
+ {% for event in events %} +
+ {{ event.summary }}
+ {% if not event.is_all_day %} + {{ event.range_str }} + {% endif %} +
+ {% endfor %} +
+ {% endfor %} +
+
+ + diff --git a/app/views.py b/server/app/views.py similarity index 74% rename from app/views.py rename to server/app/views.py index fe5d6f6..249fbe8 100644 --- a/app/views.py +++ b/server/app/views.py @@ -4,9 +4,12 @@ import os import caldav import datetime from icalendar import cal, Event -from flask import render_template +from flask import render_template, url_for, send_file, send_from_directory from .models import Event import requests +import imgkit +from PIL import Image, ImageOps +import io caldav_url = os.getenv('caldav_url') username = os.getenv('username') password = os.getenv('password') @@ -88,9 +91,38 @@ def dashboard(): # breakpoint() pass # r = "
".join([event.vobject_instance.vevent.summary.value for event in events_fetched if event.vobject_instance.vevent.dtstart.value < datetime.now()]) - return render_template("dashboard.html", + return render_template("dashboard_static.html", days=days, today=today, weather=weather() ) +@app.route('/image') +def dashboard_image(): + page = dashboard() + out_file = os.path.join(os.path.dirname(__file__), + 'static', "out.bmp" + ) + + s = imgkit.from_string( + page, + out_file, + options={ + + 'width':600, + 'height':800, + "disable-smart-width": "", + 'enable-local-file-access': "", + 'allow': os.path.join(os.path.dirname(__file__), + 'static', + ) + }, + css=os.path.join(os.path.dirname(__file__), + 'static', + 'style.css' + ) + ) + image_file = Image.open(out_file) # open colour image + image_file = ImageOps.grayscale(image_file) + image_file.save(out_file, 'BMP') + return send_from_directory(directory = 'static', path='out.bmp', as_attachment=False, attachment_filename='out.bmp') diff --git a/app/weather.py b/server/app/weather.py similarity index 96% rename from app/weather.py rename to server/app/weather.py index 8b80c4c..4697a26 100644 --- a/app/weather.py +++ b/server/app/weather.py @@ -10,8 +10,7 @@ URL = "https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid def weather(api_key=os.getenv('openweathermap_api_key'), lat="41.98", lon="-87.90"): url = URL.format(api_key=api_key, lat=lat, lon=lon) data = json.loads(requests.get(url).content) - return data['weather'][0] -f=weather() +# f=weather() pass \ No newline at end of file diff --git a/uwsgi.ini b/server/uwsgi.ini similarity index 72% rename from uwsgi.ini rename to server/uwsgi.ini index 1cf8434..6982d95 100644 --- a/uwsgi.ini +++ b/server/uwsgi.ini @@ -1,4 +1,4 @@ [uwsgi] -module = main +module = app callable = app master = true \ No newline at end of file diff --git a/test.png b/test.png new file mode 100644 index 0000000..e6de3f0 Binary files /dev/null and b/test.png differ