GithubHelp home page GithubHelp logo

wiscostret / fplscrapr Goto Github PK

View Code? Open in Web Editor NEW
72.0 72.0 16.0 4.08 MB

This package enables those interested in Fantasy Premier League to perform detailed data analysis of the game, using the FPL's JSON API. The fplscrapR functions help R users collect and parse data from the Official Fantasy Premier League website.

License: Creative Commons Zero v1.0 Universal

R 100.00%
fantasy-football fantasy-premier-league football fpl fpl-json-api

fplscrapr's People

Contributors

eivindhammers avatar wiscostret avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fplscrapr's Issues

parse_con error in get_player_details()

Hello, at at the moment I've already installed the latest version of fplscrapR and find an error on get_player_details()

When I run,

get_player_details()

I got the following error:

Error in parse_con(txt, bigint_as_char) : parse error: premature EOF (right here) ------^
8. | parse_con(txt, bigint_as_char)
7. | parseJSON(txt, bigint_as_char)
6. | parse_and_simplify(txt = txt, simplifyVector = simplifyVector, simplifyDataFrame = simplifyDataFrame, simplifyMatrix = simplifyMatrix, flatten = flatten, ...)
5. | jsonlite::fromJSON(url(paste("https://fantasy.premierleague.com/api/element-summary/", elements$id[i], "/", sep = "")))
4. | ifelse(is.null(name), { detinfo <- data.frame() for (i in 1:nrow(elements)) { fplboot <- jsonlite::fromJSON(url(paste("https://fantasy.premierleague.com/api/element-summary/", ...
3. | ifelse(is.null(playerid), ifelse(is.null(name), { detinfo <- data.frame() for (i in 1:nrow(elements)) { fplboot <- jsonlite::fromJSON(url(paste("https://fantasy.premierleague.com/api/element-summary/", ...
2. | ifelse(!is.null(season), { detinfo <- read.csv(paste0("https://raw.githubusercontent.com/wiscostret/histfpldata/master/getplayerdetails", season, ".csv"), encoding = "UTF-8") ifelse(is.null(playerid), ifelse(is.null(name), return(detinfo), ...

  1. | get_player_details()

The same error occured when I run specific player, such as

get_player_details(name = "Mohamed Salah")

I've been looking for solution elsewhere but nothing works

I'm using R version 3.6.1 (2019-07-05) and MacOS 10.15.1

Thank you for your attention!

Dhanes

Package installation issue

I have tried to get started with the fplscrapR package as per the readme using RStudio v1.2.5001:

if (!require(remotes)) {
install.packages("remotes")
}

remotes::install_github("wiscostret/fplscrapR")

library(fplscrapR)

However the following error is occuring:

ERROR: dependency 'vctrs' is not available for package 'pillar'

  • removing 'C:/Users/HP/Documents/R/win-library/3.3/pillar'
    Error: Failed to install 'fplscrapR' from GitHub:
    (converted from warning) running command '"C:/PROGRA~1/R/R-33~1.2/bin/x64/R" CMD INSTALL -l "C:\Users\HP\Documents\R\win-library\3.3" C:\Users\HP\AppData\Local\Temp\RtmpGUcyj8/downloaded_packages/pillar_1.4.2.tar.gz' had status 1
    library(fplscrapR)
    Error in library(fplscrapR) : there is no package called ‘fplscrapR’

Much appreciated!

Install problem

Hi,
I am new to R, so please forgive if this is a silly question.
Having problems installing fplscrapR. See below.
Please help?

install.packages("fplscrapr")
Installing package into ‘C:/Users/Shane/Documents/R/win-library/3.3’
(as ‘lib’ is unspecified)
Warning in install.packages :
package ‘fplscrapr’ is not available (for R version 3.3.3)
library(fplscrapr)

if (!require(remotes)) {

  • install.packages("remotes")
  • }
    Loading required package: remotes

remotes::install_github("wiscostret/fplscrapR")
Downloading GitHub repo wiscostret/fplscrapR@master
Error in utils::download.file(url, path, method = download_method(), quiet = quiet, :
cannot download all files
library(fplscrapR)
Error in library(fplscrapR) : there is no package called ‘fplscrapR’

``

Error in open.connection(con, "rb")

Hello.

I am currently working on a project that has an optimal selection of FPL players and has been using the fplscrapR package. It is great and allows easy access to data.
I'm trying to use it to get the player's score for each game week for the last three years, but I'm having some problems trying to understand how to use the function and run an example of it.

get_entry_player_picks(1076,1)
Error in open.connection(con, "rb") : HTTP error 404.

(Articles: https://wiscostret.github.io/fplscrapR/articles/hazalexishist.html)

df <- get_player_hist ( playerid = get_player_id ( c ( "Mesut Özil" , "Juan Mata" ))$ id )
Error in open.connection(con, "rb") : cannot open the connection
In addition: Warning message:
In open.connection(con, "rb") :
cannot open URL 'https://fantasy.premierleague.com/api/element-summary/NA/': HTTP status was '404 Not Found'

I initially thought the problem was on my computer and tried turning off the windows firewall, but I still can't get the data. Has anyone else had the same problem recently? If you have any time to get back to me I would be very grateful.

Obtain specific page for get_league_entries()

Thank you for this great package!

Apologies in advance for a long issue, but I have a bit of a niche request for get_league_entries() and hopefully it is helpful!

Basically I'd like to obtain the amount of points needed for a given overall rank. Because each page's length is 50, it's quite easy to work out that for the overall standings page 2000 is required for rank 100, 000 (100000 / 50).

# Get page 200
df_ranks <- get_league_entries(leagueid = 314, pages = 2000)
# Takes a long time

df_rank_10000 <- df_ranks %>%
  dplyr::filter(rank_sort == 100000) %>%
  dplyr::select(rank = rank_sort, total)

Because get_league_entries() loops for (i in 1:pages), all pages are always obtained, even though we're only interested in page 2000. This can take a long time to run, especially if I'm interest in rank 1 million, for example.

So, I'm proposing to add some functionality to get_league_entries(), by being able to specify a page. Some limitations I tried to stick to:

  • Not breaking current usage.
  • Being able to pass a list of pages
  • Not breaking current stop() functionality

I think the best approach is to add a logical argument, specificpage, which defaults to FALSE. When set to TRUE by the user it will obtain that page only. As far as I can tell, this works without breaking current usage:

get_league_entries <- function(leagueid = NULL,
                               leaguetype = "classic",
                               pages = 1,
                               specificpage = FALSE){
  if(is.null(leagueid)) stop("You'll need to input a league ID, mate.")
  if(length(leagueid) != 1) stop("One league at a time, please.")
  if(is.list(pages) & isFALSE(specificpage)) stop("Can only supply a list if specificpage == TRUE")
  if(!is.list(pages)) if(pages %% 1 != 0) stop(
    "The number of pages needs to be a whole number, or a list of numbers when specificpage == TRUE."
  )
  if(!is.logical(specificpage)) stop("specificpage can only be TRUE/FALSE")
  
  {
    entries <- data.frame()
    if(specificpage == FALSE) {
      for (i in 1:pages){
        
        standings <- jsonlite::fromJSON(
          paste(
            "https://fantasy.premierleague.com/api/leagues-",
            leaguetype,
            "/",
            leagueid,
            "/standings/?page_standings=",
            i,
            sep = "")
        )
        
        entries <- rbind(entries, standings$standings$results)
        
      }
    } else if(specificpage == TRUE) {
      for(i in pages) {
        standings <- jsonlite::fromJSON(
          paste(
            "https://fantasy.premierleague.com/api/leagues-",
            leaguetype,
            "/",
            leagueid,
            "/standings/?page_standings=",
            i,
            sep = "")
        )
        
        entries <- rbind(entries,standings$standings$results)
      }
    }
    return(entries)
  }
}

So as an example, if I want to know the points required for 1, 100, 1000, 10000:

ranks_of_interest <- c(1, 100, 1000, 10000)

list_of_pages <- ceiling(ranks_of_interest/50) %>%
  as.list()

ranks <- get_league_entries(leagueid = 314,
                            pages = list_of_pages,
                            specificpage = TRUE)

ranks <- ranks %>%
  dplyr::filter(rank_sort %in% ranks_of_interest) %>%
  dplyr::select(rank = rank_sort, total)

# In Gameweek 6:
> ranks
    rank total
1      1   492
2    100   459
3   1000   444
4  10000   428
5 100000   408

Which leads us nicely into a new function:

get_points_for_rank <- function(ranks_of_interest) {
  list_of_pages <- ceiling(ranks_of_interest/50) %>%
    as.list()
  
  ranks <- get_league_entries(leagueid = 314,
                              pages = list_of_pages,
                              specificpage = TRUE)
  
  ranks <- ranks %>%
    dplyr::filter(rank_sort %in% ranks_of_interest) %>%
    dplyr::select(rank = rank_sort, total)
}

I'll open a PR for you to review, and whether this is functionality you'd like to add this to get_league_entries() or if it should be a new function altogether.

I don't think this breaks anything, but you will know much better than I do. Happy to make changes and go with what you think is best.

Get Games List

Hi There,

Great package, the get_game_listfunction only seems to work for season 18/19. Not current season or any of the previous seasons

Cheers

Install package

I've tried to install fplscrapR using RStudio 1.2.5001 and get the following error message:

install.packages("fplscrapR")
Warning in install.packages :
package ‘fplscrapR’ is not available (for R version 3.6.1)

Any help appreciated!

JSON parsing error with `get_player_details()`

Getting the following error when trying to render an .Rmd code block containing fplscrapR::get_player_details() with no arguments (so as to return this seasons' stats)

Rendering 2020-01-25-fantasy-premier-league-1.Rmd
Quitting from lines 67-72 (2020-01-25-fantasy-premier-league-1.Rmd) 
Error in parse_con(txt, bigint_as_char) : parse error: premature EOF
                                       
                     (right here) ------^
Calls: local ... <Anonymous> -> parse_and_simplify -> parseJSON -> parse_con
Execution halted

Last Years Data

Hiya,

I built a few things in March/April time using last years (2018-19) data. Is there any way of accessing the old data with fplscrapR?

Been enjoying using the tool though, thanks!

Error installing fplscrapR

I run the code and get the following screen:

library(remotes)
install_github("wiscostret/fplscrapR")
Downloading GitHub repo wiscostret/fplscrapR@master
These packages have more recent versions available.
Which would you like to update?

1: All
2: CRAN packages only
3: None
4: dplyr (0.8.2 -> 0.8.3 ) [CRAN]
5: vctrs (0.1.0 -> 0.2.0 ) [CRAN]
6: digest (0.6.19 -> 0.6.20) [CRAN]

Enter one or more numbers, or an empty line to skip updates:
1
dplyr (0.8.2 -> 0.8.3 ) [CRAN]
vctrs (0.1.0 -> 0.2.0 ) [CRAN]
ellipsis (NA -> 0.2.0.1) [CRAN]
digest (0.6.19 -> 0.6.20 ) [CRAN]

I select the option to update all (although I receive an error for each option) and it successfully updates the packages

package ‘dplyr’ successfully unpacked and MD5 sums checked
package ‘vctrs’ successfully unpacked and MD5 sums checked
package ‘ellipsis’ successfully unpacked and MD5 sums checked
package ‘digest’ successfully unpacked and MD5 sums checked

I then get the following issue related to fplscrapR

Installing package into ‘C:/Users/Matt/Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
*installing source package 'fplscrapR' ...
** using staged installation
** R
** byte-compile and prepare package for lazy loading
Error in open.connection(con, "rb") : HTTP error 403.
Error: unable to load R code in package 'fplscrapR'
Execution halted
ERROR: lazy loading failed for package 'fplscrapR'
*removing 'C:/Users/Matt/Documents/R/win-library/3.6/fplscrapR'
Error: Failed to install 'fplscrapR' from GitHub:
(converted from warning) installation of package ‘C:/Users/Matt/AppData/Local/Temp/RtmpCqCqmP/file1fcc67a878db/fplscrapR_0.1.0.tar.gz’ had non-zero exit status

I'm assuming this means that for whatever reason I don't have access and that it may be an issue on my end regarding the network but I can't figure out what that might be, figured I'd check this isn't a github or fplscrapR related error

get_player_details()

I'm trying to call get_player_details() to get gameweek level data for all players this season, but I get this error:

Error in data.frame(fplboot, playername = elements$playername[which(elements$id == :
arguments imply differing number of rows: 0, 1

I've also tried get_player_details(season = '21') but I get this error:

Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open URL 'https://raw.githubusercontent.com/wiscostret/histfpldata/master/getplayerdetails21.csv': HTTP status was '404 Not Found'

Can't get function to work with current season data

Hello,
I'm trying to create a function that takes a vector of player names as an input and outputs a dataframe of their week by week scores using get_player_info(). The function works if I specify season = 18 but I can't get it to work for the current season.

Here's the code that works:
fn = function(team){
df <- data.frame(matrix(ncol = 0, nrow = 38))
for(i in team){
points = get_player_details(name = i, season = 18)$total_points
df[,i] = points
}
return(df)
}

df1 = fn(team)

but removing season = 18 and changing nrow to 29 (29 gameweeks) gives me this error:

Error in [<-.data.frame(*tmp*, , i, value = c(0L, 1L, 0L, 1L, 3L, :
replacement has 28 rows, data has 29

I'm new to R and I can't quite figure out why. Any help would be appreciated! Thanks :)

Is not working anymore?

I found that it is not working anymore and try to reinstall but there is a problem and I can't. Any news?

R Version 4.0.2

Hello,

Not sure if this is the best place to ask, but I'm getting this error:

package ‘fplscrapR’ is not available (for R version 4.0.2)

What R version is needed to install fplscrapR?

Function request: get_player_ids

Hello,

Thanks for this terrific package. One small feature request - a function that can make a list of all player ids (or names - but these aren't always unique - e.g. Ben Davies) for the current season.

get_player_details works great if you have the id or name, as does get_player_id if you know the player name - so what would be great is something like get_player_ids that returns all the player ids (or at least the maximum one, given they're assigned sequentially per season). Then we can do something like:

player_ids <- get_player_ids
*apply / purrr:map_*(player_ids, get_player_details)

to automatically get the details for all players at once. Currently, if I want to do that, I have to do a binary search on the player id until I get the maximum id get_player_details will accept without throwing an error.

Authentication issues using get_league and get_league_entries

First of all, thanks for sharing this great package. I've been using it with great pleasure for a few years.

Since the 2021/2022 season I have authentication issues when using the get_leagues functions to scrape my mini leagues. I did not have this issue previously.

Specifically, R provides the following error message after entering my login and password:

Error in open.connection(con, "rb") : HTTP error 405.

I reinstalled the fplscrapR package and I've minimized the code into a reproducible example:

library(fplscrapR)
FPL <- get_league_entries(45536, "classic", pages=2)

Unfortunately I cant find any info about the specific error message.

get_player_details error

I tried running get_player_details(name="Mohamed Salah") in R and I'm receiving the following error.
Error in open.connection(con, "rb") : cannot open the connection
In addition: Warning message:
In open.connection(con, "rb") :
InternetOpenUrl failed: 'The operation timed out'

Missing variables in get_player_details for season 19/20

Hi!

First of all, I just want to say that I really appreciate your work with the fplscrapR-package! :)
I am trying to build an expected assist model for season 19/20 prior to the upcoming season, but when I load a data frame for season19/20 using the get_player_details function I do not find key_passes and open_play_crosses in order to make the vector "potential assists".
Is there a way that I could access that?

Cheers!

Error message from "get_player_details() "

Hi everybody. Just contacting you by the error from get_player_details() from gplscrapR

When I run it

library(fplscrapR)

df <- get_player_details()

give me the following error:

library(fplscrapR)
df <- get_player_details() # this may take a while to load as it fetches ALL player details Error in data.frame(fplboot, playername = elements$playername[which(elements$id == : arguments imply differing number of rows: 0, 1
--
| >

Sometimes manage to pass this step clearly

df 589 obs. of 54 variables

and when I run the next step

df %>%
filter(round %in% 1:20) %>% # filtering for the GWs we are interested in
select(playername,goals_scored,assists) %>% # selecting the relevant columns
group_by(playername) %>% # transformation to group and summarize the performance at the 'playername' variable level
summarize_all(sum) %>%
mutate("involvements"=goals_scored+assists) %>% # adding a new variable that sums the goals scored and assists
arrange(-involvements) %>% # ordering (arranging) the table by top involvements
slice(1:20) # showing the top20 only

give me the following error message

df %>%

  • filter(round %in% 1:20) %>% # filtering for the GWs we are interested in
  • select(playername,goals_scored,assists) %>% # selecting the relevant columns
  • group_by(playername) %>% # transformation to group and summarize the performance at the 'playername' variable level
  • summarize_all(sum) %>%
  • mutate("involvements"=goals_scored+assists) %>% # adding a new variable that sums the goals scored and assists
  • arrange(-involvements) %>% # ordering (arranging) the table by top involvements
  • slice(1:20) # showing the top20 only
    Error in match(x, table, nomatch = 0L) :
    'match' requires vector arguments

And before didn't happen and run properly.

If you could take a look I appreciate it. For any further information or details don't hesitate to contact me.

Thank you. Enrique

SSL certificate problem: certificate has expired

I think there's an issue with the API endpoint for this season's data? When I call get_player_details() or get_game_list() for this season it's showing this error. Not sure if it's just me or if I'm doing something wrong here :D

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.