Spaces:
Runtime error
Runtime error
Commit
·
c9e6491
1
Parent(s):
d52fe98
Update scraper/views.py
Browse files- scraper/views.py +32 -2
scraper/views.py
CHANGED
|
@@ -4,7 +4,13 @@ from .utils.WallmartScraper import WallmartScraper
|
|
| 4 |
from .utils.SephoraScraper import SephoraScraper
|
| 5 |
from .utils.UltaScraper import UltaScraper
|
| 6 |
from .utils.TargetScraper import TargetScraper
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# Create your views here.
|
| 9 |
|
| 10 |
|
|
@@ -40,4 +46,28 @@ def refreshTarget(request):
|
|
| 40 |
return render(request, 'scraper/home.html', {'message': 'Target refreshed'})
|
| 41 |
|
| 42 |
def index(request):
|
| 43 |
-
return render(request, 'scraper/home.html')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
from .utils.SephoraScraper import SephoraScraper
|
| 5 |
from .utils.UltaScraper import UltaScraper
|
| 6 |
from .utils.TargetScraper import TargetScraper
|
| 7 |
+
from django_filters.views import FilterView
|
| 8 |
+
from django_tables2.views import SingleTableMixin
|
| 9 |
+
from .filters import ProductFilter
|
| 10 |
+
from .tables import ProductTable
|
| 11 |
+
from .models import Product
|
| 12 |
+
import csv
|
| 13 |
+
from django.http import HttpResponse
|
| 14 |
# Create your views here.
|
| 15 |
|
| 16 |
|
|
|
|
| 46 |
return render(request, 'scraper/home.html', {'message': 'Target refreshed'})
|
| 47 |
|
| 48 |
def index(request):
|
| 49 |
+
return render(request, 'scraper/home.html')
|
| 50 |
+
|
| 51 |
+
class ProductListView(SingleTableMixin, FilterView):
|
| 52 |
+
table_class = ProductTable
|
| 53 |
+
model = Product
|
| 54 |
+
template_name = "scraper/home.html"
|
| 55 |
+
filterset_fields = {
|
| 56 |
+
'title': ['icontains'],
|
| 57 |
+
'ingredients': ['icontains'],
|
| 58 |
+
'product_id': ['exact'],
|
| 59 |
+
'url': ['exact'],
|
| 60 |
+
'store_name': ['exact'],
|
| 61 |
+
}
|
| 62 |
+
filtered_class = ProductFilter
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def download_all_product_csv(request):
|
| 66 |
+
parcels = Product.objects.all()
|
| 67 |
+
response = HttpResponse(content_type='text/csv')
|
| 68 |
+
response['Content-Disposition'] = 'attachment; filename="parcels.csv"'
|
| 69 |
+
writer = csv.writer(response)
|
| 70 |
+
writer.writerow(['Product Id', 'Title', 'Ingredients', 'Url', 'Store Name'])
|
| 71 |
+
for parcel in parcels:
|
| 72 |
+
writer.writerow([parcel.product_id, parcel.title, parcel.ingredients, parcel.url, parcel.store_name])
|
| 73 |
+
return response
|