Best Python code snippet using avocado_python
views.py
Source: views.py
1from django.shortcuts import render2from django.urls import reverse3from django.http import HttpResponse, HttpResponseRedirect4from django.http import JsonResponse5from . import amazon, flipkart, snapdeal, sort_fn, ShopClues6# Create your views here.7def home(request):8 if request.method == 'POST':9 product=request.POST.get('product')10 request.session['query']=product11 return HttpResponseRedirect(reverse('show_deal'))12 return render(request, 'scraper_app/index.html')13# def show_deal(request):14# query = request.session.get('query', None)15# a_items = sort_fn.RankProducts(amazon.scrape(query),10)16# f_items = sort_fn.RankProducts(flipkart.getItems(query),10)17# s_items = sort_fn.RankProducts(snapdeal.snapdeal(query),10)18# sc_items = sort_fn.RankProducts(ShopClues.scrape(query),10)19# items = a_items + s_items + f_items + sc_items20# deals = sort_fn.RankProducts(items,40,1)21# return render(request, 'scraper_app/show_deal.html', {'deals': deals, 'a_items':a_items, 'f_items':f_items, 's_items':s_items})22def show_deal(request, productName):23 # query = request.session.get('query', None)24 a_items=amazon.scrape(productName)25 f_items=flipkart.getItems(productName)26 s_items=snapdeal.snapdeal(productName)27 sc_items=ShopClues.scrape(productName)28 items2=a_items + s_items + f_items + sc_items29 if a_items!=[]:30 a_items = sort_fn.RankProducts(a_items, 10)31 if f_items!=[]:32 f_items = sort_fn.RankProducts(f_items, 10)33 if s_items!=[]:34 s_items = sort_fn.RankProducts(s_items, 10)35 if sc_items!=[]:36 sc_items = sort_fn.RankProducts(sc_items, 10)37 items = a_items + s_items + f_items + sc_items38 deals=[]39 if items!=[]:40 deals = sort_fn.RankProducts(items,40,1)41 # return render(request, 'scraper_app/show_deal.html', {'items':items})42 return JsonResponse({'deals':deals, 'items':items}, safe=False)43def getFilteredData(request, productName, minimum, maximum):44 #request.lower_bound, request.upper_bound45 #give these to sort function with items46 minimum=float(minimum)47 maximum=float(maximum)48 a_items=amazon.scrape(productName)49 f_items=flipkart.getItems(productName)50 s_items=snapdeal.snapdeal(productName)51 sc_items=ShopClues.scrape(productName)52 items2=a_items + s_items + f_items + sc_items53 items3=[]54 for item in items2:55 if item['price_inr']!='':56 item_price = float(item['price_inr'].strip().replace(',', ''))57 if item_price>=minimum and item_price<=maximum:58 items3.append(item)59 deals=[]60 if items3!=[]:61 deals = sort_fn.RankProducts(items3,40,1)...
test_sort.py
Source: test_sort.py
...22 (merge_sort,[3,2,1],[1,2,3]),23 (merge_sort,[11, 25, 12, 22, 64],[11,12,22, 25, 64]),24 ])25def test_sort(sort_fn, input, expected):26 assert sort_fn(input) == expected27@pytest.mark.parametrize("sort_fn, sizes", [28 (bubble_sort, [10,100,1000,10000]), 29 (insertion_sort,[10,100,1000,10000]),30 (selection_sort,[10,100,1000,10000]),31 (merge_sort,[10,100,1000,10000,100000,1000000])32 ])33def test_performance(sort_fn, sizes):34 for size in sizes:35 start = timer()36 sort_fn(reversed_list(size))37 end = timer()...
utils.py
Source: utils.py
...9 pos = n10 11 if self.sort_fn != None:12 for i in range(n):13 if self.sort_fn(element) < self.sort_fn(self.queue[i]):14 pos = i; break15 16 self.queue.insert(pos, element)17 def pop(self):18 return self.queue.pop(0)19 def remove(self, el):20 self.queue.remove(el)21 def find(self, find_fn):22 for e in self.queue:23 if find_fn(e):24 return e25 def index(self, element):26 for i in range(len(self.queue)):27 if element == self.queue[i]:...
Check out the latest blogs from LambdaTest on this topic:
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.
JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
The rapid shift in the use of technology has impacted testing and quality assurance significantly, especially around the cloud adoption of agile development methodologies. With this, the increasing importance of quality and automation testing has risen enough to deliver quality work.
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!