How to use stats_item method in yandex-tank

Best Python code snippet using yandex-tank

views.py

Source: views.py Github

copy

Full Screen

1from django.shortcuts import render2from django.http import HttpResponse, HttpResponseRedirect, JsonResponse3from django.urls import reverse4from django.utils import timezone5from django.views.decorators.csrf import csrf_exempt6import requests7from bs4 import BeautifulSoup8from datetime import date9from .models import NBA_Player10# Create your views here.11def index(request):12 return render(request, 'data/​index.html')13def nba(request):14 return render(request, 'data/​nba.html')15def nba_players(request):16 players = NBA_Player.objects.all()17 context = {'players': players}18 return render(request, 'data/​nba_players.html', context)19def admin_nba_players(request):20 if request.user.is_superuser:21 players = NBA_Player.objects.all()22 context = {'players': players}23 return render(request, 'data/​admin_nba_players.html', context)24 25 return HttpResponse('Unauthorized', status=401)26def _validate_player(player):27 errors = {}28 if not player.get('stats_player_id'):29 errors['stats_player_id'] = { 'msg': 'stats_player_id can not be blank.' }30 if not player.get('name'):31 errors['name'] = { 'msg': 'name can not be blank.' }32 return errors33def admin_nba_players_update(request):34 if request.user.is_superuser:35 if request.method == 'POST':36 stats_player_id = request.POST.get('stats_player_id')37 page = requests.get('https:/​/​stats.nba.com/​player/​' + str(stats_player_id) + '/​')38 soup = BeautifulSoup(page.content, 'html.parser')39 el_player = soup.find('div', { 'class': 'player-summary' })40 first_name = el_player.find('p', { 'class': 'player-summary__first-name'}).text41 last_name = el_player.find('p', { 'class': 'player-summary__last-name'}).text42 name = '{} {}'.format(first_name, last_name)43 text = el_player.find('span', { 'class': 'player-summary__player-number'}).text44 number = int(text[1:])45 46 team = el_player.find('span', { 'class': 'player-summary__team-name'}).text47 48 stats_item = el_player.find('div', { 'class': 'player-stats__height'})49 text = stats_item.find('span', { 'class': 'player-stats__stat-value'}).text50 tokens = text.split('-')51 ht = (float(tokens[0]) * 12 + float(tokens[1])) * 2.5452 53 stats_item = el_player.find('div', { 'class': 'player-stats__weight'})54 text = stats_item.find('span', { 'class': 'player-stats__stat-value'}).text55 tokens = text.split()56 wt = float(tokens[0])57 58 stats_item = el_player.find('div', { 'class': 'player-stats__birthdate'})59 text = stats_item.find('span', { 'class': 'player-stats__stat-value'}).text60 tokens = text.split('/​')61 born = date(int(tokens[2]), int(tokens[0]), int(tokens[1]))62 stats_item = el_player.find('div', { 'class': 'player-stats__prior'})63 prior = stats_item.find('span', { 'class': 'player-stats__stat-value'}).text64 stats_item = el_player.find('div', { 'class': 'player-stats__draft'})65 draft = stats_item.find('span', { 'class': 'player-stats__stat-value'}).text66 stats_item = el_player.find('div', { 'class': 'player-stats__experience'})67 text = stats_item.find('div', { 'class': 'player-stats__stat-value'}).text68 tokens = text.split()69 exp = float(tokens[0])70 stats_item = el_player.find('div', { 'class': 'player-stats__pts'})71 text = stats_item.find('span', { 'class': 'player-stats__stat-value'}).text72 pts = float(text)73 stats_item = el_player.find('div', { 'class': 'player-stats__reb'})74 text = stats_item.find('span', { 'class': 'player-stats__stat-value'}).text75 reb = float(text)76 stats_item = el_player.find('div', { 'class': 'player-stats__ast'})77 text = stats_item.find('span', { 'class': 'player-stats__stat-value'}).text78 ast = float(text)79 stats_item = el_player.find('div', { 'class': 'player-stats__pie'})80 text = stats_item.find('span', { 'class': 'player-stats__stat-value'}).text81 pie = float(text)82 83 '''84 print("---------------------------------------")85 print(first_name)86 print(last_name)87 print(number)88 print(team)89 print(ht)90 print(wt)91 print(born)92 print(prior)93 print(draft)94 print(exp)95 print(pts)96 print(reb)97 print(ast)98 print(pie)99 '''100 players = NBA_Player.objects.filter(stats_player_id=stats_player_id)101 player = None if len(players) == 0 else players[0]102 if not player:103 errors = _validate_player({104 'stats_player_id': stats_player_id,105 'name': name, 106 })107 if errors:108 return JsonResponse({ 'errors': errors })109 110 player = NBA_Player(name=name, stats_player_id=stats_player_id, number=number, 111 team=team, ht=ht, wt=wt, born=born, prior=prior, draft=draft, exp=exp, 112 pts=pts, reb=reb, ast=ast, pie=pie)113 player.save()114 115 return JsonResponse({ 'status': 200, 'msg': 'success' })116 else:117 errors = _validate_player({118 'stats_player_id': stats_player_id,119 'name': name, 120 })121 if errors:122 return JsonResponse({ 'errors': errors })123 player.name = name124 player.stats_player_id = stats_player_id 125 player.number = number126 player.team=team127 player.ht=ht128 player.wt=wt 129 player.born=born130 player.prior=prior 131 player.draft=draft132 player.xp=exp133 player.pts=pts 134 player.reb=reb 135 player.ast=ast 136 player.pie=pie137 player.save()138 139 return JsonResponse({ 'status': 200, 'msg': 'success' })...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Webinar: Move Forward With An Effective Test Automation Strategy [Voices of Community]

The key to successful test automation is to focus on tasks that maximize the return on investment (ROI), ensuring that you are automating the right tests and automating them in the right way. This is where test automation strategies come into play.

Dec’22 Updates: The All-New LT Browser 2.0, XCUI App Automation with HyperExecute, And More!

Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.

Developers and Bugs – why are they happening again and again?

Entering the world of testers, one question started to formulate in my mind: “what is the reason that bugs happen?”.

Test Optimization for Continuous Integration

“Test frequently and early.” If you’ve been following my testing agenda, you’re probably sick of hearing me repeat that. However, it is making sense that if your tests detect an issue soon after it occurs, it will be easier to resolve. This is one of the guiding concepts that makes continuous integration such an effective method. I’ve encountered several teams who have a lot of automated tests but don’t use them as part of a continuous integration approach. There are frequently various reasons why the team believes these tests cannot be used with continuous integration. Perhaps the tests take too long to run, or they are not dependable enough to provide correct results on their own, necessitating human interpretation.

13 Best Java Testing Frameworks For 2023

The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful