From a2a4afa6c1b53aad34bcfb65b0c3a63312c08f7c Mon Sep 17 00:00:00 2001 From: Nikolay Tsvetanov Date: Mon, 28 Aug 2023 21:49:18 +0300 Subject: [PATCH 1/5] run black formatter run ruff without config run isort with black profile without config add pre-commit config --- .pre-commit-config.yaml | 28 ++++++++++ playersPickedInLeague.py | 111 ++++++++++++++++++++++++--------------- ppm.py | 64 ++++++++++++++++------ 3 files changed, 145 insertions(+), 58 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..2859f79 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,28 @@ +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: detect-private-key + - id: check-toml + - id: end-of-file-fixer + - id: trailing-whitespace + - id: mixed-line-ending +- repo: https://github.com/asottile/add-trailing-comma + rev: v3.0.1 + hooks: + - id: add-trailing-comma +- repo: https://github.com/asottile/pyupgrade + rev: v3.10.1 + hooks: + - id: pyupgrade + args: [--py310-plus] +- repo: https://github.com/psf/black + rev: 23.7.0 + hooks: + - id: black + language_version: python3.10 +- repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + args: ["--profile", "black", "--filter-files"] diff --git a/playersPickedInLeague.py b/playersPickedInLeague.py index c14a956..8c1d65d 100644 --- a/playersPickedInLeague.py +++ b/playersPickedInLeague.py @@ -1,10 +1,11 @@ -import requests +import argparse # noqa 401 import json +import logging +import sys + +import requests import unicodecsv as csv -import argparse from tqdm import tqdm -import logging, sys - FPL_URL = "https://fantasy.premierleague.com/api/" LOGIN_URL = "https://users.premierleague.com/accounts/login/" @@ -14,18 +15,18 @@ TEAM_ENTRY_SUBURL = "entry/" PLAYERS_INFO_SUBURL = "bootstrap-static/" PLAYERS_INFO_FILENAME = "output/allPlayersInfo.json" -USERNAME = 'fantasy@netmail3.net' -PASSWORD = 'FPLshow#123' +USERNAME = "fantasy@netmail3.net" +PASSWORD = "FPLshow#123" USER_SUMMARY_URL = FPL_URL + USER_SUMMARY_SUBURL PLAYERS_INFO_URL = FPL_URL + PLAYERS_INFO_SUBURL START_PAGE = 1 payload = { - 'login':USERNAME, - 'password':PASSWORD, - 'redirect_uri': 'https://fantasy.premierleague.com/', - 'app':'plfpl-web' + "login": USERNAME, + "password": PASSWORD, + "redirect_uri": "https://fantasy.premierleague.com/", + "app": "plfpl-web", } s = requests.session() s.post(LOGIN_URL, data=payload) @@ -34,7 +35,7 @@ def getPlayersInfo(): r = s.get(PLAYERS_INFO_URL) jsonResponse = r.json() - with open(PLAYERS_INFO_FILENAME, 'w') as outfile: + with open(PLAYERS_INFO_FILENAME, "w") as outfile: json.dump(jsonResponse, outfile) @@ -42,33 +43,42 @@ def getPlayersInfo(): # https://fantasy.premierleague.com/api/leagues-classic/43919/standings/?page_new_entries=1&page_standings=2&phase=1 def getUserEntryIds(league_id, ls_page, league_Standing_Url): entries = [] - while(True): - league_url = league_Standing_Url + str(league_id) + "/standings/" + "?page_new_entries=1&page_standings=" + str(ls_page) + "&phase=1" + while True: + league_url = ( + league_Standing_Url + + str(league_id) + + "/standings/" + + "?page_new_entries=1&page_standings=" + + str(ls_page) + + "&phase=1" + ) r = s.get(league_url) jsonResponse = r.json() managers = jsonResponse["standings"]["results"] if not managers: - print "Total managers :",len(entries) + print("Total managers :", len(entries)) break for player in managers: entries.append(player["entry"]) - ls_page+=1 + ls_page += 1 return entries - -# team picked by user. example: https://fantasy.premierleague.com/api/entry/2677936/event/1/picks with 2677936 being entry_id of the player +# team picked by user. example: https://fantasy.premierleague.com/api/entry/2677936/event/1/picks with 2677936 being entry_id of the player # noqa 501 def getplayersPickedForEntryId(entry_id, GWNumber): eventSubUrl = "event/" + str(GWNumber) + "/picks/" - playerTeamUrlForSpecificGW = FPL_URL + TEAM_ENTRY_SUBURL + str(entry_id) + "/" + eventSubUrl + playerTeamUrlForSpecificGW = ( + FPL_URL + TEAM_ENTRY_SUBURL + str(entry_id) + "/" + eventSubUrl + ) r = s.get(playerTeamUrlForSpecificGW) jsonResponse = r.json() try: picks = jsonResponse["picks"] - except: + except Exception as e: + print(e) if jsonResponse["detail"]: - print "entry_id "+str(entry_id)+" doesn't have info for this gameweek" + print("entry_id " + str(entry_id) + " doesn't have info for this gameweek") return None, None elements = [] captainId = 1 @@ -79,46 +89,53 @@ def getplayersPickedForEntryId(entry_id, GWNumber): return elements, captainId + # read player info from the json file that we downlaoded def getAllPlayersDetailedJson(): with open(PLAYERS_INFO_FILENAME) as json_data: d = json.load(json_data) return d + # writes the results to csv file def writeToFile(countOfplayersPicked, fileName): - with open(fileName, 'w') as out: + with open(fileName, "w") as out: csv_out = csv.writer(out) - csv_out.writerow(['name', 'num']) + csv_out.writerow(["name", "num"]) for row in countOfplayersPicked: csv_out.writerow(row) + # Main Script -parser = argparse.ArgumentParser(description='Get players picked in your league in a certain GameWeek') -parser.add_argument('-l','--league', help='league entry id', required=True) -parser.add_argument('-g','--gameweek', help='gameweek number', required=True) -parser.add_argument('-t', '--type', help='league type') -parser.add_argument('-d', '--debug', help='deubg mode on') +parser = argparse.ArgumentParser( + description="Get players picked in your league in a certain GameWeek" +) +parser.add_argument("-l", "--league", help="league entry id", required=True) +parser.add_argument("-g", "--gameweek", help="gameweek number", required=True) +parser.add_argument("-t", "--type", help="league type") +parser.add_argument("-d", "--debug", help="deubg mode on") args = vars(parser.parse_args()) -if args['debug']: +if args["debug"]: logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) getPlayersInfo() playerElementIdToNameMap = {} allPlayers = getAllPlayersDetailedJson() for element in allPlayers["elements"]: - playerElementIdToNameMap[element["id"]] = element["web_name"]#.encode('ascii', 'ignore') + playerElementIdToNameMap[element["id"]] = element[ + "web_name" + ] # .encode('ascii', 'ignore') countOfplayersPicked = {} countOfCaptainsPicked = {} totalNumberOfPlayersCount = 0 pageCount = START_PAGE -GWNumber = args['gameweek'] -leagueIdSelected = args['league'] +GWNumber = args["gameweek"] +leagueIdSelected = args["league"] -if args['type'] == "h2h": +if args["type"] == "h2h": leagueStandingUrl = FPL_URL + LEAGUE_H2H_STANDING_SUBURL print("h2h league mode") else: @@ -128,17 +145,17 @@ def writeToFile(countOfplayersPicked, fileName): try: entries = getUserEntryIds(leagueIdSelected, pageCount, leagueStandingUrl) -except Exception, err: - print "Error occured in getting entries/managers in the league." - print err +except Exception as e: + print("Error occured in getting entries/managers in the league.") + print(e) raise for entry in tqdm(entries): try: elements, captainId = getplayersPickedForEntryId(entry, GWNumber) - except Exception, err: - print "Error occured in getting palyers and captain of the entry/manager" - print err + except Exception as e: + print("Error occured in getting palyers and captain of the entry/manager") + print(e) raise if not elements: continue @@ -155,7 +172,17 @@ def writeToFile(countOfplayersPicked, fileName): else: countOfCaptainsPicked[captainName] = 1 -listOfcountOfplayersPicked = sorted(countOfplayersPicked.items(), key=lambda x: x[1], reverse=True) -writeToFile(listOfcountOfplayersPicked, "output/GW"+str(GWNumber)+" Players "+str(leagueIdSelected)+".csv") -listOfCountOfCaptainsPicked = sorted(countOfCaptainsPicked.items(), key=lambda x: x[1], reverse=True) -writeToFile(listOfCountOfCaptainsPicked, "output/GW"+str(GWNumber)+" Captains "+str(leagueIdSelected)+".csv") +listOfcountOfplayersPicked = sorted( + countOfplayersPicked.items(), key=lambda x: x[1], reverse=True +) +writeToFile( + listOfcountOfplayersPicked, + "output/GW" + str(GWNumber) + " Players " + str(leagueIdSelected) + ".csv", +) +listOfCountOfCaptainsPicked = sorted( + countOfCaptainsPicked.items(), key=lambda x: x[1], reverse=True +) +writeToFile( + listOfCountOfCaptainsPicked, + "output/GW" + str(GWNumber) + " Captains " + str(leagueIdSelected) + ".csv", +) diff --git a/ppm.py b/ppm.py index 09d83c5..1fcd48b 100644 --- a/ppm.py +++ b/ppm.py @@ -1,7 +1,8 @@ -import requests -import json -import csv import argparse +import csv +import json + +import requests FPL_URL = "https://fantasy.premierleague.com/api/" USER_SUMMARY_SUBURL = "element-summary/" @@ -19,7 +20,7 @@ def getPlayersInfo(): r = requests.get(PLAYERS_INFO_URL) jsonResponse = r.json() - with open(PLAYERS_INFO_FILENAME, 'w') as outfile: + with open(PLAYERS_INFO_FILENAME, "w") as outfile: json.dump(jsonResponse, outfile) @@ -29,27 +30,44 @@ def getAllPlayersDetailedJson(): d = json.load(json_data) return d + # writes the results to csv file def writeToFile(countOfplayersPicked, fileName): - with open(fileName, 'w') as out: + with open(fileName, "w") as out: csv_out = csv.writer(out) - csv_out.writerow(['name', 'num']) + csv_out.writerow(["name", "num"]) for row in countOfplayersPicked: csv_out.writerow(row) + def weird_division(n, d): return n / d if d else 0 + # Main Script getPlayersInfo() playerElementIdToNameMap = {} allPlayers = getAllPlayersDetailedJson() -playerElementIdToNameMap[0] = ",".join(["Name", "Position", "Total Score", "Minutes Played", "Cost", "points_per_game", "points_per_game_per_million", "Bonus per 90", "Points per 90", "Points per million", "Points per million per 90"]) +playerElementIdToNameMap[0] = ",".join( + [ + "Name", + "Position", + "Total Score", + "Minutes Played", + "Cost", + "points_per_game", + "points_per_game_per_million", + "Bonus per 90", + "Points per 90", + "Points per million", + "Points per million per 90", + ] +) for element in allPlayers["elements"]: -# if element["minutes"] < 1000: -# continue + # if element["minutes"] < 1000: + # continue totalScore = element["total_points"] minutesPlayed = element["minutes"] cost = element["now_cost"] / 10.0 @@ -57,14 +75,28 @@ def weird_division(n, d): points_per_game = float(element["points_per_game"]) points_per_game_per_million = round(points_per_game / cost, 2) appearances = minutesPlayed / 90.0 - pointsPer90 = round(weird_division(totalScore , appearances), 2) - pointsPerMillion = round(weird_division(totalScore , cost), 2) - pointsPerMillionPer90 = round(weird_division(pointsPer90 , cost), 2) - bonusPer90 = round(weird_division(element["bonus"] , appearances), 2) - name = element["web_name"].encode('ascii', 'ignore') - playerElementIdToNameMap[element["id"]] = ",".join([name, str(position), str(totalScore), str(minutesPlayed), str(cost), str(points_per_game), str(points_per_game_per_million), str(bonusPer90), str(pointsPer90), str(pointsPerMillion), str(pointsPerMillionPer90)]) + pointsPer90 = round(weird_division(totalScore, appearances), 2) + pointsPerMillion = round(weird_division(totalScore, cost), 2) + pointsPerMillionPer90 = round(weird_division(pointsPer90, cost), 2) + bonusPer90 = round(weird_division(element["bonus"], appearances), 2) + name = element["web_name"].encode("ascii", "ignore") + playerElementIdToNameMap[element["id"]] = ",".join( + [ + name, + str(position), + str(totalScore), + str(minutesPlayed), + str(cost), + str(points_per_game), + str(points_per_game_per_million), + str(bonusPer90), + str(pointsPer90), + str(pointsPerMillion), + str(pointsPerMillionPer90), + ] + ) print(playerElementIdToNameMap) -with open("output/ppm.csv", 'w') as f: +with open("output/ppm.csv", "w") as f: for key, value in playerElementIdToNameMap.items(): f.write(value + "\n") From 079f8c830cd43b53da14583ceb3304f85e09c6fd Mon Sep 17 00:00:00 2001 From: Nikolay Tsvetanov Date: Mon, 28 Aug 2023 22:22:11 +0300 Subject: [PATCH 2/5] rename some variables --- playersPickedInLeague.py | 203 ++++++++++++++++++++------------------- 1 file changed, 104 insertions(+), 99 deletions(-) diff --git a/playersPickedInLeague.py b/playersPickedInLeague.py index 8c1d65d..f0cbd59 100644 --- a/playersPickedInLeague.py +++ b/playersPickedInLeague.py @@ -22,64 +22,66 @@ PLAYERS_INFO_URL = FPL_URL + PLAYERS_INFO_SUBURL START_PAGE = 1 -payload = { +PAYLOAD = { "login": USERNAME, "password": PASSWORD, "redirect_uri": "https://fantasy.premierleague.com/", "app": "plfpl-web", } -s = requests.session() -s.post(LOGIN_URL, data=payload) +session = requests.session() +session.post(LOGIN_URL, data=PAYLOAD) + -# Download all player data: https://fantasy.premierleague.com/api/bootstrap-static def getPlayersInfo(): - r = s.get(PLAYERS_INFO_URL) - jsonResponse = r.json() + # Download all player data: https://fantasy.premierleague.com/api/bootstrap-static + result = session.get(PLAYERS_INFO_URL) with open(PLAYERS_INFO_FILENAME, "w") as outfile: - json.dump(jsonResponse, outfile) + json.dump(result.json(), outfile) -# Get users in league: -# https://fantasy.premierleague.com/api/leagues-classic/43919/standings/?page_new_entries=1&page_standings=2&phase=1 -def getUserEntryIds(league_id, ls_page, league_Standing_Url): +def getUserEntryIds(league_id, page_count, league_standing_url): + # Get users in league: + # https://fantasy.premierleague.com/api/leagues-classic/43919/standings/?page_new_entries=1&page_standings=2&phase=1 entries = [] while True: league_url = ( - league_Standing_Url + league_standing_url + str(league_id) + "/standings/" + "?page_new_entries=1&page_standings=" - + str(ls_page) + + str(page_count) + "&phase=1" ) - r = s.get(league_url) - jsonResponse = r.json() - managers = jsonResponse["standings"]["results"] + result = session.get(league_url) + managers = result.json()["standings"]["results"] if not managers: print("Total managers :", len(entries)) break for player in managers: entries.append(player["entry"]) - ls_page += 1 + + page_count += 1 return entries -# team picked by user. example: https://fantasy.premierleague.com/api/entry/2677936/event/1/picks with 2677936 being entry_id of the player # noqa 501 + def getplayersPickedForEntryId(entry_id, GWNumber): + # team picked by user. example: https://fantasy.premierleague.com/api/entry/2677936/event/1/picks with 2677936 being entry_id of the player # noqa 501 eventSubUrl = "event/" + str(GWNumber) + "/picks/" playerTeamUrlForSpecificGW = ( FPL_URL + TEAM_ENTRY_SUBURL + str(entry_id) + "/" + eventSubUrl ) - r = s.get(playerTeamUrlForSpecificGW) - jsonResponse = r.json() + + result = session.get(playerTeamUrlForSpecificGW).json() try: - picks = jsonResponse["picks"] + picks = result["picks"] except Exception as e: print(e) - if jsonResponse["detail"]: + if result["detail"]: print("entry_id " + str(entry_id) + " doesn't have info for this gameweek") return None, None + elements = [] captainId = 1 for pick in picks: @@ -90,15 +92,14 @@ def getplayersPickedForEntryId(entry_id, GWNumber): return elements, captainId -# read player info from the json file that we downlaoded def getAllPlayersDetailedJson(): + # read player info from the json file that we downloaded with open(PLAYERS_INFO_FILENAME) as json_data: - d = json.load(json_data) - return d + return json.load(json_data) -# writes the results to csv file def writeToFile(countOfplayersPicked, fileName): + # writes the results to csv file with open(fileName, "w") as out: csv_out = csv.writer(out) csv_out.writerow(["name", "num"]) @@ -106,83 +107,87 @@ def writeToFile(countOfplayersPicked, fileName): csv_out.writerow(row) -# Main Script - -parser = argparse.ArgumentParser( - description="Get players picked in your league in a certain GameWeek" -) -parser.add_argument("-l", "--league", help="league entry id", required=True) -parser.add_argument("-g", "--gameweek", help="gameweek number", required=True) -parser.add_argument("-t", "--type", help="league type") -parser.add_argument("-d", "--debug", help="deubg mode on") -args = vars(parser.parse_args()) - -if args["debug"]: - logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) - -getPlayersInfo() -playerElementIdToNameMap = {} -allPlayers = getAllPlayersDetailedJson() -for element in allPlayers["elements"]: - playerElementIdToNameMap[element["id"]] = element[ - "web_name" - ] # .encode('ascii', 'ignore') - -countOfplayersPicked = {} -countOfCaptainsPicked = {} -totalNumberOfPlayersCount = 0 -pageCount = START_PAGE -GWNumber = args["gameweek"] -leagueIdSelected = args["league"] - -if args["type"] == "h2h": - leagueStandingUrl = FPL_URL + LEAGUE_H2H_STANDING_SUBURL - print("h2h league mode") -else: - leagueStandingUrl = FPL_URL + LEAGUE_CLASSIC_STANDING_SUBURL - print("classic league mode") - - -try: - entries = getUserEntryIds(leagueIdSelected, pageCount, leagueStandingUrl) -except Exception as e: - print("Error occured in getting entries/managers in the league.") - print(e) - raise - -for entry in tqdm(entries): +def main(): + # Main Script + parser = argparse.ArgumentParser( + description="Get players picked in your league in a certain GameWeek", + ) + parser.add_argument("-l", "--league", help="league entry id", required=True) + parser.add_argument("-g", "--gameweek", help="gameweek number", required=True) + parser.add_argument("-t", "--type", help="league type") + parser.add_argument("-d", "--debug", help="deubg mode on") + args = vars(parser.parse_args()) + + if args["debug"]: + logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) + + getPlayersInfo() + playerElementIdToNameMap = {} + allPlayers = getAllPlayersDetailedJson() + for element in allPlayers["elements"]: + playerElementIdToNameMap[element["id"]] = element["web_name"] + + countOfplayersPicked = {} + countOfCaptainsPicked = {} + GWNumber = args["gameweek"] + leagueIdSelected = args["league"] + + if args["type"] == "h2h": + leagueStandingUrl = FPL_URL + LEAGUE_H2H_STANDING_SUBURL + print("h2h league mode") + else: + leagueStandingUrl = FPL_URL + LEAGUE_CLASSIC_STANDING_SUBURL + print("classic league mode") + try: - elements, captainId = getplayersPickedForEntryId(entry, GWNumber) + entries = getUserEntryIds(leagueIdSelected, START_PAGE, leagueStandingUrl) except Exception as e: - print("Error occured in getting palyers and captain of the entry/manager") + print("Error occured in getting entries/managers in the league.") print(e) raise - if not elements: - continue - for element in elements: - name = playerElementIdToNameMap[element] - if name in countOfplayersPicked: - countOfplayersPicked[name] += 1 + + for entry in tqdm(entries): + try: + elements, captainId = getplayersPickedForEntryId(entry, GWNumber) + except Exception as e: + print("Error occured in getting palyers and captain of the entry/manager") + print(e) + raise + if not elements: + continue + for element in elements: + name = playerElementIdToNameMap[element] + if name in countOfplayersPicked: + countOfplayersPicked[name] += 1 + else: + countOfplayersPicked[name] = 1 + + captainName = playerElementIdToNameMap[captainId] + if captainName in countOfCaptainsPicked: + countOfCaptainsPicked[captainName] += 1 else: - countOfplayersPicked[name] = 1 + countOfCaptainsPicked[captainName] = 1 - captainName = playerElementIdToNameMap[captainId] - if captainName in countOfCaptainsPicked: - countOfCaptainsPicked[captainName] += 1 - else: - countOfCaptainsPicked[captainName] = 1 - -listOfcountOfplayersPicked = sorted( - countOfplayersPicked.items(), key=lambda x: x[1], reverse=True -) -writeToFile( - listOfcountOfplayersPicked, - "output/GW" + str(GWNumber) + " Players " + str(leagueIdSelected) + ".csv", -) -listOfCountOfCaptainsPicked = sorted( - countOfCaptainsPicked.items(), key=lambda x: x[1], reverse=True -) -writeToFile( - listOfCountOfCaptainsPicked, - "output/GW" + str(GWNumber) + " Captains " + str(leagueIdSelected) + ".csv", -) + listOfcountOfplayersPicked = sorted( + countOfplayersPicked.items(), + key=lambda x: x[1], + reverse=True, + ) + writeToFile( + listOfcountOfplayersPicked, + "output/GW" + str(GWNumber) + " Players " + str(leagueIdSelected) + ".csv", + ) + + listOfCountOfCaptainsPicked = sorted( + countOfCaptainsPicked.items(), + key=lambda x: x[1], + reverse=True, + ) + writeToFile( + listOfCountOfCaptainsPicked, + "output/GW" + str(GWNumber) + " Captains " + str(leagueIdSelected) + ".csv", + ) + + +if __name__ == "__main__": + main() From 0826fabce61c38baf4f38cb568aaa72e6b0db2f6 Mon Sep 17 00:00:00 2001 From: Nikolay Tsvetanov Date: Mon, 28 Aug 2023 22:29:08 +0300 Subject: [PATCH 3/5] fix filenames and write to csv function. --- playersPickedInLeague.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/playersPickedInLeague.py b/playersPickedInLeague.py index f0cbd59..1896ce4 100644 --- a/playersPickedInLeague.py +++ b/playersPickedInLeague.py @@ -100,7 +100,8 @@ def getAllPlayersDetailedJson(): def writeToFile(countOfplayersPicked, fileName): # writes the results to csv file - with open(fileName, "w") as out: + print(countOfplayersPicked, fileName) + with open(fileName, "wb") as out: csv_out = csv.writer(out) csv_out.writerow(["name", "num"]) for row in countOfplayersPicked: @@ -175,7 +176,7 @@ def main(): ) writeToFile( listOfcountOfplayersPicked, - "output/GW" + str(GWNumber) + " Players " + str(leagueIdSelected) + ".csv", + f"output/GW{GWNumber}Players{leagueIdSelected}.csv", ) listOfCountOfCaptainsPicked = sorted( @@ -185,7 +186,7 @@ def main(): ) writeToFile( listOfCountOfCaptainsPicked, - "output/GW" + str(GWNumber) + " Captains " + str(leagueIdSelected) + ".csv", + f"output/GW{GWNumber}Captains{leagueIdSelected}.csv", ) From fce71ec7485a2769fb766cd62685a4d5a82d24c7 Mon Sep 17 00:00:00 2001 From: Nikolay Tsvetanov Date: Mon, 28 Aug 2023 22:57:07 +0300 Subject: [PATCH 4/5] introduce user and password as env variables --- playersPickedInLeague.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/playersPickedInLeague.py b/playersPickedInLeague.py index 1896ce4..c853e3d 100644 --- a/playersPickedInLeague.py +++ b/playersPickedInLeague.py @@ -1,6 +1,7 @@ import argparse # noqa 401 import json import logging +import os import sys import requests @@ -15,16 +16,14 @@ TEAM_ENTRY_SUBURL = "entry/" PLAYERS_INFO_SUBURL = "bootstrap-static/" PLAYERS_INFO_FILENAME = "output/allPlayersInfo.json" -USERNAME = "fantasy@netmail3.net" -PASSWORD = "FPLshow#123" USER_SUMMARY_URL = FPL_URL + USER_SUMMARY_SUBURL PLAYERS_INFO_URL = FPL_URL + PLAYERS_INFO_SUBURL START_PAGE = 1 PAYLOAD = { - "login": USERNAME, - "password": PASSWORD, + "login": os.environ.get("USERNAME", "fantasy@netmail3.net"), + "password": os.environ.get("PASSWORD", "FPLshow#123"), "redirect_uri": "https://fantasy.premierleague.com/", "app": "plfpl-web", } @@ -77,7 +76,6 @@ def getplayersPickedForEntryId(entry_id, GWNumber): try: picks = result["picks"] except Exception as e: - print(e) if result["detail"]: print("entry_id " + str(entry_id) + " doesn't have info for this gameweek") return None, None @@ -100,7 +98,6 @@ def getAllPlayersDetailedJson(): def writeToFile(countOfplayersPicked, fileName): # writes the results to csv file - print(countOfplayersPicked, fileName) with open(fileName, "wb") as out: csv_out = csv.writer(out) csv_out.writerow(["name", "num"]) From c6e2fa24797581e6ad2422f912364de448f3e692 Mon Sep 17 00:00:00 2001 From: Nikolay Tsvetanov Date: Mon, 28 Aug 2023 23:13:36 +0300 Subject: [PATCH 5/5] drop unicodecsv dependency --- playersPickedInLeague.py | 4 ++-- requirements.txt | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/playersPickedInLeague.py b/playersPickedInLeague.py index c853e3d..85fa19d 100644 --- a/playersPickedInLeague.py +++ b/playersPickedInLeague.py @@ -1,11 +1,11 @@ import argparse # noqa 401 +import csv import json import logging import os import sys import requests -import unicodecsv as csv from tqdm import tqdm FPL_URL = "https://fantasy.premierleague.com/api/" @@ -98,7 +98,7 @@ def getAllPlayersDetailedJson(): def writeToFile(countOfplayersPicked, fileName): # writes the results to csv file - with open(fileName, "wb") as out: + with open(fileName, "w") as out: csv_out = csv.writer(out) csv_out.writerow(["name", "num"]) for row in countOfplayersPicked: diff --git a/requirements.txt b/requirements.txt index c3dea3d..5af97f4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ -requests==2.21.0 -tqdm==4.35.0 -unicodecsv==0.14.1 +requests==2.31.0 +tqdm==4.66.1