diff options
author | luxagraf <sng@luxagraf.net> | 2023-07-28 13:39:02 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2023-07-28 13:39:02 -0500 |
commit | 9a620cf42bf1fe6977e378bd834b41ff4a593dde (patch) | |
tree | cf41a0582681cecaf88a30bfe409f9c2be57972a /bak/unused_apps/ebay/models.py | |
parent | 6e5897117124cd60ae81efb1574c6347f48e60e5 (diff) |
main: removed some apps I wasn't using and added bak to git to preserve
a copy of old apps
Diffstat (limited to 'bak/unused_apps/ebay/models.py')
-rw-r--r-- | bak/unused_apps/ebay/models.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/bak/unused_apps/ebay/models.py b/bak/unused_apps/ebay/models.py new file mode 100644 index 0000000..089e0e4 --- /dev/null +++ b/bak/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 + ) |