diff options
Diffstat (limited to 'app/unused_apps/ebay')
-rw-r--r-- | app/unused_apps/ebay/__init__.py | 0 | ||||
-rw-r--r-- | app/unused_apps/ebay/admin.py | 15 | ||||
-rw-r--r-- | app/unused_apps/ebay/migrations/0001_initial.py | 50 | ||||
-rw-r--r-- | app/unused_apps/ebay/migrations/0002_auto_20161231_1401.py | 25 | ||||
-rw-r--r-- | app/unused_apps/ebay/migrations/0003_auto_20161231_1419.py | 24 | ||||
-rw-r--r-- | app/unused_apps/ebay/migrations/0004_trackeditem_date_ending.py | 21 | ||||
-rw-r--r-- | app/unused_apps/ebay/migrations/0005_auto_20161231_1444.py | 24 | ||||
-rw-r--r-- | app/unused_apps/ebay/migrations/__init__.py | 0 | ||||
-rw-r--r-- | app/unused_apps/ebay/models.py | 84 | ||||
-rwxr-xr-x | app/unused_apps/ebay/update_price.py | 17 |
10 files changed, 260 insertions, 0 deletions
diff --git a/app/unused_apps/ebay/__init__.py b/app/unused_apps/ebay/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/unused_apps/ebay/__init__.py 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 --- /dev/null +++ b/app/unused_apps/ebay/migrations/__init__.py 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('<a href="%s">View Auction page</a>' % (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) |