From 83b7318a4672d32ed77cd3f906f43f5ad1cce854 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Thu, 14 Dec 2017 18:47:45 -0800 Subject: archived old apps that I'm not using --- app/unused_apps/daily/admin.py | 55 +++++++++++ app/unused_apps/daily/create_daily.py | 14 +++ app/unused_apps/daily/get_weather.py | 14 +++ app/unused_apps/daily/migrations/0001_initial.py | 71 ++++++++++++++ .../daily/migrations/0002_auto_20160118_2144.py | 21 +++++ .../daily/migrations/0003_auto_20160119_1206.py | 49 ++++++++++ .../daily/migrations/0004_auto_20160119_1223.py | 30 ++++++ .../daily/migrations/0005_remove_daily_slug.py | 19 ++++ .../daily/migrations/0006_daily_weather_human.py | 20 ++++ .../daily/migrations/0007_auto_20160119_1604.py | 21 +++++ .../daily/migrations/0008_auto_20160124_0914.py | 30 ++++++ .../daily/migrations/0009_remove_daily_title.py | 19 ++++ .../daily/migrations/0010_auto_20161023_2014.py | 19 ++++ app/unused_apps/daily/migrations/__init__.py | 0 app/unused_apps/daily/models.py | 105 +++++++++++++++++++++ app/unused_apps/daily/retriever.py | 53 +++++++++++ 16 files changed, 540 insertions(+) create mode 100644 app/unused_apps/daily/admin.py create mode 100644 app/unused_apps/daily/create_daily.py create mode 100644 app/unused_apps/daily/get_weather.py create mode 100644 app/unused_apps/daily/migrations/0001_initial.py create mode 100644 app/unused_apps/daily/migrations/0002_auto_20160118_2144.py create mode 100644 app/unused_apps/daily/migrations/0003_auto_20160119_1206.py create mode 100644 app/unused_apps/daily/migrations/0004_auto_20160119_1223.py create mode 100644 app/unused_apps/daily/migrations/0005_remove_daily_slug.py create mode 100644 app/unused_apps/daily/migrations/0006_daily_weather_human.py create mode 100644 app/unused_apps/daily/migrations/0007_auto_20160119_1604.py create mode 100644 app/unused_apps/daily/migrations/0008_auto_20160124_0914.py create mode 100644 app/unused_apps/daily/migrations/0009_remove_daily_title.py create mode 100644 app/unused_apps/daily/migrations/0010_auto_20161023_2014.py create mode 100644 app/unused_apps/daily/migrations/__init__.py create mode 100644 app/unused_apps/daily/models.py create mode 100644 app/unused_apps/daily/retriever.py (limited to 'app/unused_apps/daily') diff --git a/app/unused_apps/daily/admin.py b/app/unused_apps/daily/admin.py new file mode 100644 index 0000000..32a5747 --- /dev/null +++ b/app/unused_apps/daily/admin.py @@ -0,0 +1,55 @@ +from django.contrib import admin + +from utils.widgets import LGEntryForm, OLAdminBase +from .models import CheckIn, Daily, Weather + + +class WeatherAdmin(OLAdminBase): + pass + + +class CheckInAdmin(OLAdminBase): + list_display = ('date', 'location') + pass + + +class DailyAdmin(admin.ModelAdmin): + form = LGEntryForm + list_display = ('date', 'user', 'location') + list_filter = ( + 'date', + ('location', admin.RelatedOnlyFieldListFilter), + ) + fieldsets = ( + (None, { + 'fields': ( + 'user', + 'body_markdown', + 'weather_human', + ) + }), + ('Details', { + 'fields': ( + 'location', + 'weather', + 'date' + ), + 'classes': ('collapse',), + }), + ) + + def get_form(self, request, obj=None, **kwargs): + form = super(DailyAdmin, self).get_form(request, **kwargs) + form.current_user = request.user + return form + + def get_queryset(self, request): + qs = super(DailyAdmin, self).get_queryset(request) + if request.user.is_superuser: + return qs + return qs.filter(user=request.user) + + +admin.site.register(CheckIn, CheckInAdmin) +admin.site.register(Weather, WeatherAdmin) +admin.site.register(Daily, DailyAdmin) diff --git a/app/unused_apps/daily/create_daily.py b/app/unused_apps/daily/create_daily.py new file mode 100644 index 0000000..5441b77 --- /dev/null +++ b/app/unused_apps/daily/create_daily.py @@ -0,0 +1,14 @@ +import sys +import os +from os.path import dirname, abspath +import django +PROJECT_ROOT = abspath(dirname(dirname(dirname(__file__)))) + '/' +sys.path.append(PROJECT_ROOT) +sys.path.append(PROJECT_ROOT + '/app') +sys.path.append(PROJECT_ROOT + '/app/lib') +sys.path.append(PROJECT_ROOT + '/config') +sys.path.append(PROJECT_ROOT + '/venv/bin/python3') +os.environ['DJANGO_SETTINGS_MODULE'] = 'config.settings' +django.setup() +from daily import retriever +retriever.create_daily() diff --git a/app/unused_apps/daily/get_weather.py b/app/unused_apps/daily/get_weather.py new file mode 100644 index 0000000..6cd56af --- /dev/null +++ b/app/unused_apps/daily/get_weather.py @@ -0,0 +1,14 @@ +import sys +import os +from os.path import dirname, abspath +import django +PROJECT_ROOT = abspath(dirname(dirname(dirname(__file__)))) + '/' +sys.path.append(PROJECT_ROOT) +sys.path.append(PROJECT_ROOT + '/app') +sys.path.append(PROJECT_ROOT + '/app/lib') +sys.path.append(PROJECT_ROOT + '/config') +sys.path.append(PROJECT_ROOT + '/venv/bin/python3') +os.environ['DJANGO_SETTINGS_MODULE'] = 'config.settings' +django.setup() +from daily import retriever +retriever.get_yesterday_weather() diff --git a/app/unused_apps/daily/migrations/0001_initial.py b/app/unused_apps/daily/migrations/0001_initial.py new file mode 100644 index 0000000..b3ba687 --- /dev/null +++ b/app/unused_apps/daily/migrations/0001_initial.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-01-18 20:38 +from __future__ import unicode_literals + +import django.contrib.gis.db.models.fields +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('locations', '__first__'), + ] + + operations = [ + migrations.CreateModel( + name='CheckIn', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('point', django.contrib.gis.db.models.fields.PointField(blank=True, srid=4326)), + ('date', models.DateField(default=django.utils.timezone.now)), + ('location', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location')), + ], + ), + migrations.CreateModel( + name='Daily', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('slug', models.SlugField()), + ('body_html', models.TextField(blank=True)), + ('body_markdown', models.TextField()), + ('date', models.DateField(verbose_name='Date published')), + ('location', models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location')), + ], + options={ + 'get_latest_by': 'date', + 'ordering': ('date',), + }, + ), + migrations.CreateModel( + name='Weather', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('point', django.contrib.gis.db.models.fields.PointField(blank=True, null=True, srid=4326)), + ('date', models.DateField()), + ('temp_max', models.CharField(max_length=4)), + ('temp_min', models.CharField(max_length=4)), + ('temp_mean', models.CharField(max_length=4)), + ('wind_mean', models.CharField(max_length=10)), + ('wind_max', models.CharField(max_length=10)), + ('humidity', models.CharField(max_length=10)), + ('snow_amount', models.CharField(max_length=10)), + ('rain_amount', models.CharField(max_length=10)), + ('fog', models.NullBooleanField()), + ('rain', models.NullBooleanField()), + ('snow', models.NullBooleanField()), + ('hail', models.NullBooleanField()), + ('thunder', models.NullBooleanField()), + ], + ), + migrations.AddField( + model_name='daily', + name='weather', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='daily.Weather'), + ), + ] diff --git a/app/unused_apps/daily/migrations/0002_auto_20160118_2144.py b/app/unused_apps/daily/migrations/0002_auto_20160118_2144.py new file mode 100644 index 0000000..4769c21 --- /dev/null +++ b/app/unused_apps/daily/migrations/0002_auto_20160118_2144.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-01-18 21:44 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('daily', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='checkin', + name='location', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location'), + ), + ] diff --git a/app/unused_apps/daily/migrations/0003_auto_20160119_1206.py b/app/unused_apps/daily/migrations/0003_auto_20160119_1206.py new file mode 100644 index 0000000..d28c9ff --- /dev/null +++ b/app/unused_apps/daily/migrations/0003_auto_20160119_1206.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-01-19 12:06 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('daily', '0002_auto_20160118_2144'), + ] + + operations = [ + migrations.AlterModelOptions( + name='checkin', + options={'get_latest_by': 'date', 'ordering': ('-date',)}, + ), + migrations.AlterModelOptions( + name='weather', + options={'get_latest_by': 'date', 'ordering': ('-date',), 'verbose_name_plural': 'Weather'}, + ), + migrations.AlterField( + model_name='daily', + name='body_html', + field=models.TextField(blank=True, null=True), + ), + migrations.AlterField( + model_name='daily', + name='body_markdown', + field=models.TextField(blank=True, null=True), + ), + migrations.AlterField( + model_name='daily', + name='slug', + field=models.SlugField(blank=True, null=True), + ), + migrations.AlterField( + model_name='daily', + name='title', + field=models.CharField(blank=True, max_length=200, null=True), + ), + migrations.AlterField( + model_name='daily', + name='weather', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='daily.Weather'), + ), + ] diff --git a/app/unused_apps/daily/migrations/0004_auto_20160119_1223.py b/app/unused_apps/daily/migrations/0004_auto_20160119_1223.py new file mode 100644 index 0000000..3c77deb --- /dev/null +++ b/app/unused_apps/daily/migrations/0004_auto_20160119_1223.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-01-19 12:23 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('daily', '0003_auto_20160119_1206'), + ] + + operations = [ + migrations.AlterField( + model_name='weather', + name='temp_max', + field=models.CharField(max_length=8), + ), + migrations.AlterField( + model_name='weather', + name='temp_mean', + field=models.CharField(max_length=8), + ), + migrations.AlterField( + model_name='weather', + name='temp_min', + field=models.CharField(max_length=8), + ), + ] diff --git a/app/unused_apps/daily/migrations/0005_remove_daily_slug.py b/app/unused_apps/daily/migrations/0005_remove_daily_slug.py new file mode 100644 index 0000000..8a896ba --- /dev/null +++ b/app/unused_apps/daily/migrations/0005_remove_daily_slug.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-01-19 13:38 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('daily', '0004_auto_20160119_1223'), + ] + + operations = [ + migrations.RemoveField( + model_name='daily', + name='slug', + ), + ] diff --git a/app/unused_apps/daily/migrations/0006_daily_weather_human.py b/app/unused_apps/daily/migrations/0006_daily_weather_human.py new file mode 100644 index 0000000..7f701b4 --- /dev/null +++ b/app/unused_apps/daily/migrations/0006_daily_weather_human.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-01-19 13:45 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('daily', '0005_remove_daily_slug'), + ] + + operations = [ + migrations.AddField( + model_name='daily', + name='weather_human', + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/app/unused_apps/daily/migrations/0007_auto_20160119_1604.py b/app/unused_apps/daily/migrations/0007_auto_20160119_1604.py new file mode 100644 index 0000000..1acd5de --- /dev/null +++ b/app/unused_apps/daily/migrations/0007_auto_20160119_1604.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-01-19 16:04 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('daily', '0006_daily_weather_human'), + ] + + operations = [ + migrations.AlterField( + model_name='daily', + name='location', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location'), + ), + ] diff --git a/app/unused_apps/daily/migrations/0008_auto_20160124_0914.py b/app/unused_apps/daily/migrations/0008_auto_20160124_0914.py new file mode 100644 index 0000000..eff3604 --- /dev/null +++ b/app/unused_apps/daily/migrations/0008_auto_20160124_0914.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-01-24 09:14 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +from django.contrib.auth.models import User +lux = User.objects.get(username="luxagraf") + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('daily', '0007_auto_20160119_1604'), + ] + + operations = [ + migrations.AddField( + model_name='daily', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + migrations.AlterField( + model_name='daily', + name='date', + field=models.DateField(), + ), + ] diff --git a/app/unused_apps/daily/migrations/0009_remove_daily_title.py b/app/unused_apps/daily/migrations/0009_remove_daily_title.py new file mode 100644 index 0000000..085adf3 --- /dev/null +++ b/app/unused_apps/daily/migrations/0009_remove_daily_title.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-01-24 16:27 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('daily', '0008_auto_20160124_0914'), + ] + + operations = [ + migrations.RemoveField( + model_name='daily', + name='title', + ), + ] diff --git a/app/unused_apps/daily/migrations/0010_auto_20161023_2014.py b/app/unused_apps/daily/migrations/0010_auto_20161023_2014.py new file mode 100644 index 0000000..72a68cf --- /dev/null +++ b/app/unused_apps/daily/migrations/0010_auto_20161023_2014.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-10-23 20:14 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('daily', '0009_remove_daily_title'), + ] + + operations = [ + migrations.AlterModelOptions( + name='daily', + options={'get_latest_by': 'date', 'ordering': ('-date',)}, + ), + ] diff --git a/app/unused_apps/daily/migrations/__init__.py b/app/unused_apps/daily/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/unused_apps/daily/models.py b/app/unused_apps/daily/models.py new file mode 100644 index 0000000..1bf7bfd --- /dev/null +++ b/app/unused_apps/daily/models.py @@ -0,0 +1,105 @@ +from django.contrib.gis.db import models +from django.conf import settings +from django import forms +from django.utils import timezone + +from locations.models import Location + +from utils.widgets import markdown_to_html + + +class CheckIn(models.Model): + point = models.PointField(blank=True) + location = models.ForeignKey(Location, blank=True, null=True) + date = models.DateField(default=timezone.now) + + class Meta: + ordering = ('-date',) + get_latest_by = 'date' + + def __str__(self): + return str(self.date) + + @property + def lon(self): + '''Get the site's longitude.''' + return self.point.x + + @property + def lat(self): + '''Get the site's latitude.''' + return self.point.y + + def save(self): + try: + self.location = Location.objects.filter(geometry__contains=self.point).get() + except Location.DoesNotExist: + raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL)) + super(CheckIn, self).save() + + +class Weather(models.Model): + point = models.PointField(null=True, blank=True) + date = models.DateField() + temp_max = models.CharField(max_length=8) + temp_min = models.CharField(max_length=8) + temp_mean = models.CharField(max_length=8) + wind_mean = models.CharField(max_length=10) + wind_max = models.CharField(max_length=10) + humidity = models.CharField(max_length=10) + snow_amount = models.CharField(max_length=10) + rain_amount = models.CharField(max_length=10) + fog = models.NullBooleanField() + rain = models.NullBooleanField() + snow = models.NullBooleanField() + hail = models.NullBooleanField() + thunder = models.NullBooleanField() + + class Meta: + ordering = ('-date',) + get_latest_by = 'date' + verbose_name_plural = "Weather" + + def __str__(self): + return str(self.date) + + +class Daily(models.Model): + user = models.ForeignKey(settings.AUTH_USER_MODEL) + location = models.ForeignKey(Location, blank=True, null=True) + weather = models.ForeignKey(Weather, blank=True, null=True) + weather_human = models.TextField(blank=True, null=True) + body_html = models.TextField(blank=True, null=True) + body_markdown = models.TextField(blank=True, null=True) + date = models.DateField() + + class Meta: + ordering = ('-date',) + get_latest_by = 'date' + + def __str__(self): + return str(self.date) + + @property + def longitude(self): + '''Get the site's longitude.''' + return self.point.x + + @property + def latitude(self): + '''Get the site's latitude.''' + return self.point.y + + @property + def get_previous_published(self): + return self.get_previous_by_pub_date(status__exact=1) + + @property + def get_next_published(self): + return self.get_next_by_pub_date(status__exact=1) + + def save(self, **kwargs): + if self.body_markdown: + self.body_html = markdown_to_html(self.body_markdown) + self.location = CheckIn.objects.latest().location + super(Daily, self).save() diff --git a/app/unused_apps/daily/retriever.py b/app/unused_apps/daily/retriever.py new file mode 100644 index 0000000..3b7da87 --- /dev/null +++ b/app/unused_apps/daily/retriever.py @@ -0,0 +1,53 @@ +from datetime import datetime +import requests +import json + +from django.utils import timezone +from django.template.loader import render_to_string +from django.contrib.auth.models import User +from django.db.models import Q + +from .models import CheckIn, Daily, Weather + + +def create_daily(): + users = User.objects.filter(Q(username="luxagraf") | Q(username="corrinne")) + for user in users: + d, created = Daily.objects.get_or_create( + user=user, + date=timezone.now() + ) + if not created: + print("already existed") + + +def get_yesterday_weather(): + current = CheckIn.objects.latest() + PB_URL = "http://api.wunderground.com/api/39c3ce6a12b14e75/yesterday/q/%s,%s.json" % (current.lat, current.lon) + r = requests.get(PB_URL) + weather = json.loads(r.text) + data = weather['history']['dailysummary'][0] + date = "%s %s %s" % (data['date']['year'], data['date']['mon'], data['date']['mday']) + dt = datetime.strptime(date, "%Y %m %d") + w, created = Weather.objects.get_or_create( + point=current.point, + date=dt, + temp_max=data['maxtempi'], + temp_min=data['mintempi'], + temp_mean=data['meantempi'], + wind_mean=data['meanwindspdi'], + wind_max=data['maxwspdi'], + humidity=data['humidity'], + snow_amount=data['snowfalli'], + rain_amount=data['precipi'], + fog=int(data['fog']), + rain=int(data['rain']), + snow=int(data['snow']), + hail=int(data['hail']), + thunder=int(data['thunder']), + ) + dailies = Daily.objects.filter(date=dt) + for d in dailies: + d.weather = w + d.weather_human = render_to_string('human_weather.txt', {'object': w}).strip() + d.save() -- cgit v1.2.3-70-g09d2