diff options
Diffstat (limited to 'app/deals')
-rw-r--r-- | app/deals/admin.py | 27 | ||||
-rw-r--r-- | app/deals/models.py | 140 | ||||
-rw-r--r-- | app/deals/urls.py | 10 | ||||
-rw-r--r-- | app/deals/views.py | 9 |
4 files changed, 173 insertions, 13 deletions
diff --git a/app/deals/admin.py b/app/deals/admin.py index 9e37d67..3686309 100644 --- a/app/deals/admin.py +++ b/app/deals/admin.py @@ -4,12 +4,12 @@ from django.contrib.gis.admin import OSMGeoAdmin from django.contrib.contenttypes.admin import GenericStackedInline from django_admin_listfilter_dropdown.filters import DropdownFilter, RelatedDropdownFilter, ChoiceDropdownFilter -from .models import Deal, Brand +from .models import Deal, Brand, MyDeal @admin.register(Deal) class DealAdmin(OSMGeoAdmin): - list_display = ('title', 'brand', 'category', 'deal_price', 'original_price', 'discount_percent', 'promo_type', 'amazon_link', 'search_ccc', 'search_wired', 'get_airtable_code') + list_display = ('asin', 'title', 'brand', 'category', 'deal_price', 'original_price', 'discount_percent', 'promo_type', 'amazon_link', 'search_ccc', 'search_wired', 'get_airtable_code') search_fields = ['brand__name', 'title', ] list_filter = ('category', 'promo_type', ('brand_str', DropdownFilter),) @@ -19,3 +19,26 @@ class BrandAdmin(OSMGeoAdmin): list_display = ('name',) search_fields = ['name' ] + +@admin.register(MyDeal) +class MyDealAdmin(OSMGeoAdmin): + list_display = ('title', 'blurb', 'amazon_link', 'search_ccc', 'search_wired') + search_fields = ['title', ] + list_filter = () + fieldsets = ( + ('Base', { + 'fields': ( + 'title', + 'blurb', + ('retailer', 'asin'), + 'url', + 'body', + ), + 'classes': ( + 'show', + 'extrapretty', + 'wide' + ) + } + ), + ) diff --git a/app/deals/models.py b/app/deals/models.py index 0d58367..a4fd875 100644 --- a/app/deals/models.py +++ b/app/deals/models.py @@ -61,6 +61,41 @@ class Deal(models.Model): return format_html("<a target='_blank' href='https://camelcamelcamel.com/product/%s'>Deal?</a>" % (self.asin)) admin_link.short_description = 'Link' + + +class MyDeal(models.Model): + title = models.CharField(max_length=200, blank=True, null=True) + lookup_title = models.CharField(max_length=200, blank=True, null=True) + asin = models.CharField(max_length=200, blank=True, null=True) + brand = models.CharField(max_length=200, blank=True, null=True) + retailer = models.CharField(max_length=200, blank=True, null=True) + secondary_retailer = models.CharField(max_length=200, blank=True, null=True) + tertiary_retailer = models.CharField(max_length=200, blank=True, null=True) + url = models.CharField(max_length=200) + secondary_url = models.CharField(max_length=200, blank=True, null=True) + tertiary_url = models.CharField(max_length=200, blank=True, null=True) + body = models.TextField(null=True, blank=True) + blurb = models.TextField(null=True) + + class Meta: + ordering = ('title',) + + def __str__(self): + return self.title + + def amazon_link(self): + return format_html('<a target="_blank" href="%s">%s</a>' % (self.url, self.asin)) + admin_link.short_description = 'Link' + + def search_wired(self): + term = "https://www.google.com/search?q=%s" % (str(self.lookup_title)) + term = term+"+site%3Awired.com" + return format_html("<a target='_blank' href='%s'>wired search</a>" % (term)) + admin_link.short_description = 'Link' + + def search_ccc(self): + return format_html("<a target='_blank' href='https://camelcamelcamel.com/product/%s'>Deal?</a>" % (self.asin)) + admin_link.short_description = 'Link' """ @@ -145,17 +180,16 @@ with open(path) as f: _, created = Deal.objects.get_or_create( print(row) asin=row[0], - cateogry=row[1], - brand=row[2], - title=row[3], - prime_only=row[4], - promo_type=row[5], - deal_price= row[9], - original_price = row[10], - discount_percent=row[11], - url=row[12], + cateogry="New", + brand=row[7], + title=row[18], + prime_only=row[19], + promo_type=row[21], + deal_price= row[29], + original_price = row[31], + discount_percent=row[32], + url=row[34], ) - print(row[0], row[1], row[2], row[4],row[5],row[6],row[10],row[13],row[14]) title, prime_only, promo_type, deal_price, discount_percent, url) @@ -174,3 +208,89 @@ with open(path) as f: # creates a tuple of the new object or # current object and a boolean of if it was created """ + +""" + +parse airtable csv: + +import tldextract, csv +path = '' + +with open(path) as f: + reader = csv.reader(f) + count = 0 + for row in reader: + if count > 0: + domain = tldextract.extract(row[2]) + retailer = domain.domain.capitalize() + d = '#### [%s](%s)\n\n+++button-group\n\n[%s](%s "%s"){: target="_blank"}\n\n+++\n\n%s\n\n' %(str(row[0]).strip(), row[2], retailer, row[2], retailer, row[4]) + with open('out.txt', 'a') as the_file: + the_file.write(d) + print(d) + count = count+1 + + +import tldextract, csv +path = '' + +with open(path) as f: + reader = csv.reader(f) + count = 0 + for row in reader: + if count > 0: + domain = tldextract.extract(row[2]) + retailer = domain.domain.capitalize() + title = str(row[0].strip()) + try: + stitle = title.split('for')[0] + except: + stitle=title + try: + asin = str(row[2]).split("/dp/")[1] + except: + asin = '' + d, created = MyDeal.objects.get_or_create( + title = str(row[0].strip()), + lookup_title = stitle, + asin = asin, + retailer = retailer, + url = str(row[2].strip()) + ) + if not created: + d.body = row[4] + d.save() + count = count+1 + + + + ++++button-group + +[Amazon]({{object.url}} "Amazon"){: target="_blank"} + ++++ +""" + +""" +asin = 3 +deal_type = 4 +name = 6 +url = 7 +deal price = 9 +price = 8 +percent_discount_str = 10 +prime only = 11 + + + + +from selenium import webdriver +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.common.by import By + +driver = webdriver.Firefox() +driver.get("http://www.python.org") + + + +""" diff --git a/app/deals/urls.py b/app/deals/urls.py index 2a9bf4a..8ca1fca 100644 --- a/app/deals/urls.py +++ b/app/deals/urls.py @@ -6,6 +6,16 @@ app_name = "deals" urlpatterns = [ path( + r'mydeals', + views.MyDealListView.as_view(), + name="detail" + ), + path( + r'mydealsnew', + views.MyDealLapListView.as_view(), + name="detail" + ), + path( r'<str:pk>', views.DealDetailView.as_view(), name="detail" diff --git a/app/deals/views.py b/app/deals/views.py index c615bd8..10b02c9 100644 --- a/app/deals/views.py +++ b/app/deals/views.py @@ -1,7 +1,14 @@ from django.views.generic import DetailView, ListView -from .models import Deal +from .models import Deal, MyDeal class DealDetailView(DetailView): model = Deal + +class MyDealListView(ListView): + model = MyDeal + +class MyDealLapListView(ListView): + model = MyDeal + queryset = MyDeal.objects.filter(asin="newbest") |