diff options
Diffstat (limited to 'app/deals/models.py')
-rw-r--r-- | app/deals/models.py | 116 |
1 files changed, 103 insertions, 13 deletions
diff --git a/app/deals/models.py b/app/deals/models.py index a4fd875..4f38cd1 100644 --- a/app/deals/models.py +++ b/app/deals/models.py @@ -30,6 +30,8 @@ class Deal(models.Model): discount_percent_str = models.CharField(max_length=20, null=True) discount_percent = models.FloatField(null=True) url = models.CharField(max_length=200) + deal_start_date = models.DateTimeField(null=True) + deal_end_date = models.DateTimeField(null=True) class Meta: ordering = ('title',) @@ -62,6 +64,39 @@ class Deal(models.Model): admin_link.short_description = 'Link' +class REIDeal(models.Model): + brand_str = models.CharField(max_length=200) + category = models.CharField(max_length=200) + title = models.CharField(max_length=200, blank=True, null=True) + deal_price = models.CharField(max_length=20, null=True) + original_price = models.CharField(max_length=20, null=True) + discount_percent_str = models.CharField(max_length=20, null=True) + url = models.CharField(max_length=200) + generate_deal = models.BooleanField(default=False) + + class Meta: + ordering = ('title',) + + + def get_deal_price_pretty(self): + try: + return "{:.0f}".format(Decimal(self.deal_price)) + except: + return None + + def dollars_off(self): + try: + return "{:.0f}".format(Decimal(self.original_price) - Decimal(self.deal_price)) + except: + return None + + def rei_link(self): + return format_html('<a target="_blank" href="https://%s">REI</a>' % (self.url)) + admin_link.short_description = 'Link' + + def __str__(self): + return self.title + class MyDeal(models.Model): title = models.CharField(max_length=200, blank=True, null=True) @@ -76,6 +111,7 @@ class MyDeal(models.Model): tertiary_url = models.CharField(max_length=200, blank=True, null=True) body = models.TextField(null=True, blank=True) blurb = models.TextField(null=True) + added = models.BooleanField(default=False) class Meta: ordering = ('title',) @@ -98,6 +134,9 @@ class MyDeal(models.Model): admin_link.short_description = 'Link' """ +for deal in Deal.objects.all(): + if deal.promo_type == "Lightning Deal": + deal.delete() with open(path) as f: reader = csv.reader(f) @@ -116,6 +155,7 @@ with open(path) as f: import csv +from datetime import datetime path = "pdelectronicsdata.csv" with open(path) as f: reader = csv.reader(f) @@ -123,21 +163,23 @@ with open(path) as f: for row in reader: if count > 0: print(row) - if row[4] == "Y": + if row[21] == "Y": prime = True else: prime = False _, created = Deal.objects.get_or_create( asin=row[0], - category=row[1], - brand_str=row[2], - title=row[3], + category=row[8], + brand_str=row[10], + title=row[1], prime_only=prime, - promo_type=row[5], - deal_price= row[9], - original_price = row[10], - discount_percent_str=row[12], - url=row[13], + promo_type=row[23], + deal_price= row[29], + original_price = row[30], + discount_percent_str=row[35], + url=row[42], + deal_start_date=datetime.strptime(row[24], "%m/%d/%Y") + deal_end_date=datetime.strptime(row[25], "%m/%d/%Y") ) count = count+1 @@ -254,11 +296,39 @@ with open(path) as f: lookup_title = stitle, asin = asin, retailer = retailer, - url = str(row[2].strip()) + url = str(row[2].strip()), + body = row[4] + ) + count = count+1 + + + +import csv +path = "rei.csv" +with open(path) as f: + reader = csv.reader(f) + count = 0 + for row in reader: + if count > 0: + print(row) + try: + + if row[4] == "Y": + prime = True + else: + prime = False + _, created = Deal.objects.get_or_create( + asin=row[0], + category=row[1], + brand_str=row[2], + title=row[3], + prime_only=prime, + promo_type=row[5], + deal_price= row[9], + original_price = row[10], + discount_percent_str=row[12], + url=row[13], ) - if not created: - d.body = row[4] - d.save() count = count+1 @@ -294,3 +364,23 @@ driver.get("http://www.python.org") """ + +""" + +REI Importer + + +with open(path) as f: + reader = csv.reader(f) + count = 0 + for row in reader: + _, created = REIDeal.objects.get_or_create( + category=row[3], + brand_str=row[5], + title=row[8], + deal_price= row[12], + original_price = row[11], + discount_percent_=row[13], + url=row[15], + ) +""" |