Facebook
From Blush Marmoset, 2 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 64
  1. def item_selected(d):
  2.     selection = listbox.curselection()
  3.     ID = (playersid[selection[0]])
  4.     response = requests.get('https://statsapi.web.nhl.com/api/v1/people/' + ID)
  5.     player = json.loads(response.text)
  6.     fullname = (player["people"][0]["fullName"])
  7.     number = (player["people"][0]["primaryNumber"])
  8.     abbreviation = (player["people"][0]["primaryPosition"]["abbreviation"])
  9.     height = (player["people"][0]["height"])
  10.     weight = (player["people"][0]["weight"])
  11.     age = (player["people"][0]["currentAge"])
  12.     birth = (player["people"][0]["birthDate"])
  13.     nationality = (player["people"][0]["nationality"])
  14.     number = str(number)
  15.     namenumber["text"] = (fullname +" | # "+number)
  16.     height = str(height)
  17.     weight = str(weight)
  18.     age = str(age)
  19.     hwabn["text"] = (abbreviation+" | "+height + " | " + weight + " lbs | " + age + " | " + birth + " | " + nationality)
  20.     response2 = requests.get("https://statsapi.web.nhl.com/api/v1/people/"+ ID + "/stats?stats=statsSingleSeason&season=20202021")
  21.     current_season = json.loads(response2.text)
  22.     season = (current_season["stats"][0]["splits"][0]["season"])
  23.     games = (current_season["stats"][0]["splits"][0]["stat"]["games"])
  24.     goals = (current_season["stats"][0]["splits"][0]["stat"]["goals"])
  25.     assists = (current_season["stats"][0]["splits"][0]["stat"]["assists"])
  26.     points = (current_season["stats"][0]["splits"][0]["stat"]["points"])
  27.     plusminus = (current_season["stats"][0]["splits"][0]["stat"]["plusMinus"])
  28.     games = str(games)
  29.     goals = str(goals)
  30.     assists = str(assists)
  31.     points = str(points)
  32.     plusminus = str(plusminus)
  33.     current["text"] = ("2020/2021 | "+games+" | "+goals+" | "+assists+" | "+points+" | "+plusminus)
  34.     response3 = requests.get("https://statsapi.web.nhl.com/api/v1/people/"+ ID + "?hydrate=stats(splits=careerRegularSeason)")
  35.     career_stats = json.loads(response3.text)
  36.     season2 = (career_stats["people"][0]["stats"][0]["type"]["displayName"])
  37.     games2 = (career_stats["people"][0]["stats"][0]["splits"][0]["stat"]["games"])
  38.     goals2 = (career_stats["people"][0]["stats"][0]["splits"][0]["stat"]["goals"])
  39.     assists2 = (career_stats["people"][0]["stats"][0]["splits"][0]["stat"]["assists"])
  40.     points2 = (career_stats["people"][0]["stats"][0]["splits"][0]["stat"]["points"])
  41.     plusminus2 = (career_stats["people"][0]["stats"][0]["splits"][0]["stat"]["plusMinus"])
  42.     games2 = str(games2)
  43.     goals2 = str(goals2)
  44.     assists2 = str(assists2)
  45.     points2 = str(points2)
  46.     plusminus2 = str(plusminus2)
  47.     alll["text"] = ("Career Stats | "+games2+" | "+goals2+" | "+assists2+" | "+points2+" | "+plusminus2)
  48.     photo["file"] = ID + ".png"
  49.  
  50.  
  51.  
  52. window = Tk()
  53. Mainframe = Frame(window, width=400, height=400, bg="blue")
  54. Mainframe.grid(row=0, column=0, padx=20, pady=20, ipadx=20, ipady=20)
  55. topframe = Frame(Mainframe, width=400, height=40,bg="blue")
  56. topframe.grid(row=0, column=0, padx=20, pady=20, ipadx=20, ipady=20,columnspan=3)
  57. label1 = Label(topframe, text="Toronto Maple Leafs", bg="blue", fg="white", font="Arial 60 bold")
  58. label1.pack()
  59. frameright = Frame(Mainframe, width="100", bg="blue")
  60. frameright.grid(row=1, column=0, padx=20, pady=20, ipadx=20, ipady=20)
  61. frameright1 = Frame(frameright, width="100",)
  62. frameright1.grid(row=1, column=0, pady=20)
  63. label2 = Label(frameright1, text="Team Roster",)
  64. label2.pack()
  65. frameright2 = Frame(frameright, width="80")
  66. frameright2.grid(row=2, column=0)
  67. scrollbar = Scrollbar(frameright2)
  68. scrollbar.pack(side="right", fill="y")
  69. listbox=Listbox(frameright2,
  70.                 height=10,
  71.                 width=20,
  72.                 bg="grey",
  73.                 font = "arial"
  74.                 ,yscrollcommand=scrollbar.set)
  75. counter=1
  76. while counter<len(players):
  77.     listbox.insert(counter, players[counter-1])
  78.     counter=counter+1
  79. listbox.pack()
  80. listbox.bind("<<ListboxSelect>>", item_selected)
  81.  
  82. scrollbar.config(command=listbox.yview)
  83.  
  84. frameright3 = Frame(frameright, width="100", bg="blue")
  85. frameright3.grid(row=3, column=0, padx=20, pady=20, ipadx=20, ipady=20)
  86.  
  87.  
  88. frameleft = Frame(Mainframe, width="100", bg="blue")
  89. frameleft.grid(row=1, column=1, padx=20, pady=20, ipadx=20, ipady=20)
  90. frameleft1 = Frame(frameleft, width="100")
  91. frameleft1.grid(row=1, column=0, padx=20, pady=20, ipadx=20, ipady=20)
  92. photo = PhotoImage(file="")
  93. playerimage = Label(frameleft1, image=photo)
  94. playerimage.pack()
  95. frameleft2 = Frame(frameleft, width="100", bg="white")
  96. frameleft2.grid(row=2, column=0)
  97. namenumber = Label(frameleft2, text="", bg="white")
  98. namenumber.pack()
  99. hwabn = Label(frameleft2, text="", bg="white", width="40")
  100. hwabn.pack()
  101. stats = Label(frameleft2, text="      Seson    | Gp | G | A | P | +/- ")
  102. stats.pack()
  103. current = Label(frameleft2, text="", bg="white")
  104. current.pack()
  105. alll = Label(frameleft2, text="", bg="white")
  106. alll.pack()
  107. frameleft3 = Frame(frameleft, width="100",bg="blue")
  108. frameleft3.grid(row=3, column=0, padx=20, pady=20, ipadx=20, ipady=20)
  109.  
  110. window. mainloop()