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/daily/admin.py | 55 --------- app/daily/create_daily.py | 14 --- app/daily/get_weather.py | 14 --- app/daily/migrations/0001_initial.py | 71 ------------ app/daily/migrations/0002_auto_20160118_2144.py | 21 ---- app/daily/migrations/0003_auto_20160119_1206.py | 49 -------- app/daily/migrations/0004_auto_20160119_1223.py | 30 ----- app/daily/migrations/0005_remove_daily_slug.py | 19 --- app/daily/migrations/0006_daily_weather_human.py | 20 ---- app/daily/migrations/0007_auto_20160119_1604.py | 21 ---- app/daily/migrations/0008_auto_20160124_0914.py | 30 ----- app/daily/migrations/0009_remove_daily_title.py | 19 --- app/daily/migrations/0010_auto_20161023_2014.py | 19 --- app/daily/migrations/__init__.py | 0 app/daily/models.py | 105 ----------------- app/daily/retriever.py | 53 --------- app/ebay/__init__.py | 0 app/ebay/admin.py | 15 --- app/ebay/migrations/0001_initial.py | 50 -------- app/ebay/migrations/0002_auto_20161231_1401.py | 25 ---- app/ebay/migrations/0003_auto_20161231_1419.py | 24 ---- .../migrations/0004_trackeditem_date_ending.py | 21 ---- app/ebay/migrations/0005_auto_20161231_1444.py | 24 ---- app/ebay/migrations/__init__.py | 0 app/ebay/models.py | 84 -------------- app/ebay/update_price.py | 17 --- app/guide/__init__.py | 0 app/guide/admin.py | 61 ---------- app/guide/models.py | 129 --------------------- app/guide/urls.py | 13 --- app/guide/views.py | 35 ------ app/syndication/__init__.py | 0 app/syndication/admin.py | 20 ---- app/syndication/migrations/0001_initial.py | 37 ------ .../migrations/0002_auto_20160628_2149.py | 31 ----- .../migrations/0003_auto_20161023_2014.py | 19 --- app/syndication/migrations/__init__.py | 0 app/syndication/models.py | 86 -------------- app/syndication/syndicators.py | 123 -------------------- app/syndication/templatetags/__init__.py | 0 app/syndication/templatetags/facebook_processor.py | 23 ---- app/syndication/views.py | 17 --- 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 +++++++++ app/unused_apps/ebay/__init__.py | 0 app/unused_apps/ebay/admin.py | 15 +++ app/unused_apps/ebay/migrations/0001_initial.py | 50 ++++++++ .../ebay/migrations/0002_auto_20161231_1401.py | 25 ++++ .../ebay/migrations/0003_auto_20161231_1419.py | 24 ++++ .../migrations/0004_trackeditem_date_ending.py | 21 ++++ .../ebay/migrations/0005_auto_20161231_1444.py | 24 ++++ app/unused_apps/ebay/migrations/__init__.py | 0 app/unused_apps/ebay/models.py | 84 ++++++++++++++ app/unused_apps/ebay/update_price.py | 17 +++ app/unused_apps/guide/__init__.py | 0 app/unused_apps/guide/admin.py | 61 ++++++++++ app/unused_apps/guide/models.py | 129 +++++++++++++++++++++ app/unused_apps/guide/urls.py | 13 +++ app/unused_apps/guide/views.py | 35 ++++++ app/unused_apps/syndication/__init__.py | 0 app/unused_apps/syndication/admin.py | 20 ++++ .../syndication/migrations/0001_initial.py | 37 ++++++ .../migrations/0002_auto_20160628_2149.py | 31 +++++ .../migrations/0003_auto_20161023_2014.py | 19 +++ app/unused_apps/syndication/migrations/__init__.py | 0 app/unused_apps/syndication/models.py | 86 ++++++++++++++ app/unused_apps/syndication/syndicators.py | 123 ++++++++++++++++++++ .../syndication/templatetags/__init__.py | 0 .../syndication/templatetags/facebook_processor.py | 23 ++++ app/unused_apps/syndication/views.py | 17 +++ 84 files changed, 1394 insertions(+), 1394 deletions(-) delete mode 100644 app/daily/admin.py delete mode 100644 app/daily/create_daily.py delete mode 100644 app/daily/get_weather.py delete mode 100644 app/daily/migrations/0001_initial.py delete mode 100644 app/daily/migrations/0002_auto_20160118_2144.py delete mode 100644 app/daily/migrations/0003_auto_20160119_1206.py delete mode 100644 app/daily/migrations/0004_auto_20160119_1223.py delete mode 100644 app/daily/migrations/0005_remove_daily_slug.py delete mode 100644 app/daily/migrations/0006_daily_weather_human.py delete mode 100644 app/daily/migrations/0007_auto_20160119_1604.py delete mode 100644 app/daily/migrations/0008_auto_20160124_0914.py delete mode 100644 app/daily/migrations/0009_remove_daily_title.py delete mode 100644 app/daily/migrations/0010_auto_20161023_2014.py delete mode 100644 app/daily/migrations/__init__.py delete mode 100644 app/daily/models.py delete mode 100644 app/daily/retriever.py delete mode 100644 app/ebay/__init__.py delete mode 100644 app/ebay/admin.py delete mode 100644 app/ebay/migrations/0001_initial.py delete mode 100644 app/ebay/migrations/0002_auto_20161231_1401.py delete mode 100644 app/ebay/migrations/0003_auto_20161231_1419.py delete mode 100644 app/ebay/migrations/0004_trackeditem_date_ending.py delete mode 100644 app/ebay/migrations/0005_auto_20161231_1444.py delete mode 100644 app/ebay/migrations/__init__.py delete mode 100644 app/ebay/models.py delete mode 100755 app/ebay/update_price.py delete mode 100644 app/guide/__init__.py delete mode 100644 app/guide/admin.py delete mode 100644 app/guide/models.py delete mode 100644 app/guide/urls.py delete mode 100644 app/guide/views.py delete mode 100644 app/syndication/__init__.py delete mode 100644 app/syndication/admin.py delete mode 100644 app/syndication/migrations/0001_initial.py delete mode 100644 app/syndication/migrations/0002_auto_20160628_2149.py delete mode 100644 app/syndication/migrations/0003_auto_20161023_2014.py delete mode 100644 app/syndication/migrations/__init__.py delete mode 100644 app/syndication/models.py delete mode 100644 app/syndication/syndicators.py delete mode 100644 app/syndication/templatetags/__init__.py delete mode 100644 app/syndication/templatetags/facebook_processor.py delete mode 100644 app/syndication/views.py 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 create mode 100644 app/unused_apps/ebay/__init__.py create mode 100644 app/unused_apps/ebay/admin.py create mode 100644 app/unused_apps/ebay/migrations/0001_initial.py create mode 100644 app/unused_apps/ebay/migrations/0002_auto_20161231_1401.py create mode 100644 app/unused_apps/ebay/migrations/0003_auto_20161231_1419.py create mode 100644 app/unused_apps/ebay/migrations/0004_trackeditem_date_ending.py create mode 100644 app/unused_apps/ebay/migrations/0005_auto_20161231_1444.py create mode 100644 app/unused_apps/ebay/migrations/__init__.py create mode 100644 app/unused_apps/ebay/models.py create mode 100755 app/unused_apps/ebay/update_price.py create mode 100644 app/unused_apps/guide/__init__.py create mode 100644 app/unused_apps/guide/admin.py create mode 100644 app/unused_apps/guide/models.py create mode 100644 app/unused_apps/guide/urls.py create mode 100644 app/unused_apps/guide/views.py create mode 100644 app/unused_apps/syndication/__init__.py create mode 100644 app/unused_apps/syndication/admin.py create mode 100644 app/unused_apps/syndication/migrations/0001_initial.py create mode 100644 app/unused_apps/syndication/migrations/0002_auto_20160628_2149.py create mode 100644 app/unused_apps/syndication/migrations/0003_auto_20161023_2014.py create mode 100644 app/unused_apps/syndication/migrations/__init__.py create mode 100644 app/unused_apps/syndication/models.py create mode 100644 app/unused_apps/syndication/syndicators.py create mode 100644 app/unused_apps/syndication/templatetags/__init__.py create mode 100644 app/unused_apps/syndication/templatetags/facebook_processor.py create mode 100644 app/unused_apps/syndication/views.py diff --git a/app/daily/admin.py b/app/daily/admin.py deleted file mode 100644 index 32a5747..0000000 --- a/app/daily/admin.py +++ /dev/null @@ -1,55 +0,0 @@ -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/daily/create_daily.py b/app/daily/create_daily.py deleted file mode 100644 index 5441b77..0000000 --- a/app/daily/create_daily.py +++ /dev/null @@ -1,14 +0,0 @@ -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/daily/get_weather.py b/app/daily/get_weather.py deleted file mode 100644 index 6cd56af..0000000 --- a/app/daily/get_weather.py +++ /dev/null @@ -1,14 +0,0 @@ -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/daily/migrations/0001_initial.py b/app/daily/migrations/0001_initial.py deleted file mode 100644 index b3ba687..0000000 --- a/app/daily/migrations/0001_initial.py +++ /dev/null @@ -1,71 +0,0 @@ -# -*- 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/daily/migrations/0002_auto_20160118_2144.py b/app/daily/migrations/0002_auto_20160118_2144.py deleted file mode 100644 index 4769c21..0000000 --- a/app/daily/migrations/0002_auto_20160118_2144.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- 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/daily/migrations/0003_auto_20160119_1206.py b/app/daily/migrations/0003_auto_20160119_1206.py deleted file mode 100644 index d28c9ff..0000000 --- a/app/daily/migrations/0003_auto_20160119_1206.py +++ /dev/null @@ -1,49 +0,0 @@ -# -*- 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/daily/migrations/0004_auto_20160119_1223.py b/app/daily/migrations/0004_auto_20160119_1223.py deleted file mode 100644 index 3c77deb..0000000 --- a/app/daily/migrations/0004_auto_20160119_1223.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- 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/daily/migrations/0005_remove_daily_slug.py b/app/daily/migrations/0005_remove_daily_slug.py deleted file mode 100644 index 8a896ba..0000000 --- a/app/daily/migrations/0005_remove_daily_slug.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- 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/daily/migrations/0006_daily_weather_human.py b/app/daily/migrations/0006_daily_weather_human.py deleted file mode 100644 index 7f701b4..0000000 --- a/app/daily/migrations/0006_daily_weather_human.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- 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/daily/migrations/0007_auto_20160119_1604.py b/app/daily/migrations/0007_auto_20160119_1604.py deleted file mode 100644 index 1acd5de..0000000 --- a/app/daily/migrations/0007_auto_20160119_1604.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- 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/daily/migrations/0008_auto_20160124_0914.py b/app/daily/migrations/0008_auto_20160124_0914.py deleted file mode 100644 index eff3604..0000000 --- a/app/daily/migrations/0008_auto_20160124_0914.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- 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/daily/migrations/0009_remove_daily_title.py b/app/daily/migrations/0009_remove_daily_title.py deleted file mode 100644 index 085adf3..0000000 --- a/app/daily/migrations/0009_remove_daily_title.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- 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/daily/migrations/0010_auto_20161023_2014.py b/app/daily/migrations/0010_auto_20161023_2014.py deleted file mode 100644 index 72a68cf..0000000 --- a/app/daily/migrations/0010_auto_20161023_2014.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- 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/daily/migrations/__init__.py b/app/daily/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/daily/models.py b/app/daily/models.py deleted file mode 100644 index 1bf7bfd..0000000 --- a/app/daily/models.py +++ /dev/null @@ -1,105 +0,0 @@ -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/daily/retriever.py b/app/daily/retriever.py deleted file mode 100644 index 3b7da87..0000000 --- a/app/daily/retriever.py +++ /dev/null @@ -1,53 +0,0 @@ -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() diff --git a/app/ebay/__init__.py b/app/ebay/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/ebay/admin.py b/app/ebay/admin.py deleted file mode 100644 index 93bf87f..0000000 --- a/app/ebay/admin.py +++ /dev/null @@ -1,15 +0,0 @@ -from django.contrib import admin - -from .models import Item, Price, TrackedItem - - -@admin.register(Item) -class ItemAdmin(admin.ModelAdmin): - list_display = ('name', 'currently_own', 'purchase_price') - - -@admin.register(TrackedItem) -class TrackedItemAdmin(admin.ModelAdmin): - list_display = ('title', 'admin_link', 'date_ending', 'get_latest_price', 'amount_desired' ) - list_filter = ('amount_desired',) - diff --git a/app/ebay/migrations/0001_initial.py b/app/ebay/migrations/0001_initial.py deleted file mode 100644 index 3d2d34e..0000000 --- a/app/ebay/migrations/0001_initial.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2016-12-31 11:43 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Item', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('url', models.CharField(max_length=200)), - ('title', models.CharField(max_length=200)), - ('purchase_price', models.IntegerField()), - ('currently_own', models.BooleanField(default=False)), - ('sold', models.BooleanField(default=False)), - ('sale_price', models.IntegerField()), - ], - ), - migrations.CreateModel( - name='Price', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('date', models.DateTimeField()), - ('price', models.IntegerField()), - ], - ), - migrations.CreateModel( - name='TrackedItem', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('url', models.CharField(max_length=200)), - ('title', models.CharField(max_length=200)), - ], - ), - migrations.AddField( - model_name='price', - name='item', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ebay.TrackedItem'), - ), - ] diff --git a/app/ebay/migrations/0002_auto_20161231_1401.py b/app/ebay/migrations/0002_auto_20161231_1401.py deleted file mode 100644 index 46f5a12..0000000 --- a/app/ebay/migrations/0002_auto_20161231_1401.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2016-12-31 14:01 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('ebay', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='price', - name='date', - field=models.DateTimeField(blank=True), - ), - migrations.AlterField( - model_name='price', - name='price', - field=models.DecimalField(decimal_places=2, max_digits=6), - ), - ] diff --git a/app/ebay/migrations/0003_auto_20161231_1419.py b/app/ebay/migrations/0003_auto_20161231_1419.py deleted file mode 100644 index 1f05859..0000000 --- a/app/ebay/migrations/0003_auto_20161231_1419.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2016-12-31 14:19 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('ebay', '0002_auto_20161231_1401'), - ] - - operations = [ - migrations.AlterModelOptions( - name='price', - options={'get_latest_by': 'date', 'ordering': ('-date',)}, - ), - migrations.RenameField( - model_name='item', - old_name='title', - new_name='name', - ), - ] diff --git a/app/ebay/migrations/0004_trackeditem_date_ending.py b/app/ebay/migrations/0004_trackeditem_date_ending.py deleted file mode 100644 index 15f41e7..0000000 --- a/app/ebay/migrations/0004_trackeditem_date_ending.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2016-12-31 14:26 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.utils.timezone - - -class Migration(migrations.Migration): - - dependencies = [ - ('ebay', '0003_auto_20161231_1419'), - ] - - operations = [ - migrations.AddField( - model_name='trackeditem', - name='date_ending', - field=models.DateTimeField(default=django.utils.timezone.now), - ), - ] diff --git a/app/ebay/migrations/0005_auto_20161231_1444.py b/app/ebay/migrations/0005_auto_20161231_1444.py deleted file mode 100644 index a7a48ac..0000000 --- a/app/ebay/migrations/0005_auto_20161231_1444.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2016-12-31 14:44 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('ebay', '0004_trackeditem_date_ending'), - ] - - operations = [ - migrations.AlterModelOptions( - name='trackeditem', - options={'get_latest_by': 'date_ending', 'ordering': ('-date_ending', 'amount_desired')}, - ), - migrations.AddField( - model_name='trackeditem', - name='amount_desired', - field=models.IntegerField(choices=[(0, '1'), (1, '2'), (2, '3'), (3, '4'), (4, '5')], default=0), - ), - ] diff --git a/app/ebay/migrations/__init__.py b/app/ebay/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/ebay/models.py b/app/ebay/models.py deleted file mode 100644 index 089e0e4..0000000 --- a/app/ebay/models.py +++ /dev/null @@ -1,84 +0,0 @@ -import datetime -import re -from django.utils.encoding import force_text -from django.contrib.gis.db import models -from django.utils import timezone -from bs4 import BeautifulSoup -import requests - -class Item(models.Model): - name = models.CharField(max_length=200) - purchase_price = models.IntegerField() - url = models.CharField(max_length=200) - currently_own = models.BooleanField(blank=True, default=False) - sold = models.BooleanField(blank=True, default=False) - sale_price = models.IntegerField() - - def save(self, **kwargs): - super(Item, self).save() - - def __str__(self): - return self.name - - -class TrackedItem(models.Model): - title = models.CharField(max_length=200) - url = models.CharField(max_length=200) - DESIRE = ( - (0, '1'), - (1, '2'), - (2, '3'), - (3, '4'), - (4, '5'), - ) - amount_desired = models.IntegerField(choices=DESIRE, default=0) - date_ending = models.DateTimeField(default=timezone.now) - - class Meta: - ordering = ('date_ending', 'amount_desired') - get_latest_by = 'date_ending' - - @property - def get_latest_price(self): - return self.price_set.latest().price - - def admin_link(self): - return force_text('View Auction page' % (self.url)) - admin_link.allow_tags = True - admin_link.short_description = 'Link' - - def __str__(self): - return self.title - - def save(self, **kwargs): - super(TrackedItem, self).save() - - -class Price(models.Model): - date = models.DateTimeField(blank=True) - price = models.DecimalField(max_digits=6, decimal_places=2) - item = models.ForeignKey(TrackedItem) - - class Meta: - ordering = ('-date',) - get_latest_by = 'date' - - def __str__(self): - return str(self.date) - - def save(self, **kwargs): - if not self.pk: - self.date = datetime.datetime.now() - super(Price, self).save() - - -def update_tracked_item_price(item): - r = requests.get(item.url) - soup = BeautifulSoup(r.text, "lxml") - numbers = re.compile('\d+(?:\.\d+)?') - price = soup.find(itemprop="price").get_text() - price = numbers.findall(price)[0] - l, created = Price.objects.get_or_create( - price=price, - item=item - ) diff --git a/app/ebay/update_price.py b/app/ebay/update_price.py deleted file mode 100755 index b8b4c8c..0000000 --- a/app/ebay/update_price.py +++ /dev/null @@ -1,17 +0,0 @@ -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() -import datetime -from ebay.models import TrackedItem, update_tracked_item_price -items = TrackedItem.objects.filter(date_ending__gte=datetime.datetime.now()) -for item in items: - update_tracked_item_price(item) diff --git a/app/guide/__init__.py b/app/guide/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/guide/admin.py b/app/guide/admin.py deleted file mode 100644 index dfdf45e..0000000 --- a/app/guide/admin.py +++ /dev/null @@ -1,61 +0,0 @@ -from django.contrib import admin -from guide.models import Guide -from django.contrib.gis.admin import OSMGeoAdmin - - -class GuideAdmin(OSMGeoAdmin): - list_display = ( - 'title', - 'pub_date', - 'template_name', - 'status', - 'location', - 'photo_gallery' - ) - search_fields = ['title', 'body_markdown'] - prepopulated_fields = {"slug": ('title',)} - list_filter = ('pub_date', 'status', 'location__state__country__lux_region', 'location') - fieldsets = ( - ('Note', { - 'fields': ( - 'title', - 'body_markdown', - 'location', - 'pub_date', - 'status', - 'slug', - 'photo_gallery' - ), - 'classes': ( - 'show', - 'extrapretty', - 'wide' - ) - }), - ('Extra', { - 'fields': ( - 'dek', - 'meta_description', - 'template_name', - 'image', - 'thumbnail' - ), - 'classes': ( - 'collapse', - 'wide' - ) - }), - ) - - # options for OSM map Using custom ESRI topo map - default_lon = -9285175 - default_lat = 4025046 - default_zoom = 6 - units = True - scrollable = False - map_width = 700 - map_height = 425 - map_template = 'gis/admin/osm.html' - openlayers_url = '/static/admin/js/OpenLayers.js' - -admin.site.register(Guide, GuideAdmin) diff --git a/app/guide/models.py b/app/guide/models.py deleted file mode 100644 index 7f0d501..0000000 --- a/app/guide/models.py +++ /dev/null @@ -1,129 +0,0 @@ -import datetime -from django.contrib.gis.db import models -from django.conf import settings -from django.contrib.sitemaps import Sitemap -from django.contrib.syndication.views import Feed -from PIL import Image - -from taggit.managers import TaggableManager -from locations.models import Location -from jrnl.models import Entry -from photos.models import PhotoGallery - -from utils.widgets import markdown_to_html - - -def get_upload_path(self, filename): - return "images/guide-images/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) - - -def get_tn_path(self, filename): - return "images/guide-thumbnail/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) - - -def image_url_replace(str): - str = str.replace('[[base_url]]', settings.IMAGES_URL) - return str - - -def markdown_processor(md): - return markdown_to_html(md) - - -class Guide(models.Model): - title = models.CharField(max_length=200) - slug = models.SlugField(unique_for_date='pub_date') - entry = models.ForeignKey(Entry, null=True, blank=True) - body_html = models.TextField(blank=True) - body_markdown = models.TextField() - dek = models.TextField(null=True, blank=True) - pub_date = models.DateTimeField('Date published') - location = models.ForeignKey(Location, null=True, blank=True) - PUB_STATUS = ( - (0, 'Draft'), - (1, 'Published'), - ) - status = models.IntegerField(choices=PUB_STATUS, default=0) - photo_gallery = models.ForeignKey(PhotoGallery, blank=True, null=True, verbose_name='photo set') - meta_description = models.CharField(max_length=256, null=True, blank=True) - TEMPLATES = ( - (0, 'single'), - (1, 'double'), - (2, 'single-dark'), - (3, 'double-dark'), - ) - template_name = models.IntegerField(choices=TEMPLATES, default=0) - tags = TaggableManager(blank=True) - image = models.FileField(upload_to=get_upload_path, null=True, blank=True) - thumbnail = models.FileField(upload_to=get_tn_path, null=True, blank=True) - - @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 - - class Meta: - ordering = ('-pub_date',) - get_latest_by = 'pub_date' - verbose_name_plural = 'entries' - - def __unicode__(self): - return self.title - - def get_absolute_url(self): - if self.location: - return "/travel-guide/location/%s/%s/" % (self.location.slug, self.slug) - else: - return "/travel-guide/%s/" % (self.slug) - - def get_thumbnail_url(self): - image_dir, img = self.thumbnail.url.split('guide-thumbnail/')[1].split('/') - return '%sguide-thumbnail/%s/%s' % (settings.IMAGES_URL, image_dir, img) - - def get_image_url(self): - image_dir, img = self.image.url.split('guide-images/')[1].split('/') - return '%sguide-images/%s/%s' % (settings.IMAGES_URL, image_dir, img) - - def save(self): - if self.image: - img = Image.open(self.image) - self.image_width, self.image_height = img.size - img = Image.open(self.thumbnail) - self.thumb_width, self.thumb_height = img.size - md = image_url_replace(self.body_markdown) - self.body_html = markdown_to_html(md) - self.dek = markdown_to_html(self.dek) - super(Guide, self).save() - - -class GuideSitemap(Sitemap): - changefreq = "never" - priority = 1.0 - - def items(self): - return Entry.objects.filter(status=1) - - def lastmod(self, obj): - return obj.pub_date - - -class GuideFull(Feed): - title = "Luxagraf: Topographical Writings" - link = "/writing/" - description = "Latest postings to luxagraf.net" - description_template = 'feeds/blog_description.html' - - def items(self): - return Entry.objects.filter(status__exact=1).order_by('-pub_date')[:10] - - -#from django.dispatch import dispatcher -#from django.db.models import signals - -#signals.post_save.connect(update_recent, sender=Entry) - diff --git a/app/guide/urls.py b/app/guide/urls.py deleted file mode 100644 index e701d3e..0000000 --- a/app/guide/urls.py +++ /dev/null @@ -1,13 +0,0 @@ -from django.conf.urls import * -from django.views.generic.base import RedirectView - -from . import views - -urlpatterns = [ - url(r'location/(?P[-\w]+)/(?P[-\w]+)/$', views.guide_detail), - url(r'location/(?P[-\w]+)/$', views.guide_list_by_location), - url(r'location/$', views.location_list), - url(r'(?P\d+)/$', views.guide_list), - url(r'(?P[-\w]+)/$', views.guide_detail), - url(r'', RedirectView.as_view(url="/travel-guide/1/")), -] diff --git a/app/guide/views.py b/app/guide/views.py deleted file mode 100644 index c22a6b3..0000000 --- a/app/guide/views.py +++ /dev/null @@ -1,35 +0,0 @@ -from django.shortcuts import render_to_response, get_object_or_404 -from django.template import RequestContext - -from guide.models import Guide - - -def guide_list(request, page): - """List of all guides""" - request.page_url = "/guide/%d/" - request.page = int(page) - context = { - 'object_list': Guide.objects.filter(status__exact=1).order_by('-pub_date').select_related(), - 'page': page, - } - return render_to_response("archives/guide.html", context, context_instance=RequestContext(request)) - - -def guide_list_by_location(request, location): - context = { - "object_list": Guide.objects.filter(location__slug__exact=location), - } - return render_to_response("archives/guide.html", context, context_instance=RequestContext(request)) - - -def location_list(request): - """List of all locations with guides""" - context = { - "object_list": Guide.objects.filter(status__exact=1).order_by('-pub_date').select_related() - } - return render_to_response("archives/guide.html", context, context_instance=RequestContext(request)) - - -def guide_detail(request, slug, location=None): - obj = get_object_or_404(Guide, slug__exact=slug) - return render_to_response('details/guide.html', {'object': obj}, context_instance=RequestContext(request)) diff --git a/app/syndication/__init__.py b/app/syndication/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/syndication/admin.py b/app/syndication/admin.py deleted file mode 100644 index b873eb7..0000000 --- a/app/syndication/admin.py +++ /dev/null @@ -1,20 +0,0 @@ -from django.contrib import admin - -from .models import Syndicate, SyndicatedItem, FBOAuthToken - - -@admin.register(FBOAuthToken) -class FBOAuthTokenAdmin(admin.ModelAdmin): - list_display = ('__str__', 'expires',) - pass - - -@admin.register(Syndicate) -class SyndicateAdmin(admin.ModelAdmin): - pass - - -@admin.register(SyndicatedItem) -class SyndicatedItemAdmin(admin.ModelAdmin): - list_display = ('__str__', 'syndicated_to',) - pass diff --git a/app/syndication/migrations/0001_initial.py b/app/syndication/migrations/0001_initial.py deleted file mode 100644 index 9643d51..0000000 --- a/app/syndication/migrations/0001_initial.py +++ /dev/null @@ -1,37 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2016-03-29 10:07 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ('contenttypes', '0002_remove_content_type_name'), - ] - - operations = [ - migrations.CreateModel( - name='Syndicate', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=200)), - ], - ), - migrations.CreateModel( - name='SyndicatedItem', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('object_id', models.PositiveIntegerField()), - ('publish_date', models.DateTimeField()), - ('status', models.CharField(blank=True, choices=[('1', 'Unsent'), ('2', 'Sent')], max_length=1, null=True)), - ('rel_link', models.CharField(blank=True, max_length=300, null=True)), - ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')), - ('syndicate', models.ManyToManyField(to='syndication.Syndicate')), - ], - ), - ] diff --git a/app/syndication/migrations/0002_auto_20160628_2149.py b/app/syndication/migrations/0002_auto_20160628_2149.py deleted file mode 100644 index 51812bf..0000000 --- a/app/syndication/migrations/0002_auto_20160628_2149.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9 on 2016-06-28 21:49 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.utils.timezone - - -class Migration(migrations.Migration): - - dependencies = [ - ('syndication', '0001_initial'), - ] - - operations = [ - migrations.CreateModel( - name='FBOAuthToken', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('short_token', models.TextField()), - ('long_token', models.TextField(blank=True, null=True)), - ('expires', models.DateTimeField(blank=True)), - ('created', models.DateTimeField(default=django.utils.timezone.now)), - ], - ), - migrations.AlterField( - model_name='syndicateditem', - name='status', - field=models.CharField(choices=[('1', 'Unsent'), ('2', 'Sent')], max_length=1, null=True), - ), - ] diff --git a/app/syndication/migrations/0003_auto_20161023_2014.py b/app/syndication/migrations/0003_auto_20161023_2014.py deleted file mode 100644 index 2b311fb..0000000 --- a/app/syndication/migrations/0003_auto_20161023_2014.py +++ /dev/null @@ -1,19 +0,0 @@ -# -*- 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 = [ - ('syndication', '0002_auto_20160628_2149'), - ] - - operations = [ - migrations.AlterModelOptions( - name='fboauthtoken', - options={'get_latest_by': 'expires', 'ordering': ('-expires',)}, - ), - ] diff --git a/app/syndication/migrations/__init__.py b/app/syndication/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/syndication/models.py b/app/syndication/models.py deleted file mode 100644 index c348c1b..0000000 --- a/app/syndication/models.py +++ /dev/null @@ -1,86 +0,0 @@ -from django.db import models -from django.utils import timezone -from django.conf import settings -import datetime -from django.contrib.contenttypes.models import ContentType -from django.contrib.contenttypes.fields import GenericForeignKey -from django.db.models.signals import post_save -from django.dispatch import receiver - -from .syndicators import post_to_medium, build_facebook_feed, post_to_twitter, post_photo_to_flickr, post_to_facebook - - -class FBOAuthToken(models.Model): - short_token = models.TextField() - long_token = models.TextField(null=True, blank=True) - expires = models.DateTimeField(blank=True) - created = models.DateTimeField(default=timezone.now) - - def __str__(self): - return str(self.expires) - - def long_token_link(self): - token_url = "https://graph.facebook.com/oauth/access_token?client_id=%s&client_secret=%s&grant_type=fb_exchange_token&fb_exchange_token=%s" % (settings.FACEBOOK_APP_ID, settings.FACEBOOK_APP_SECRET, self.short_token) - return token_url - - class Meta: - ordering = ('-expires',) - get_latest_by = 'expires' - - def save(self, *args, **kwargs): - self.expires = self.created + datetime.timedelta(60) - super(FBOAuthToken, self).save() - - -class Syndicate(models.Model): - name = models.CharField(max_length=200) - - def __str__(self): - return self.name - - -class SyndicatedItem(models.Model): - content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) - object_id = models.PositiveIntegerField() - content_object = GenericForeignKey('content_type', 'object_id') - syndicate = models.ManyToManyField(Syndicate) - publish_date = models.DateTimeField() - STATUS = ( - ('1', "Unsent"), - ('2', "Sent"), - ) - status = models.CharField(max_length=1, choices=STATUS, null=True) - rel_link = models.CharField(max_length=300, null=True, blank=True) - - def __str__(self): - return str(self.content_object) - - def syndicated_to(self): - return ','.join(str(synd) for synd in self.syndicate.all()) - - -@receiver(post_save, sender=SyndicatedItem) -def post_save_events(sender, update_fields, created, instance, **kwargs): - print(instance.status) - if instance.status == "1": - print("---------calling-----------") - for item in instance.syndicate.all(): - print(item.name) - if item.name == "Medium": - instance.rel_link = post_to_medium(instance.content_object) - instance.status = 2 - if item.name == "Facebook Instant Articles": - build_facebook_feed() - instance.status = 2 - if item.name == "Twitter": - print("calling function") - post_to_twitter(instance.content_object, instance.content_type.name) - if item.name == "Flickr": - if instance.content_type.name == "lux image": - post_photo_to_flickr(instance.content_object) - if item.name == "Facebook": - post_to_facebook(instance.content_object, instance.content_type.name) - post_save.disconnect(post_save_events, sender=SyndicatedItem) - instance.status = "2" - instance.save() - post_save.connect(post_save_events, sender=SyndicatedItem) diff --git a/app/syndication/syndicators.py b/app/syndication/syndicators.py deleted file mode 100644 index 5f8762c..0000000 --- a/app/syndication/syndicators.py +++ /dev/null @@ -1,123 +0,0 @@ -import os -from django.conf import settings -from django.test.client import Client - -from twython import Twython -from bs4 import BeautifulSoup -from medium import Client as MediumClient -import flickrapi -import facebook - -from photos.models import LuxImage - - -def absolute_urls_for_syndication(s): - soup = BeautifulSoup(s, "lxml") - for a in soup.find_all('a'): - if a['href'][:1] == "/": - a['href'] = "https://luxagraf.net%s" % a['href'] - return soup - - -def post_to_medium(item): - client = MediumClient(application_id=settings.MEDIUM_CLIENT_ID, application_secret=settings.MEDIUM_CLIENT_SECRET) - client.access_token = settings.MEDIUM_INT_TOKEN - user = client.get_current_user() - head = '

This was originally posted on my own site.

' % item.get_absolute_url() - body = "%s %s" % (head, absolute_urls_for_syndication(item.body_html)) - # Create a post. - post = client.create_post( - user_id=user["id"], - title=item.title, - content=body, - content_format="html", - publish_status="public", - canonical_url="https://luxagraf.net%s" % item.get_absolute_url(), - license="all-rights-reserved" - ) - return post["url"] - - -def build_facebook_feed(): - print("+++++++++++++building+++++++++++") - c = Client() - response = c.get('/iafeed.xml', HTTP_HOST='127.0.0.1') - f = open("%siafeed.xml" % settings.FLATFILES_ROOT, 'wb') - f.write(response.content) - f.close() - - -def post_to_twitter(obj, ctype): - print("content type is" + ctype) - t = Twython(settings.TWITTER_API_KEY, settings.TWITTER_API_SECRET, settings.TWITTER_ACCESS_TOKEN, settings.TWITTER_ACCESS_SECRET) - imgs = [] - if ctype == "lux image": - p = open(obj.get_largest_image(), 'rb') - if obj.caption: - status = obj.caption - else: - status = obj.title - response = t.upload_media(media=p) - imgs.append(response) - elif ctype == "lux note": - status = obj.body_markdown - # parse out images and send seperately - soup = BeautifulSoup(status, "lxml") - loop = 0 - for img in soup.find_all('img'): - src = img['src'].split("images/")[1] - i = LuxImage.objects.get(image__icontains=src) - p = open(i.get_largest_image(), 'rb') - response = t.upload_media(media=p) - imgs.append(response) - loop = loop+1 - if loop == 3: - break - for t in soup.find_all('img'): - t.replaceWith("") - # truncate message - if len(status) > 140: - try: - status = status.split("|")[0] + obj.get_absolute_url() - except: - status = status[:140] + obj.get_absolute_url() - print(status) - try: - geo = t.reverse_geocode(lat=obj.latitude, lon=obj.longitude, accuracy=1500, granularity="city") - geo_id = geo['result']['places'][0]['id'] - tweet = t.update_status(status=status, media_ids=[img['media_id'] for img in imgs], place_id=geo_id) - except: - try: - tweet = t.update_status(status=status, media_ids=[img['media_id'] for img in imgs]) - except: - tweet = t.update_status(status=status) - - -def post_photo_to_flickr(photo): - TOKEN_FILE = os.path.join(settings.PROJ_ROOT, "config/flickrToken") - token = open(TOKEN_FILE).read() - flickr = flickrapi.FlickrAPI(settings.FLICKR_API_KEY, settings.FLICKR_API_SECRET, token=token) - sent = flickr.upload(filename=photo.get_image_path_by_size("original"), title=photo.title, description=photo.caption) - photo_id = sent.find('photoid').text - photo.flickr_id = photo_id - try: - flickr.photos.geo.setLocation(photo_id=photo_id, lat=photo.latitude, lon=photo.longitude, accuracy=12) - except: - pass - - -def post_to_facebook(obj, ctype): - from syndication.models import FBOAuthToken - token = FBOAuthToken.objects.latest() - graph = facebook.GraphAPI(access_token=token.long_token, version='2.2') - if ctype == "lux image": - p = open(obj.get_largest_image(), 'rb') - if obj.caption: - message = obj.caption - else: - message = obj.title - try: - fb_response = graph.put_photo(p, message=message) - print(fb_response) - except facebook.GraphAPIError as e: - print('Something went wrong:', e.type, e.message) diff --git a/app/syndication/templatetags/__init__.py b/app/syndication/templatetags/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/app/syndication/templatetags/facebook_processor.py b/app/syndication/templatetags/facebook_processor.py deleted file mode 100644 index 973f863..0000000 --- a/app/syndication/templatetags/facebook_processor.py +++ /dev/null @@ -1,23 +0,0 @@ -from django import template -from bs4 import BeautifulSoup - -from syndication.syndicators import absolute_urls_for_syndication - -register = template.Library() - - -def wrap_image_tags(text): - soup = BeautifulSoup(text, 'lxml') - for img in soup.find_all('img'): - if img.parent.name != "figure": - new_tag = soup.new_tag('figure') - img.wrap(new_tag) - return soup - - -def facebook_processor(text): - ia = absolute_urls_for_syndication(text) - ia = wrap_image_tags(str(ia)[12:-14]) - return str(ia)[12:-14] - -register.filter('facebook_processor', facebook_processor) diff --git a/app/syndication/views.py b/app/syndication/views.py deleted file mode 100644 index e489846..0000000 --- a/app/syndication/views.py +++ /dev/null @@ -1,17 +0,0 @@ -from django.views.generic import ListView - -from .models import SyndicatedItem - - -class FacebookFeedView(ListView): - """ - Return a main entry and list of Entries in reverse chronological order - """ - queryset = SyndicatedItem.objects.filter(syndicate__name__exact="Facebook")[:16] - - def get_template_names(self): - return "fb-feed.xml" - - def render_to_response(self, context, **response_kwargs): - response_kwargs.update({'content_type': 'text/xml'}) - return super(FacebookFeedView, self).render_to_response(context, **response_kwargs) 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() diff --git a/app/unused_apps/ebay/__init__.py b/app/unused_apps/ebay/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/unused_apps/ebay/admin.py b/app/unused_apps/ebay/admin.py new file mode 100644 index 0000000..93bf87f --- /dev/null +++ b/app/unused_apps/ebay/admin.py @@ -0,0 +1,15 @@ +from django.contrib import admin + +from .models import Item, Price, TrackedItem + + +@admin.register(Item) +class ItemAdmin(admin.ModelAdmin): + list_display = ('name', 'currently_own', 'purchase_price') + + +@admin.register(TrackedItem) +class TrackedItemAdmin(admin.ModelAdmin): + list_display = ('title', 'admin_link', 'date_ending', 'get_latest_price', 'amount_desired' ) + list_filter = ('amount_desired',) + diff --git a/app/unused_apps/ebay/migrations/0001_initial.py b/app/unused_apps/ebay/migrations/0001_initial.py new file mode 100644 index 0000000..3d2d34e --- /dev/null +++ b/app/unused_apps/ebay/migrations/0001_initial.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-12-31 11:43 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Item', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('url', models.CharField(max_length=200)), + ('title', models.CharField(max_length=200)), + ('purchase_price', models.IntegerField()), + ('currently_own', models.BooleanField(default=False)), + ('sold', models.BooleanField(default=False)), + ('sale_price', models.IntegerField()), + ], + ), + migrations.CreateModel( + name='Price', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('date', models.DateTimeField()), + ('price', models.IntegerField()), + ], + ), + migrations.CreateModel( + name='TrackedItem', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('url', models.CharField(max_length=200)), + ('title', models.CharField(max_length=200)), + ], + ), + migrations.AddField( + model_name='price', + name='item', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='ebay.TrackedItem'), + ), + ] diff --git a/app/unused_apps/ebay/migrations/0002_auto_20161231_1401.py b/app/unused_apps/ebay/migrations/0002_auto_20161231_1401.py new file mode 100644 index 0000000..46f5a12 --- /dev/null +++ b/app/unused_apps/ebay/migrations/0002_auto_20161231_1401.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-12-31 14:01 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ebay', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='price', + name='date', + field=models.DateTimeField(blank=True), + ), + migrations.AlterField( + model_name='price', + name='price', + field=models.DecimalField(decimal_places=2, max_digits=6), + ), + ] diff --git a/app/unused_apps/ebay/migrations/0003_auto_20161231_1419.py b/app/unused_apps/ebay/migrations/0003_auto_20161231_1419.py new file mode 100644 index 0000000..1f05859 --- /dev/null +++ b/app/unused_apps/ebay/migrations/0003_auto_20161231_1419.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-12-31 14:19 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('ebay', '0002_auto_20161231_1401'), + ] + + operations = [ + migrations.AlterModelOptions( + name='price', + options={'get_latest_by': 'date', 'ordering': ('-date',)}, + ), + migrations.RenameField( + model_name='item', + old_name='title', + new_name='name', + ), + ] diff --git a/app/unused_apps/ebay/migrations/0004_trackeditem_date_ending.py b/app/unused_apps/ebay/migrations/0004_trackeditem_date_ending.py new file mode 100644 index 0000000..15f41e7 --- /dev/null +++ b/app/unused_apps/ebay/migrations/0004_trackeditem_date_ending.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-12-31 14:26 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('ebay', '0003_auto_20161231_1419'), + ] + + operations = [ + migrations.AddField( + model_name='trackeditem', + name='date_ending', + field=models.DateTimeField(default=django.utils.timezone.now), + ), + ] diff --git a/app/unused_apps/ebay/migrations/0005_auto_20161231_1444.py b/app/unused_apps/ebay/migrations/0005_auto_20161231_1444.py new file mode 100644 index 0000000..a7a48ac --- /dev/null +++ b/app/unused_apps/ebay/migrations/0005_auto_20161231_1444.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-12-31 14:44 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('ebay', '0004_trackeditem_date_ending'), + ] + + operations = [ + migrations.AlterModelOptions( + name='trackeditem', + options={'get_latest_by': 'date_ending', 'ordering': ('-date_ending', 'amount_desired')}, + ), + migrations.AddField( + model_name='trackeditem', + name='amount_desired', + field=models.IntegerField(choices=[(0, '1'), (1, '2'), (2, '3'), (3, '4'), (4, '5')], default=0), + ), + ] diff --git a/app/unused_apps/ebay/migrations/__init__.py b/app/unused_apps/ebay/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/unused_apps/ebay/models.py b/app/unused_apps/ebay/models.py new file mode 100644 index 0000000..089e0e4 --- /dev/null +++ b/app/unused_apps/ebay/models.py @@ -0,0 +1,84 @@ +import datetime +import re +from django.utils.encoding import force_text +from django.contrib.gis.db import models +from django.utils import timezone +from bs4 import BeautifulSoup +import requests + +class Item(models.Model): + name = models.CharField(max_length=200) + purchase_price = models.IntegerField() + url = models.CharField(max_length=200) + currently_own = models.BooleanField(blank=True, default=False) + sold = models.BooleanField(blank=True, default=False) + sale_price = models.IntegerField() + + def save(self, **kwargs): + super(Item, self).save() + + def __str__(self): + return self.name + + +class TrackedItem(models.Model): + title = models.CharField(max_length=200) + url = models.CharField(max_length=200) + DESIRE = ( + (0, '1'), + (1, '2'), + (2, '3'), + (3, '4'), + (4, '5'), + ) + amount_desired = models.IntegerField(choices=DESIRE, default=0) + date_ending = models.DateTimeField(default=timezone.now) + + class Meta: + ordering = ('date_ending', 'amount_desired') + get_latest_by = 'date_ending' + + @property + def get_latest_price(self): + return self.price_set.latest().price + + def admin_link(self): + return force_text('View Auction page' % (self.url)) + admin_link.allow_tags = True + admin_link.short_description = 'Link' + + def __str__(self): + return self.title + + def save(self, **kwargs): + super(TrackedItem, self).save() + + +class Price(models.Model): + date = models.DateTimeField(blank=True) + price = models.DecimalField(max_digits=6, decimal_places=2) + item = models.ForeignKey(TrackedItem) + + class Meta: + ordering = ('-date',) + get_latest_by = 'date' + + def __str__(self): + return str(self.date) + + def save(self, **kwargs): + if not self.pk: + self.date = datetime.datetime.now() + super(Price, self).save() + + +def update_tracked_item_price(item): + r = requests.get(item.url) + soup = BeautifulSoup(r.text, "lxml") + numbers = re.compile('\d+(?:\.\d+)?') + price = soup.find(itemprop="price").get_text() + price = numbers.findall(price)[0] + l, created = Price.objects.get_or_create( + price=price, + item=item + ) diff --git a/app/unused_apps/ebay/update_price.py b/app/unused_apps/ebay/update_price.py new file mode 100755 index 0000000..b8b4c8c --- /dev/null +++ b/app/unused_apps/ebay/update_price.py @@ -0,0 +1,17 @@ +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() +import datetime +from ebay.models import TrackedItem, update_tracked_item_price +items = TrackedItem.objects.filter(date_ending__gte=datetime.datetime.now()) +for item in items: + update_tracked_item_price(item) diff --git a/app/unused_apps/guide/__init__.py b/app/unused_apps/guide/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/unused_apps/guide/admin.py b/app/unused_apps/guide/admin.py new file mode 100644 index 0000000..dfdf45e --- /dev/null +++ b/app/unused_apps/guide/admin.py @@ -0,0 +1,61 @@ +from django.contrib import admin +from guide.models import Guide +from django.contrib.gis.admin import OSMGeoAdmin + + +class GuideAdmin(OSMGeoAdmin): + list_display = ( + 'title', + 'pub_date', + 'template_name', + 'status', + 'location', + 'photo_gallery' + ) + search_fields = ['title', 'body_markdown'] + prepopulated_fields = {"slug": ('title',)} + list_filter = ('pub_date', 'status', 'location__state__country__lux_region', 'location') + fieldsets = ( + ('Note', { + 'fields': ( + 'title', + 'body_markdown', + 'location', + 'pub_date', + 'status', + 'slug', + 'photo_gallery' + ), + 'classes': ( + 'show', + 'extrapretty', + 'wide' + ) + }), + ('Extra', { + 'fields': ( + 'dek', + 'meta_description', + 'template_name', + 'image', + 'thumbnail' + ), + 'classes': ( + 'collapse', + 'wide' + ) + }), + ) + + # options for OSM map Using custom ESRI topo map + default_lon = -9285175 + default_lat = 4025046 + default_zoom = 6 + units = True + scrollable = False + map_width = 700 + map_height = 425 + map_template = 'gis/admin/osm.html' + openlayers_url = '/static/admin/js/OpenLayers.js' + +admin.site.register(Guide, GuideAdmin) diff --git a/app/unused_apps/guide/models.py b/app/unused_apps/guide/models.py new file mode 100644 index 0000000..7f0d501 --- /dev/null +++ b/app/unused_apps/guide/models.py @@ -0,0 +1,129 @@ +import datetime +from django.contrib.gis.db import models +from django.conf import settings +from django.contrib.sitemaps import Sitemap +from django.contrib.syndication.views import Feed +from PIL import Image + +from taggit.managers import TaggableManager +from locations.models import Location +from jrnl.models import Entry +from photos.models import PhotoGallery + +from utils.widgets import markdown_to_html + + +def get_upload_path(self, filename): + return "images/guide-images/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) + + +def get_tn_path(self, filename): + return "images/guide-thumbnail/%s/%s" % (datetime.datetime.today().strftime("%Y"), filename) + + +def image_url_replace(str): + str = str.replace('[[base_url]]', settings.IMAGES_URL) + return str + + +def markdown_processor(md): + return markdown_to_html(md) + + +class Guide(models.Model): + title = models.CharField(max_length=200) + slug = models.SlugField(unique_for_date='pub_date') + entry = models.ForeignKey(Entry, null=True, blank=True) + body_html = models.TextField(blank=True) + body_markdown = models.TextField() + dek = models.TextField(null=True, blank=True) + pub_date = models.DateTimeField('Date published') + location = models.ForeignKey(Location, null=True, blank=True) + PUB_STATUS = ( + (0, 'Draft'), + (1, 'Published'), + ) + status = models.IntegerField(choices=PUB_STATUS, default=0) + photo_gallery = models.ForeignKey(PhotoGallery, blank=True, null=True, verbose_name='photo set') + meta_description = models.CharField(max_length=256, null=True, blank=True) + TEMPLATES = ( + (0, 'single'), + (1, 'double'), + (2, 'single-dark'), + (3, 'double-dark'), + ) + template_name = models.IntegerField(choices=TEMPLATES, default=0) + tags = TaggableManager(blank=True) + image = models.FileField(upload_to=get_upload_path, null=True, blank=True) + thumbnail = models.FileField(upload_to=get_tn_path, null=True, blank=True) + + @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 + + class Meta: + ordering = ('-pub_date',) + get_latest_by = 'pub_date' + verbose_name_plural = 'entries' + + def __unicode__(self): + return self.title + + def get_absolute_url(self): + if self.location: + return "/travel-guide/location/%s/%s/" % (self.location.slug, self.slug) + else: + return "/travel-guide/%s/" % (self.slug) + + def get_thumbnail_url(self): + image_dir, img = self.thumbnail.url.split('guide-thumbnail/')[1].split('/') + return '%sguide-thumbnail/%s/%s' % (settings.IMAGES_URL, image_dir, img) + + def get_image_url(self): + image_dir, img = self.image.url.split('guide-images/')[1].split('/') + return '%sguide-images/%s/%s' % (settings.IMAGES_URL, image_dir, img) + + def save(self): + if self.image: + img = Image.open(self.image) + self.image_width, self.image_height = img.size + img = Image.open(self.thumbnail) + self.thumb_width, self.thumb_height = img.size + md = image_url_replace(self.body_markdown) + self.body_html = markdown_to_html(md) + self.dek = markdown_to_html(self.dek) + super(Guide, self).save() + + +class GuideSitemap(Sitemap): + changefreq = "never" + priority = 1.0 + + def items(self): + return Entry.objects.filter(status=1) + + def lastmod(self, obj): + return obj.pub_date + + +class GuideFull(Feed): + title = "Luxagraf: Topographical Writings" + link = "/writing/" + description = "Latest postings to luxagraf.net" + description_template = 'feeds/blog_description.html' + + def items(self): + return Entry.objects.filter(status__exact=1).order_by('-pub_date')[:10] + + +#from django.dispatch import dispatcher +#from django.db.models import signals + +#signals.post_save.connect(update_recent, sender=Entry) + diff --git a/app/unused_apps/guide/urls.py b/app/unused_apps/guide/urls.py new file mode 100644 index 0000000..e701d3e --- /dev/null +++ b/app/unused_apps/guide/urls.py @@ -0,0 +1,13 @@ +from django.conf.urls import * +from django.views.generic.base import RedirectView + +from . import views + +urlpatterns = [ + url(r'location/(?P[-\w]+)/(?P[-\w]+)/$', views.guide_detail), + url(r'location/(?P[-\w]+)/$', views.guide_list_by_location), + url(r'location/$', views.location_list), + url(r'(?P\d+)/$', views.guide_list), + url(r'(?P[-\w]+)/$', views.guide_detail), + url(r'', RedirectView.as_view(url="/travel-guide/1/")), +] diff --git a/app/unused_apps/guide/views.py b/app/unused_apps/guide/views.py new file mode 100644 index 0000000..c22a6b3 --- /dev/null +++ b/app/unused_apps/guide/views.py @@ -0,0 +1,35 @@ +from django.shortcuts import render_to_response, get_object_or_404 +from django.template import RequestContext + +from guide.models import Guide + + +def guide_list(request, page): + """List of all guides""" + request.page_url = "/guide/%d/" + request.page = int(page) + context = { + 'object_list': Guide.objects.filter(status__exact=1).order_by('-pub_date').select_related(), + 'page': page, + } + return render_to_response("archives/guide.html", context, context_instance=RequestContext(request)) + + +def guide_list_by_location(request, location): + context = { + "object_list": Guide.objects.filter(location__slug__exact=location), + } + return render_to_response("archives/guide.html", context, context_instance=RequestContext(request)) + + +def location_list(request): + """List of all locations with guides""" + context = { + "object_list": Guide.objects.filter(status__exact=1).order_by('-pub_date').select_related() + } + return render_to_response("archives/guide.html", context, context_instance=RequestContext(request)) + + +def guide_detail(request, slug, location=None): + obj = get_object_or_404(Guide, slug__exact=slug) + return render_to_response('details/guide.html', {'object': obj}, context_instance=RequestContext(request)) diff --git a/app/unused_apps/syndication/__init__.py b/app/unused_apps/syndication/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/unused_apps/syndication/admin.py b/app/unused_apps/syndication/admin.py new file mode 100644 index 0000000..b873eb7 --- /dev/null +++ b/app/unused_apps/syndication/admin.py @@ -0,0 +1,20 @@ +from django.contrib import admin + +from .models import Syndicate, SyndicatedItem, FBOAuthToken + + +@admin.register(FBOAuthToken) +class FBOAuthTokenAdmin(admin.ModelAdmin): + list_display = ('__str__', 'expires',) + pass + + +@admin.register(Syndicate) +class SyndicateAdmin(admin.ModelAdmin): + pass + + +@admin.register(SyndicatedItem) +class SyndicatedItemAdmin(admin.ModelAdmin): + list_display = ('__str__', 'syndicated_to',) + pass diff --git a/app/unused_apps/syndication/migrations/0001_initial.py b/app/unused_apps/syndication/migrations/0001_initial.py new file mode 100644 index 0000000..9643d51 --- /dev/null +++ b/app/unused_apps/syndication/migrations/0001_initial.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-03-29 10:07 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ] + + operations = [ + migrations.CreateModel( + name='Syndicate', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200)), + ], + ), + migrations.CreateModel( + name='SyndicatedItem', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('object_id', models.PositiveIntegerField()), + ('publish_date', models.DateTimeField()), + ('status', models.CharField(blank=True, choices=[('1', 'Unsent'), ('2', 'Sent')], max_length=1, null=True)), + ('rel_link', models.CharField(blank=True, max_length=300, null=True)), + ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')), + ('syndicate', models.ManyToManyField(to='syndication.Syndicate')), + ], + ), + ] diff --git a/app/unused_apps/syndication/migrations/0002_auto_20160628_2149.py b/app/unused_apps/syndication/migrations/0002_auto_20160628_2149.py new file mode 100644 index 0000000..51812bf --- /dev/null +++ b/app/unused_apps/syndication/migrations/0002_auto_20160628_2149.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-06-28 21:49 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('syndication', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='FBOAuthToken', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('short_token', models.TextField()), + ('long_token', models.TextField(blank=True, null=True)), + ('expires', models.DateTimeField(blank=True)), + ('created', models.DateTimeField(default=django.utils.timezone.now)), + ], + ), + migrations.AlterField( + model_name='syndicateditem', + name='status', + field=models.CharField(choices=[('1', 'Unsent'), ('2', 'Sent')], max_length=1, null=True), + ), + ] diff --git a/app/unused_apps/syndication/migrations/0003_auto_20161023_2014.py b/app/unused_apps/syndication/migrations/0003_auto_20161023_2014.py new file mode 100644 index 0000000..2b311fb --- /dev/null +++ b/app/unused_apps/syndication/migrations/0003_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 = [ + ('syndication', '0002_auto_20160628_2149'), + ] + + operations = [ + migrations.AlterModelOptions( + name='fboauthtoken', + options={'get_latest_by': 'expires', 'ordering': ('-expires',)}, + ), + ] diff --git a/app/unused_apps/syndication/migrations/__init__.py b/app/unused_apps/syndication/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/unused_apps/syndication/models.py b/app/unused_apps/syndication/models.py new file mode 100644 index 0000000..c348c1b --- /dev/null +++ b/app/unused_apps/syndication/models.py @@ -0,0 +1,86 @@ +from django.db import models +from django.utils import timezone +from django.conf import settings +import datetime +from django.contrib.contenttypes.models import ContentType +from django.contrib.contenttypes.fields import GenericForeignKey +from django.db.models.signals import post_save +from django.dispatch import receiver + +from .syndicators import post_to_medium, build_facebook_feed, post_to_twitter, post_photo_to_flickr, post_to_facebook + + +class FBOAuthToken(models.Model): + short_token = models.TextField() + long_token = models.TextField(null=True, blank=True) + expires = models.DateTimeField(blank=True) + created = models.DateTimeField(default=timezone.now) + + def __str__(self): + return str(self.expires) + + def long_token_link(self): + token_url = "https://graph.facebook.com/oauth/access_token?client_id=%s&client_secret=%s&grant_type=fb_exchange_token&fb_exchange_token=%s" % (settings.FACEBOOK_APP_ID, settings.FACEBOOK_APP_SECRET, self.short_token) + return token_url + + class Meta: + ordering = ('-expires',) + get_latest_by = 'expires' + + def save(self, *args, **kwargs): + self.expires = self.created + datetime.timedelta(60) + super(FBOAuthToken, self).save() + + +class Syndicate(models.Model): + name = models.CharField(max_length=200) + + def __str__(self): + return self.name + + +class SyndicatedItem(models.Model): + content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) + object_id = models.PositiveIntegerField() + content_object = GenericForeignKey('content_type', 'object_id') + syndicate = models.ManyToManyField(Syndicate) + publish_date = models.DateTimeField() + STATUS = ( + ('1', "Unsent"), + ('2', "Sent"), + ) + status = models.CharField(max_length=1, choices=STATUS, null=True) + rel_link = models.CharField(max_length=300, null=True, blank=True) + + def __str__(self): + return str(self.content_object) + + def syndicated_to(self): + return ','.join(str(synd) for synd in self.syndicate.all()) + + +@receiver(post_save, sender=SyndicatedItem) +def post_save_events(sender, update_fields, created, instance, **kwargs): + print(instance.status) + if instance.status == "1": + print("---------calling-----------") + for item in instance.syndicate.all(): + print(item.name) + if item.name == "Medium": + instance.rel_link = post_to_medium(instance.content_object) + instance.status = 2 + if item.name == "Facebook Instant Articles": + build_facebook_feed() + instance.status = 2 + if item.name == "Twitter": + print("calling function") + post_to_twitter(instance.content_object, instance.content_type.name) + if item.name == "Flickr": + if instance.content_type.name == "lux image": + post_photo_to_flickr(instance.content_object) + if item.name == "Facebook": + post_to_facebook(instance.content_object, instance.content_type.name) + post_save.disconnect(post_save_events, sender=SyndicatedItem) + instance.status = "2" + instance.save() + post_save.connect(post_save_events, sender=SyndicatedItem) diff --git a/app/unused_apps/syndication/syndicators.py b/app/unused_apps/syndication/syndicators.py new file mode 100644 index 0000000..5f8762c --- /dev/null +++ b/app/unused_apps/syndication/syndicators.py @@ -0,0 +1,123 @@ +import os +from django.conf import settings +from django.test.client import Client + +from twython import Twython +from bs4 import BeautifulSoup +from medium import Client as MediumClient +import flickrapi +import facebook + +from photos.models import LuxImage + + +def absolute_urls_for_syndication(s): + soup = BeautifulSoup(s, "lxml") + for a in soup.find_all('a'): + if a['href'][:1] == "/": + a['href'] = "https://luxagraf.net%s" % a['href'] + return soup + + +def post_to_medium(item): + client = MediumClient(application_id=settings.MEDIUM_CLIENT_ID, application_secret=settings.MEDIUM_CLIENT_SECRET) + client.access_token = settings.MEDIUM_INT_TOKEN + user = client.get_current_user() + head = '

This was originally posted on my own site.

' % item.get_absolute_url() + body = "%s %s" % (head, absolute_urls_for_syndication(item.body_html)) + # Create a post. + post = client.create_post( + user_id=user["id"], + title=item.title, + content=body, + content_format="html", + publish_status="public", + canonical_url="https://luxagraf.net%s" % item.get_absolute_url(), + license="all-rights-reserved" + ) + return post["url"] + + +def build_facebook_feed(): + print("+++++++++++++building+++++++++++") + c = Client() + response = c.get('/iafeed.xml', HTTP_HOST='127.0.0.1') + f = open("%siafeed.xml" % settings.FLATFILES_ROOT, 'wb') + f.write(response.content) + f.close() + + +def post_to_twitter(obj, ctype): + print("content type is" + ctype) + t = Twython(settings.TWITTER_API_KEY, settings.TWITTER_API_SECRET, settings.TWITTER_ACCESS_TOKEN, settings.TWITTER_ACCESS_SECRET) + imgs = [] + if ctype == "lux image": + p = open(obj.get_largest_image(), 'rb') + if obj.caption: + status = obj.caption + else: + status = obj.title + response = t.upload_media(media=p) + imgs.append(response) + elif ctype == "lux note": + status = obj.body_markdown + # parse out images and send seperately + soup = BeautifulSoup(status, "lxml") + loop = 0 + for img in soup.find_all('img'): + src = img['src'].split("images/")[1] + i = LuxImage.objects.get(image__icontains=src) + p = open(i.get_largest_image(), 'rb') + response = t.upload_media(media=p) + imgs.append(response) + loop = loop+1 + if loop == 3: + break + for t in soup.find_all('img'): + t.replaceWith("") + # truncate message + if len(status) > 140: + try: + status = status.split("|")[0] + obj.get_absolute_url() + except: + status = status[:140] + obj.get_absolute_url() + print(status) + try: + geo = t.reverse_geocode(lat=obj.latitude, lon=obj.longitude, accuracy=1500, granularity="city") + geo_id = geo['result']['places'][0]['id'] + tweet = t.update_status(status=status, media_ids=[img['media_id'] for img in imgs], place_id=geo_id) + except: + try: + tweet = t.update_status(status=status, media_ids=[img['media_id'] for img in imgs]) + except: + tweet = t.update_status(status=status) + + +def post_photo_to_flickr(photo): + TOKEN_FILE = os.path.join(settings.PROJ_ROOT, "config/flickrToken") + token = open(TOKEN_FILE).read() + flickr = flickrapi.FlickrAPI(settings.FLICKR_API_KEY, settings.FLICKR_API_SECRET, token=token) + sent = flickr.upload(filename=photo.get_image_path_by_size("original"), title=photo.title, description=photo.caption) + photo_id = sent.find('photoid').text + photo.flickr_id = photo_id + try: + flickr.photos.geo.setLocation(photo_id=photo_id, lat=photo.latitude, lon=photo.longitude, accuracy=12) + except: + pass + + +def post_to_facebook(obj, ctype): + from syndication.models import FBOAuthToken + token = FBOAuthToken.objects.latest() + graph = facebook.GraphAPI(access_token=token.long_token, version='2.2') + if ctype == "lux image": + p = open(obj.get_largest_image(), 'rb') + if obj.caption: + message = obj.caption + else: + message = obj.title + try: + fb_response = graph.put_photo(p, message=message) + print(fb_response) + except facebook.GraphAPIError as e: + print('Something went wrong:', e.type, e.message) diff --git a/app/unused_apps/syndication/templatetags/__init__.py b/app/unused_apps/syndication/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app/unused_apps/syndication/templatetags/facebook_processor.py b/app/unused_apps/syndication/templatetags/facebook_processor.py new file mode 100644 index 0000000..973f863 --- /dev/null +++ b/app/unused_apps/syndication/templatetags/facebook_processor.py @@ -0,0 +1,23 @@ +from django import template +from bs4 import BeautifulSoup + +from syndication.syndicators import absolute_urls_for_syndication + +register = template.Library() + + +def wrap_image_tags(text): + soup = BeautifulSoup(text, 'lxml') + for img in soup.find_all('img'): + if img.parent.name != "figure": + new_tag = soup.new_tag('figure') + img.wrap(new_tag) + return soup + + +def facebook_processor(text): + ia = absolute_urls_for_syndication(text) + ia = wrap_image_tags(str(ia)[12:-14]) + return str(ia)[12:-14] + +register.filter('facebook_processor', facebook_processor) diff --git a/app/unused_apps/syndication/views.py b/app/unused_apps/syndication/views.py new file mode 100644 index 0000000..e489846 --- /dev/null +++ b/app/unused_apps/syndication/views.py @@ -0,0 +1,17 @@ +from django.views.generic import ListView + +from .models import SyndicatedItem + + +class FacebookFeedView(ListView): + """ + Return a main entry and list of Entries in reverse chronological order + """ + queryset = SyndicatedItem.objects.filter(syndicate__name__exact="Facebook")[:16] + + def get_template_names(self): + return "fb-feed.xml" + + def render_to_response(self, context, **response_kwargs): + response_kwargs.update({'content_type': 'text/xml'}) + return super(FacebookFeedView, self).render_to_response(context, **response_kwargs) -- cgit v1.2.3-70-g09d2