diff --git a/infoscreen/management/commands/importabb.py b/infoscreen/management/commands/importabb.py new file mode 100644 index 0000000..3db581c --- /dev/null +++ b/infoscreen/management/commands/importabb.py @@ -0,0 +1,46 @@ +from django.core.management.base import BaseCommand, CommandError +from django.db.models import Max +from django.conf import settings +from datetime import datetime, timedelta +from pytz import utc +from paramiko.client import SSHClient, AutoAddPolicy, RSAKey +from infoscreen.models import ABBJob +import qrcode + +class Command(BaseCommand): + help = 'import new abbjobs from oldish sikweb' + + def add_arguments(self, parser): + parser.add_argument('keypath') + + def handle(self, *args, **options): + last_id = ABBJob.objects.aggregate(Max('sw_id'))['sw_id__max'] or 0 + client = SSHClient() + client.set_missing_host_key_policy(AutoAddPolicy()) + key = RSAKey.from_private_key_file(options.get("keypath")) + client.connect("otax.ayy.fi", username="sik", pkey=key) + stdin, stdout, stderr = client.exec_command("./abbjobexport.sh {}".format(last_id)) + errors = stderr.read() + if len(errors) > 0: + print(errors) + client.close() + return + data = stdout.read().decode("latin1").strip().split("\n") # shame on latin1 otax!!! + for row in data: + if not row: + continue + cols = row.split('\t',maxsplit=2) + qr_url = gen_qr(cols[0]) + created = datetime.strptime(cols[1], "%Y-%m-%d %H:%M:%S").replace(tzinfo=utc) # todo parse to right timezone + ABBJob.objects.create( + sw_id=int(cols[0]), + created=created, + title=cols[2], + QR=qr_url) + +def gen_qr(sw_id): + img = qrcode.make("http://sahkoinsinoorikilta.fi/news/{}".format(sw_id)) + imgname = "abbjobs_{}.png".format(sw_id) + imgurl = "{}qr/{}".format(settings.MEDIA_URL,imgname) + img.save("{}/qr/{}".format(settings.MEDIA_ROOT,imgname)) + return imgurl diff --git a/infoscreen/migrations/0001_initial.py b/infoscreen/migrations/0001_initial.py new file mode 100644 index 0000000..5254f3b --- /dev/null +++ b/infoscreen/migrations/0001_initial.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-08-31 17:54 +from __future__ import unicode_literals + +import datetime +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='ABBJob', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('sw_id', models.IntegerField(default=-1)), + ('title', models.CharField(max_length=255)), + ('QR', models.CharField(default='', max_length=255)), + ('created', models.DateTimeField(default=datetime.datetime.now)), + ], + ), + ] diff --git a/infoscreen/migrations/0002_auto_20160831_1757.py b/infoscreen/migrations/0002_auto_20160831_1757.py new file mode 100644 index 0000000..b21b61d --- /dev/null +++ b/infoscreen/migrations/0002_auto_20160831_1757.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-08-31 17:57 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('infoscreen', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='abbjob', + name='created', + field=models.DateTimeField(default=django.utils.timezone.now), + ), + ] diff --git a/infoscreen/models.py b/infoscreen/models.py index 71a8362..2d4d93a 100644 --- a/infoscreen/models.py +++ b/infoscreen/models.py @@ -1,3 +1,14 @@ from django.db import models +from django.utils import timezone -# Create your models here. +class ABBJob(models.Model): + sw_id = models.IntegerField(default=-1) + title = models.CharField(max_length=255) + QR = models.CharField(max_length=255, default="") + created = models.DateTimeField(default=timezone.now) + + def get_dict(self): + return { + "title": self.title, + "QR": self.QR, + } diff --git a/infoscreen/static/css/infoscreen.css b/infoscreen/static/css/infoscreen.css index 1df6617..ef39121 100644 --- a/infoscreen/static/css/infoscreen.css +++ b/infoscreen/static/css/infoscreen.css @@ -18,4 +18,20 @@ display: block; margin-left: auto; margin-right: auto; -} \ No newline at end of file +} + +.swap-animation.ng-enter, .swap-animation.ng-leave { + transition:0.5s linear all; +} +.swap-animation.ng-enter { + opacity:0; +} +.swap-animation.ng-enter-active { + opacity:1; +} +.swap-animation.ng-leave { + opacity:1; +} +.swap-animation.ng-leave-active { + opacity:0; +} diff --git a/infoscreen/static/html/abb.html b/infoscreen/static/html/abb.html new file mode 100644 index 0000000..bf65a06 --- /dev/null +++ b/infoscreen/static/html/abb.html @@ -0,0 +1,11 @@ +
