Example #1
0
def watcher_list(request):
    """
	List all watchers or create a new one
	"""
    if request.method == 'GET':
        for watcher in Watcher.objects.all():
            watcher.update()

        watcher = Watcher.objects.all()
        serializer = WatcherSerializer(watcher, many=True)

        watcher_purchase = Watcher.objects.all().filter(purchase=True)
        if (watcher_purchase):
            sendmail(watcher_purchase)

        return JSONResponse(serializer.data)

    elif request.method == 'POST':
        #Grab Json data of desired products

        data = JSONParser().parse(request)

        query_string = data['query_string']
        target_price = Decimal(data['target_price'])
        threshold = Decimal(data['threshold'])
        email = data['email']
        send_email = data['send_email']

        api_string = "http://api.remix.bestbuy.com/v1/products(sku=" + query_string + ")?show=sku,name,regularPrice,salePrice&apiKey=xkuweuxjvtgpnpv2vs5usq35&format=json"

        r = requests.get(api_string)
        response = r.json()

        name = response['products'][0]['name']

        current_watcher = Watcher(name=name,
                                  query_string=query_string,
                                  target_price=target_price,
                                  threshold=threshold,
                                  email=email,
                                  send_email=(send_email == 'True'))
        current_watcher.save()

        for p in list(response['products']):
            product = Product(name=p['name'],
                              lowest_price=min(p['regularPrice'],
                                               p['salePrice']),
                              sku=p['sku'],
                              watcher=current_watcher)
            product.save()

        return JSONResponse(data, status=201)
        """
Example #2
0
def watcher_list(request):
	"""
	List all watchers or create a new one
	"""
	if request.method == 'GET':
		for watcher in Watcher.objects.all(): 
			watcher.update()

		watcher = Watcher.objects.all()
		serializer = WatcherSerializer(watcher, many=True)

		watcher_purchase = Watcher.objects.all().filter(purchase=True)
		if (watcher_purchase):
			sendmail(watcher_purchase)

		return JSONResponse(serializer.data)

	elif request.method == 'POST':
		#Grab Json data of desired products

		data = JSONParser().parse(request)

		query_string = data['query_string']
		target_price = Decimal(data['target_price'])
		threshold = Decimal(data['threshold'])
		email = data['email']
		send_email = data['send_email']

		api_string = "http://api.remix.bestbuy.com/v1/products(sku=" + query_string + ")?show=sku,name,regularPrice,salePrice&apiKey=xkuweuxjvtgpnpv2vs5usq35&format=json"

		r = requests.get(api_string)
		response = r.json()

		name = response['products'][0]['name']

		current_watcher = Watcher(name = name, query_string=query_string, target_price=target_price, threshold=threshold, email=email, send_email=(send_email=='True'))
		current_watcher.save()

		for p in list(response['products']):
			product = Product(
				name=p['name'], 
				lowest_price=min(p['regularPrice'],p['salePrice']), 
				sku=p['sku'],
				watcher=current_watcher)
			product.save()

		return JSONResponse(data, status=201)
		"""
Example #3
0
def watcher_list(request):
    """
	List all watchers or create a new one
	"""
    if request.method == 'GET':
        for watcher in Watcher.objects.all():
            watcher.update()

        watcher = Watcher.objects.all()
        serializer = WatcherSerializer(watcher, many=True)
        return JSONResponse(serializer.data)

    elif request.method == 'POST':
        #Grab Json data of desired products

        data = JSONParser().parse(request)

        name = data['name']
        query_string = data['query_string']
        target_price = Decimal(data['target_price'])
        threshold = Decimal(data['threshold'])

        current_watcher = Watcher(name=name,
                                  query_string=query_string,
                                  target_price=target_price,
                                  threshold=threshold)
        current_watcher.save()

        r = requests.get(
            "http://api.remix.bestbuy.com/v1/products(name=iPhone*)?show=sku,name,regularPrice,salePrice&pageSize=15&page=5&apiKey=xkuweuxjvtgpnpv2vs5usq35&format=json"
        )
        response = r.json()

        for p in list(response['products']):
            product = Product(name=p['name'],
                              lowest_price=min(p['regularPrice'],
                                               p['salePrice']),
                              watcher=current_watcher)
            product.save()

        return JSONResponse(data, status=201)
        """
Example #4
0
def watcher_list(request):
	"""
	List all watchers or create a new one
	"""
	if request.method == 'GET':
		for watcher in Watcher.objects.all(): 
			watcher.update()

		watcher = Watcher.objects.all()
		serializer = WatcherSerializer(watcher, many=True)
		return JSONResponse(serializer.data)

	elif request.method == 'POST':
		#Grab Json data of desired products

		data = JSONParser().parse(request)

		name = data['name']
		query_string = data['query_string']
		target_price = Decimal(data['target_price'])
		threshold = Decimal(data['threshold'])

		current_watcher = Watcher(name = name, query_string=query_string, target_price=target_price, threshold=threshold)
		current_watcher.save()

		r = requests.get("http://api.remix.bestbuy.com/v1/products(name=iPhone*)?show=sku,name,regularPrice,salePrice&pageSize=15&page=5&apiKey=xkuweuxjvtgpnpv2vs5usq35&format=json")
		response = r.json()

		for p in list(response['products']):
			product = Product(
				name=p['name'], 
				lowest_price=min(p['regularPrice'],p['salePrice']), 
				watcher=current_watcher)
			product.save()

		return JSONResponse(data, status=201)
		"""
Example #5
0
from bba_server.models import Product, Watcher
from bba_server.serializers import WatcherSerializer
import requests
import json

#Grab Json data of desired products
r = requests.get(
    "http://api.remix.bestbuy.com/v1/products(name=iPhone*)?show=sku,name,regularPrice,salePrice&pageSize=15&page=5&apiKey=xkuweuxjvtgpnpv2vs5usq35&format=json"
)
response = r.json()

# Watcher #1: Instantiate a watcher for iPhone prices around 400
current_watcher = Watcher(name='iPhone400', target_price='400')
current_watcher.save()

#turn json data into products for our watcher
for p in list(response['products']):
    product = Product(name=p['name'],
                      lowest_price=min(p['regularPrice'], p['salePrice']),
                      watcher=current_watcher)
    product.save()

# Watcher #2: Instantiate a watcher for Iphone prices around 680
current_watcher = Watcher(name='iPhone680', target_price='680')
current_watcher.save()

#turn json data into products for our watcher
for p in list(response['products']):
    product = Product(name=p['name'],
                      lowest_price=min(p['regularPrice'], p['salePrice']),
                      watcher=current_watcher)