-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsleeperPy.py
executable file
·771 lines (632 loc) · 26.3 KB
/
sleeperPy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
#!/usr/bin/env python3
# sleeperPy
# REQUIREMENTS:
# pip3 install bs4
# if apache is root, sudo pip3 install bs4
# ISSUES/TODO
# TODO: not taking account into flex, e.g noah fant tier 5 better than desean tier 7
# TODO: waiver wire suggestions would be great, especially for DST/K. If player on WW is higher tier, mention it.
# looks like i would have to curl "https://api.sleeper.app/v1/players/nfl/trending/add" and keep ~top 5
# then determine if that player is rostered in any team, seperately
# TODO: easy one, unranked player doesn't count towards the tier. maybe make them tier 12?
# TODO: better comments
# API
# https://docs.sleeper.app/
# Bugs:
# Craig Stevens
# https://www.reddit.com/r/fantasyfootball/comments/jszktk/like_boris_chen_tiers_and_use_sleeper_simple_tool/gc2mqa7/
# has to be *not* having a player in a position, like no kicker
# players.txt perm issue
# check apache log in next few days, might've fixed it
# PHP Warning: file_put_contents(players.txt): failed to open stream: Permission denied in /var/www/html/sleeperPy/index.php on line 40, referer: https://wboll.dev/sleeperPy/
# Tiers
# https://github.com/abhinavk99/espn-borischentiers/blob/master/src/js/espn-borischentiers.js
import requests, json, os, time, re, sys, fileinput, logging, time, calendar, urllib.request, json
from pathlib import Path
from shutil import copyfile
from urllib.request import urlopen
from bs4 import BeautifulSoup
from datetime import datetime
from operator import itemgetter
from logging.handlers import RotatingFileHandler
from pymongo import MongoClient
from os import path
# Variables
sport = "nfl"
# current year, e.g 2020
year = datetime.now().strftime("%Y")
# template file
htmlFile = "tiers.php"
# logging
loggingFile = "sleeperPy.log"
playersFile = "players.json"
dbName = "sleeperPy"
collectionName = "players"
# Functions
def mongoConnect():
# connect to mongodb
client = MongoClient()
# default host/port
db = client[dbName]
collection = db[collectionName]
return db, collection
def mongoImport():
playersPath = Path(playersFile)
url = "https://api.sleeper.app/v1/players/nfl"
today = datetime.today()
# see if we need a new players.json
if playersPath.is_file():
# 8 is last modified
t = os.stat(playersPath)[8]
filetime = today - datetime.fromtimestamp(t)
if int(filetime.seconds) > 86400:
# if it's last been modified longer than a day ago, download new players.txt
with urllib.request.urlopen(url) as url:
data = json.loads(url.read().decode())
with open(playersFile, "w") as f:
json.dump(data, f)
f.close()
# clean up existing data
collection.delete_many({})
# import new stuff
os.system(
"mongoimport --db "
+ dbName
+ " --collection "
+ collectionName
+ " --file "
+ playersFile
)
# if file doesn't exist at all"
else:
with urllib.request.urlopen(url) as url:
data = json.loads(url.read().decode())
with open(playersFile, "w") as f:
json.dump(data, f)
f.close()
# clean up existing data
collection.delete_many({})
# import new stuff
os.system(
"mongoimport --db "
+ dbName
+ " --collection "
+ collectionName
+ " --file "
+ playersFile
)
def Diff(li1, li2):
# used to find "bench" by finding the difference between total team and starters
li_dif = [i for i in li1 + li2 if i not in li1 or i not in li2]
return li_dif
def sortLists(list1, list2):
# list1 should be tiers, list2 players
# sort player list and tier list together, keeping values
# sort by lowest value (highest tier) first
if type(list1) == "None" or type(list2) == "None":
return list1, list2
if len(list1) == 0 or len(list2) == 0:
return list1, list2
# force tiers to ints
list1 = [int(i) for i in list1]
# reverse=True
# damn this works!!!
# https://stackoverflow.com/questions/9764298/how-to-sort-two-lists-which-reference-each-other-in-the-exact-same-way
list1, list2 = (list(t) for t in zip(*sorted(zip(list1, list2), key=itemgetter(0))))
return list1, list2
def printTiers(playerList, tierList, pos):
# used to generate HTML with lists of players and their matching tiers
outputList = []
# playerList, tierList = sortLists(playerList, tierList)
tierList, playerList = sortLists(tierList, playerList)
# print(*tierList)
# print(*playerList)
if len(playerList) > 0:
print("<tr>")
print("<th>" + pos + "</th>")
print("<th>Tier</th>")
print("</tr>")
for x in range(len(playerList)):
outputList.append(
"<tr>"
+ "<td>"
+ playerList[x]
+ "</td>"
+ "<td>"
+ str(tierList[x])
+ "</td>"
+ "</tr>"
)
return outputList
def validateBoris(tierListPos):
# fixing inconsistencies as i find them between boris chen and sleeper player names
# ok this works at least but i think i have to edit the list
# BorisName, Sleeper Name
tierListPos = [w.replace("D.K. Metcalf", "DK Metcalf") for w in tierListPos]
tierListPos = [w.replace("Jeff Wilson Jr.", "Jeffery Wilson") for w in tierListPos]
tierListPos = [w.replace("JaMycal Hasty", "Jamycal Hasty") for w in tierListPos]
return tierListPos
def createTiers(tierListPos, fullName, posPlayerList, posTierList, tier):
# find the players name in a tier list, when found also note their tier
tierListPos = validateBoris(tierListPos)
for q in range(len(tierListPos)):
# tierListPos[q] means: Tier 1: Lamar Jackson, Dak Prescott, Patrick Mahomes II
# iterates through each line of tier
if fullName in tierListPos[q]:
tier = q + 1
posPlayerList.append(f"{fullName}")
posTierList.append(f"{tier}")
return posPlayerList, posTierList, tier
def createUnranked(tierListPos, fullName):
# go through entire tier list for a position, if player name not in any of them, they are not ranked
flag = False
tierListPos = validateBoris(tierListPos)
if any(fullName in word for word in tierListPos):
flag = True
if flag == False:
return f"{fullName}"
else:
return "ranked"
def currentWeek():
# if the start of the NFL season isn't ~week 36 of the year, change that value
# between like August -> September 9th (Thursday) (2021), it's week 1.
# Final games in week 1 would be 13th.. so september 14th - 21st is week 2.. 22nd - 29th is week 3
# ending on Jan 9th, 2020, a Sunday
currentWeek = datetime.today().isocalendar()[1]
# if july 17 is week 28.. then september 9th would be week 37... and january 9th 2022 is week.. 2 of 2022
# lmao, $currentWeek - 36 is technically right. but man that's nasty to change in the future
# sorry to future me
currentNFLWeek = currentWeek - 35
# if it's postseason, cap at 16. wait this'll screwup for 2020
if currentNFLWeek > 16:
currentNFLWeek == 16
# a beautiful elif for week 1/2 of 2022, the last week.. ugh
elif currentWeek == 1 | 2:
currentNFLWeek == 16
# basically offseason, if negative weeks then
else:
currentNFLWeek = max(1, currentNFLWeek)
return currentNFLWeek
# Rotating application logging
def create_rotating_log(path):
logger = logging.getLogger("Rotating Log")
logger.setLevel(logging.DEBUG)
# add a rotating handler
handler = RotatingFileHandler(path, maxBytes=2000000, backupCount=5)
logger.addHandler(handler)
# logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
log_file = path
root = logging.getLogger()
root.setLevel(logging.DEBUG)
# handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
handler.setFormatter(formatter)
root.addHandler(handler)
create_rotating_log(loggingFile)
db, collection = mongoConnect()
mongoImport()
# logger = logging.getLogger()
# get username argument
n = len(sys.argv)
if n < 2:
print("Error: please enter your Sleeper username.")
elif n > 2:
print("Error: Too many arguments. Please type your sleeper username.")
username = str(sys.argv[1])
tiersFilename = "tiers_" + username + ".php"
tiersFilepath = "tiers/" + tiersFilename
# mkdir if not exists
if not os.path.isdir("tiers/"):
os.mkdir("tiers/")
# delete file if exists already
if os.path.exists(tiersFilepath):
os.remove(tiersFilepath)
# copy template html file to user specific file
copyfile(htmlFile, tiersFilepath)
os.chmod(tiersFilepath, 0o666)
sys.stdout = open(tiersFilepath, "a")
# Get USERID
url = f"https://api.sleeper.app/v1/user/{username}"
r = requests.get(url)
data = r.json()
# attempt to see if we can get any data from sleeper for inputted username
try:
userid = data["user_id"]
except TypeError:
print("Sorry, invalid Sleeper username. Please try again.")
sys.exit()
# Get all leagues for user
url = f"https://api.sleeper.app/v1/user/{userid}/leagues/{sport}/{year}"
r = requests.get(url)
data = r.json()
# list type
leagues = []
leagueNames = []
scoring = []
i = 0
for d in data:
leagues.append(d["league_id"])
leagueNames.append(d["name"])
scoring.append(d["scoring_settings"]["rec"])
# leagues, e.g
# ['603501445962080256', '597557922544807936']
# Get current players of user for * leagues
# GET https://api.sleeper.app/v1/league/<league_id>/rosters
# first, fetch all players so I can cross reference IDs
# read from players file
# print roster for both leagues:
i = 0
starters = []
players = []
# roster_id = []
# matchup_id = []
oppStarters = []
oppPlayers = []
print("<h5>Username: " + username + " - Week " + str(currentWeek()) + "</h5>")
print(
'<div class="buttonholder"><form action="" method="post"> <input type="submit" name="submit" value="Refresh Tiers" /></form>'
)
print("</div>")
print("</div>")
print("</div>")
print('<div class="flex-container container">')
# get players and starters for user team in each league
for league in leagues:
# Get current roster
url = f"https://api.sleeper.app/v1/league/{league}/rosters"
r = requests.get(url)
data = r.json()
# data is a list here
# length is number of teams
for d in data:
# for every team in league, do
if d["owner_id"] == userid:
# then this is current user
starters.append(d["starters"])
players.append(d["players"])
roster_id = d["roster_id"]
week = currentWeek()
url = f"https://api.sleeper.app/v1/league/{league}/matchups/{week}"
r = requests.get(url)
data = r.json()
for d in data:
if roster_id == d["roster_id"]:
# if player matchup is found via roster id
matchup_id = d["matchup_id"]
# get matchup id
for d in data:
if matchup_id == d["matchup_id"]:
if roster_id != d["roster_id"]:
# if you found a matching matchup ID but NOT matching roster_id, must be opponent
oppStarters.append(d["starters"])
oppPlayers.append(d["players"])
bench = []
starterList, benchList = [], []
# ur = unranked
qbStarterList,rbStarterList,wrStarterList,teStarterList,dstStarterList,kStarterList,urStarterList = [],[],[],[],[],[],[]
qbTierList,rbTierList,wrTierList,dstTierList,teTierList,kTierList = [],[],[],[],[],[]
qbBenchList,rbBenchList,wrBenchList,teBenchList,dstBenchList,kBenchList,urBenchList = [],[],[],[],[],[],[]
qbTierBenchList,rbTierBenchList,wrTierBenchList,teTierBenchList,dstTierBenchList,kTierBenchList = [],[],[],[],[],[]
# mode = scoringMode(scoring)
# figure out what lists to use
# below 3 are guranteed regardless of scoring
qbBoris = "https://s3-us-west-1.amazonaws.com/fftiers/out/text_QB.txt"
dstBoris = "https://s3-us-west-1.amazonaws.com/fftiers/out/text_DST.txt"
kBoris = "https://s3-us-west-1.amazonaws.com/fftiers/out/text_K.txt"
scoring_to_text_map = {1.0: "-PPR", 0.5: "-HALF", 0.0: ""}
rbBoris = f"https://s3-us-west-1.amazonaws.com/fftiers/out/text_RB{scoring_to_text_map[scoring[i]]}.txt"
wrBoris = f"https://s3-us-west-1.amazonaws.com/fftiers/out/text_WR{scoring_to_text_map[scoring[i]]}.txt"
teBoris = f"https://s3-us-west-1.amazonaws.com/fftiers/out/text_TE{scoring_to_text_map[scoring[i]]}.txt"
print('<table class="table-fill">')
if scoring[i] == 1.0:
print(
f'<th class="league-title" colspan="2">League: {leagueNames[i]} (PPR) | Starters</th>'
)
elif scoring[i] == 0.5:
print(
f'<th class="league-title" colspan="2">League: {leagueNames[i]} (Half PPR) | Starters</th>'
)
elif scoring[i] == 0.0:
print(
f'<th class="league-title" colspan="2">League: {leagueNames[i]} (Standard) | Starters</th>'
)
print("</tr>")
r = requests.get(rbBoris)
data = r.text
tierListRB = data.splitlines()
# tierListRB[0] = Tier 1: Christian McCaffrey, Ezekiel Elliott
# tfw when python has no switch/case
r = requests.get(wrBoris)
data = r.text
tierListWR = data.splitlines()
r = requests.get(teBoris)
data = r.text
tierListTE = data.splitlines()
r = requests.get(qbBoris)
data = r.text
tierListQB = data.splitlines()
r = requests.get(kBoris)
data = r.text
tierListK = data.splitlines()
r = requests.get(dstBoris)
data = r.text
tierListDST = data.splitlines()
# get bench by subtracting all players by starters
bench = Diff(players[i], starters[i])
tierSum = 0
# before: iterated through *every* key in players.txt
# if that key HAPPENED to match their key, starters[i][j], then do shit
# that sucks horribly
# instead, just loop through their teams' players
# instead, just loop through their teams' players
j = 0
tier = 0
# key = {}
# looping through starters[i] to get all IDs of starters, e.g 4881
while j < len(starters[i]):
for key in collection.distinct(str(starters[i][j])):
fName = key["first_name"]
lName = key["last_name"]
pos = key["position"]
fullName = fName + " " + lName
# iterate through tierlists based on pos
# DEF, WR, TE, K, RB, QB
# len is amount of tiers
if pos == "QB":
qbStarterList, qbTierList, tier = createTiers(
tierListQB, fullName, qbStarterList, qbTierList, tier
)
if createUnranked(tierListQB, fullName) != "ranked":
urStarterList.append(createUnranked(tierListQB, fullName))
if pos == "RB":
rbStarterList, rbTierList, tier = createTiers(
tierListRB, fullName, rbStarterList, rbTierList, tier
)
if createUnranked(tierListRB, fullName) != "ranked":
urStarterList.append(createUnranked(tierListRB, fullName))
if pos == "WR":
wrStarterList, wrTierList, tier = createTiers(
tierListWR, fullName, wrStarterList, wrTierList, tier
)
if createUnranked(tierListWR, fullName) != "ranked":
urStarterList.append(createUnranked(tierListWR, fullName))
if pos == "K":
kStarterList, kTierList, tier = createTiers(
tierListK, fullName, kStarterList, kTierList, tier
)
if createUnranked(tierListK, fullName) != "ranked":
urStarterList.append(createUnranked(tierListK, fullName))
if pos == "DEF":
dstStarterList, dstTierList, tier = createTiers(
tierListDST, fullName, dstStarterList, dstTierList, tier
)
if createUnranked(tierListDST, fullName) != "ranked":
urStarterList.append(createUnranked(tierListDST, fullName))
if pos == "TE":
teStarterList, teTierList, tier = createTiers(
tierListTE, fullName, teStarterList, teTierList, tier
)
if createUnranked(tierListTE, fullName) != "ranked":
urStarterList.append(createUnranked(tierListTE, fullName))
tierSum = tier + tierSum
tier = tier + 1
j = j + 1
# returns list with HTML to print to page
outputList = printTiers(qbStarterList, qbTierList, "QB")
for x in range(len(outputList)):
print(outputList[x])
outputList = printTiers(rbStarterList, rbTierList, "RB")
for x in range(len(outputList)):
print(outputList[x])
outputList = printTiers(wrStarterList, wrTierList, "WR")
for x in range(len(outputList)):
print(outputList[x])
outputList = printTiers(teStarterList, teTierList, "TE")
for x in range(len(outputList)):
print(outputList[x])
outputList = printTiers(kStarterList, kTierList, "K")
for x in range(len(outputList)):
print(outputList[x])
outputList = printTiers(dstStarterList, dstTierList, "DST")
for x in range(len(outputList)):
print(outputList[x])
# Sometimes goes out of bounds and grabs "Craig Stevens"
badList = ["Craig Stevens"]
urStarterList = [element for element in urStarterList if element not in badList]
if len(urStarterList) > 0:
print("<tr>")
print('<th colspan="2" style="text-align: center">Not Ranked</th>')
print("</tr>")
# urStarterList.remove("Craig Stevens")
for x in range(len(urStarterList)):
print("<tr>")
print('<td colspan="2">' + urStarterList[x] + "</td>")
print("</tr>")
qbOppTierList,rbOppTierList,wrOppTierList,dstOppTierList,teOppTierList,kOppTierList = [],[],[],[],[],[]
qbOppList,rbOppList,wrOppList,teOppList,dstOppList,kOppList,urOppList = [],[],[],[],[],[],[]
tierOppSum = 0
# Calculate Opponent Tiers
# not the best test, but if oppStarters has no length, don't do any of this
if oppStarters:
j = 0
tier = 0
# key = {}
try:
# looping through starters[i] to get all IDs of starters, e.g 4881
while j < len(oppStarters[i]):
for key in collection.distinct(str(oppStarters[i][j])):
fName = key["first_name"]
lName = key["last_name"]
pos = key["position"]
fullName = fName + " " + lName
if pos == "QB":
qbOppList, qbOppTierList, tier = createTiers(
tierListQB, fullName, qbOppList, qbOppTierList, tier
)
if pos == "RB":
rbOppList, rbOppTierList, tier = createTiers(
tierListRB, fullName, rbOppList, rbOppTierList, tier
)
if pos == "WR":
wrOppList, wrOppTierList, tier = createTiers(
tierListWR, fullName, wrOppList, wrOppTierList, tier
)
if pos == "K":
kOppList, kOppTierList, tier = createTiers(
tierListK, fullName, kOppList, kOppTierList, tier
)
if pos == "DEF":
dstOppList, dstOppTierList, tier = createTiers(
tierListDST, fullName, dstOppList, dstOppTierList, tier
)
if pos == "TE":
teOppList, teOppTierList, tier = createTiers(
tierListTE, fullName, teOppList, teOppTierList, tier
)
tierOppSum = tier + tierOppSum
tier = tier + 1
j = j + 1
except IndexError:
avgTier = round(tierSum / (len(starters[i])), 2)
print(
f'<tr><td colspan="2" style="text-align: center">Average Tier {avgTier}</td></tr>'
)
break
try:
tierOppSum = tierOppSum - 1
tierSum = tierSum - 1
avgTier = round(tierSum / (len(starters[i])), 2)
avgOppTier = round(tierOppSum / (len(oppStarters[i])), 2)
# 🏆 = trophy
# 📉 = down line
# 😐 = neutral face
# higher tier is worse
if avgTier < avgOppTier:
print(
f'<tr><td colspan="2" style="text-align: center">🏆 Average Tier {avgTier}</td></tr>'
)
print(
f'<tr><td colspan="2" style="text-align: center">📉 Opponent Average Tier {avgOppTier}</td></tr>'
)
elif avgOppTier < avgTier:
print(
f'<tr><td colspan="2" style="text-align: center">📉 Average Tier {avgTier}</td></tr>'
)
print(
f'<tr><td colspan="2" style="text-align: center">🏆 Opponent Average Tier {avgOppTier}</td></tr>'
)
elif avgOppTier == avgTier:
print(
f'<tr><td colspan="2" style="text-align: center">😐 Average Tier {avgTier}</td></tr>'
)
print(
f'<tr><td colspan="2" style="text-align: center">😐 Opponent Average Tier {avgOppTier}</td></tr>'
)
else:
print(
f'<tr><td colspan="2" style="text-align: center">Average Tier {avgTier}</td></tr>'
)
print(
f'<tr><td colspan="2" style="text-align: center">Opponent Average Tier {avgOppTier}</td></tr>'
)
except IndexError:
# issues with leagues without opponents
print("")
else:
# basically if i cant get opponent, do plain old tier averages
avgTier = round(tierSum / (len(starters[i])), 2)
print(
f'<tr><td colspan="2" style="text-align: center">Average Tier {avgTier}</td></tr>'
)
# bench
print("<br>")
print("<br>")
tier = 0
for b in bench:
for key in collection.distinct(str(b)):
fName = key["first_name"]
lName = key["last_name"]
pos = key["position"]
fullName = fName + " " + lName
if pos == "QB":
qbBenchList, qbTierBenchList, tier = createTiers(
tierListQB, fullName, qbBenchList, qbTierBenchList, tier
)
if createUnranked(tierListQB, fullName) != "ranked":
urBenchList.append(createUnranked(tierListQB, fullName))
if pos == "RB":
# rbStarterList, rbTierList, tier = createTiers(tierListRB,fullName,rbStarterList,rbTierList,tier)
rbBenchList, rbTierBenchList, tier = createTiers(
tierListRB, fullName, rbBenchList, rbTierBenchList, tier
)
if createUnranked(tierListRB, fullName) != "ranked":
urBenchList.append(createUnranked(tierListRB, fullName))
if pos == "WR":
wrBenchList, wrTierBenchList, tier = createTiers(
tierListWR, fullName, wrBenchList, wrTierBenchList, tier
)
if createUnranked(tierListWR, fullName) != "ranked":
urBenchList.append(createUnranked(tierListWR, fullName))
if pos == "K":
kBenchList, kTierBenchList, tier = createTiers(
tierListK, fullName, kBenchList, kTierBenchList, tier
)
if createUnranked(tierListK, fullName) != "ranked":
urBenchList.append(createUnranked(tierListK, fullName))
if pos == "DEF":
dstBenchList, dstTierBenchList, tier = createTiers(
tierListDST, fullName, dstBenchList, dstTierBenchList, tier
)
if createUnranked(tierListDST, fullName) != "ranked":
urBenchList.append(createUnranked(tierListDST, fullName))
if pos == "TE":
teBenchList, teTierBenchList, tier = createTiers(
tierListTE, fullName, teBenchList, teTierBenchList, tier
)
if createUnranked(tierListTE, fullName) != "ranked":
urBenchList.append(createUnranked(tierListTE, fullName))
tier = tier + 1
print("<tr>")
print('<th colspan="2" style="text-align:center;">Bench</th>')
print("</tr>")
outputList = printTiers(qbBenchList, qbTierBenchList, "QB")
for x in range(len(outputList)):
print(outputList[x])
outputList = printTiers(rbBenchList, rbTierBenchList, "RB")
for x in range(len(outputList)):
print(outputList[x])
outputList = printTiers(wrBenchList, wrTierBenchList, "WR")
for x in range(len(outputList)):
print(outputList[x])
outputList = printTiers(teBenchList, teTierBenchList, "TE")
for x in range(len(outputList)):
print(outputList[x])
outputList = printTiers(kBenchList, kTierBenchList, "K")
for x in range(len(outputList)):
print(outputList[x])
outputList = printTiers(dstBenchList, dstTierBenchList, "DST")
for x in range(len(outputList)):
print(outputList[x])
# Sometimes goes out of bounds and grabs "Craig Stevens"
badList = ["Craig Stevens"]
urBenchList = [element for element in urBenchList if element not in badList]
if len(urBenchList) > 0:
print("<tr>")
print('<th colspan="2" style="text-align: center">Not Ranked</th>')
print("</tr>")
# urBenchList.remove("Craig Stevens")
for x in range(len(urBenchList)):
print("<tr>")
print('<td colspan="2">' + urBenchList[x] + "</td>")
print("</tr>")
# end of all output for league
print("</table>")
# end of main while
i = i + 1
print("</div>")
print("<br>")
print("</body>")
print("</html>")