Skip to content

Commit

Permalink
v1.0.1 add support for XBox One and PC
Browse files Browse the repository at this point in the history
  • Loading branch information
danielredondo committed May 3, 2021
1 parent 629d1d5 commit e272d92
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 900 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.RData
.Ruserdata
.DS_Store

README.html
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rfutbin
Type: Package
Title: Searchs FIFA Ultimate Team players to get stats and prices in Futbin
Version: 1.0.0
Version: 1.0.1
Authors@R: person("Daniel", "Redondo-Sanchez", email = "danielredondosanchez@hotmail.com",
role = c("aut", "cre"))
Maintainer: Daniel Redondo Sánchez <danielredondosanchez@hotmail.com>
Expand All @@ -14,7 +14,7 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Depends: R (>= 3.5)
Imports: dplyr, rvest, magrittr, xml2, radarchart
Imports: dplyr, rvest, httr, magrittr, xml2, radarchart
Suggests:
URL: https://github.com/danielredondo/rfutbin/
BugReports: https://github.com/danielredondo/rfutbin/issues
Expand Down
11 changes: 8 additions & 3 deletions R/futbin_scrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' @param url Futbin URL to web scrap.
#' Futbin webpage (https://www.futbin.com/players) can be used to make customised filters, and then copy the URL here.
#' All the players found in the URL (and the next pages) will be automatically detected and downloaded.
#' @param platform Platform to get the prices from. Default is `ps4`. Other options are `xone` (XBox One) and `pc`.
#' @param sleep_time Time (in seconds) ellapsed between scraping one page and the next one. Please respect Futbin API.
#' @param verbose Optional. To show additional verbose about webpage used and number of players found.
#' @return A dataframe with all the players found at the URL.
Expand All @@ -17,7 +18,7 @@
#' futbin_scrap(url = "https://www.futbin.com/players?page=1&nation=45&league=53&position=CB")
#' }

futbin_scrap <- function(url, sleep_time = 5, verbose = TRUE) {
futbin_scrap <- function(url, platform = "ps4", sleep_time = 5, verbose = TRUE) {

url_split <- strsplit(x = url, split = "page=1", fixed = TRUE) %>% unlist

Expand All @@ -35,14 +36,18 @@ futbin_scrap <- function(url, sleep_time = 5, verbose = TRUE) {

# Web scraping
if (i == 1) {
tabla <- xml2::read_html(url_to_scrap) %>%
tabla <- httr::GET(url_to_scrap,
httr::set_cookies(platform = platform)) %>%
httr::content() %>%
rvest::html_nodes(xpath = "//table") %>%
magrittr::extract(1) %>%
rvest::html_table() %>%
magrittr::extract2(1)
} else {
Sys.sleep(sleep_time)
tabla.i <- xml2::read_html(url_to_scrap) %>%
tabla.i <- httr::GET(url_to_scrap,
httr::set_cookies(platform = platform)) %>%
httr::content() %>%
rvest::html_nodes(xpath = "//table") %>%
magrittr::extract(1) %>%
rvest::html_table() %>%
Expand Down
14 changes: 11 additions & 3 deletions R/futbin_search.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#' @importFrom dplyr %>%
#' @param name Optional. Vector with the names of the players. If not specified
#' it will report the 30 highest-rated players of the game.
#' @param platform Platform to get the prices from. Default is `ps4`. Other options are `xone` (XBox One) and `pc`.
#' @param version Optional. Version of the cards. Some options are "Rare",
#' "Non-Rare", "IF" (In-Form), "SIF" (Second In-Form), ...
#' @param verbose Optional. To show additional verbose about webpage used and number of players found.
Expand All @@ -14,6 +15,12 @@
#' # Search for a player
#' futbin_search(name = "Lionel Messi")
#'
#' # Search for a player and get the PC price
#' futbin_search(name = "Lionel Messi", platform = "pc")
#'
#' # Search for a player and get the XBox One price
#' futbin_search(name = "Lionel Messi", platform = "xone")
#'
#' # Search for more than one player
#' futbin_search(name = c("Lionel Messi", "Cristiano Ronaldo"))
#'
Expand All @@ -25,7 +32,7 @@
#' futbin_search(name = "Grealish", version = "IF", verbose = TRUE)
#' }

futbin_search <- function(name = "", version = NULL, verbose = F) {
futbin_search <- function(name = "", platform = "ps4", version = NULL,verbose = F) {
if (length(name) == 1) {

# Name transformation
Expand All @@ -41,7 +48,8 @@ futbin_search <- function(name = "", version = NULL, verbose = F) {
url <- paste0("https://www.futbin.com/21/players?page=1&search=", name)

# Web scraping
tabla <- xml2::read_html(url) %>%
tabla <- httr::GET(url, httr::set_cookies(platform = platform)) %>%
httr::content() %>%
rvest::html_nodes(xpath = "//table") %>%
magrittr::extract(1) %>%
rvest::html_table() %>%
Expand Down Expand Up @@ -89,7 +97,7 @@ futbin_search <- function(name = "", version = NULL, verbose = F) {
# Recursive search
first.name <- name[1]
other.names <- name[-1]
return(rbind(futbin_search(first.name, version, verbose), futbin_search(other.names, version, verbose)))
return(rbind(futbin_search(first.name, platform, version, verbose), futbin_search(other.names, platform, version, verbose)))
}
}

98 changes: 61 additions & 37 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ knitr::opts_chunk$set(
)
```

```{r, echo = FALSE}
# Remove scientific notation
options(scipen = 999)
```

# rfutbin

R package to get price and stats of FIFA Ultimate Team players in [Futbin](https://www.futbin.com).
R package to get price and stats of FIFA Ultimate Team players in [Futbin](https://www.futbin.com) for all platforms (PS4/XBox One/PC).

## Installation

Expand All @@ -31,41 +36,6 @@ install_github("danielredondo/rfutbin")
library(rfutbin)
```

## Functions

### futbin_search

`futbin_search` searchs players in Futbin. It has the following parameters:

- `name`. Optional. Vector with the names of the players. If not specified, it will report the 30 highest-rated players of the game.

- `version`. Optional. Version of the cards. Some options are "Rare", "Non-Rare", "IF" (In-Form), "SIF" (Second In-Form), ...

- `verbose`. Optional. To show additional messages (webpage scraped and number of players found).

The output of the function is a dataframe with all the players found searching for `name` and `version`.

### futbin_scrap

`futbin_scrap` extracts all players of a Futbin URL. It has the following parameters:

- `url`. Futbin URL to web scrap. Futbin webpage (https://www.futbin.com/players) can be used to make customised filters, and then copy the URL here. All the players found in the URL (and the next pages) will be automatically detected and downloaded.

- `sleep_time`. Time (in seconds) ellapsed between scraping one page and the next one. Please respect Futbin API.

- `verbose`. Optional. To show additional verbose about webpage used and number of players found.

The output of the function is a dataframe with all the players found at the URL.

### futbin_plot

`futbin_plot` makes an interactive radar plot of the stats of the players. It has the following parameters:

- `df` dataframe generated with columns `pac`, `sho`, `pas`, `dri`, `def`, `phy`. This dataframe can be obtained from function `futbin_search`.
- `gk` Optional. If `TRUE`, the labels of the plot are the main stats for goalkeepers: diving, handling, kicking, reflexes, speed and position.

The output of the function is an interactive radar plot of the stats.

## Examples

#### Load package
Expand All @@ -83,6 +53,19 @@ futbin_search(name = "Lionel Messi")
Sys.sleep(3)
```

#### The default platform is PS4, but you can get the price in other platforms (XBox One/PC)

```{r}
futbin_search(name = "Lionel Messi", platform = "xone")
futbin_search(name = "Lionel Messi", platform = "pc")
```

```{r, echo = FALSE, results='hide'}
Sys.sleep(3)
```

The default platform is PS4.

#### Search for more than one player

```{r}
Expand Down Expand Up @@ -157,11 +140,52 @@ futbin_plot(some_goalkeepers, gk = TRUE)
![https://i.imgur.com/zpD21wa.png](https://i.imgur.com/zpD21wa.png)
*(Please note that this is a static version. Real plots are interactive.)*

## Functions

### futbin_search

`futbin_search` searchs players in Futbin. It has the following parameters:

- `name`. Optional. Vector with the names of the players. If not specified, it will report the 30 highest-rated players of the game.

- `platform`. Platform to get the prices from. Default is `ps4`. Other options are `xone` (XBox One) and `pc`.

- `version`. Optional. Version of the cards. Some options are "Rare", "Non-Rare", "IF" (In-Form), "SIF" (Second In-Form), ...

- `verbose`. Optional. To show additional messages (webpage scraped and number of players found).

The output of the function is a dataframe with all the players found searching for `name` and `version`.

### futbin_scrap

`futbin_scrap` extracts all players of a Futbin URL. It has the following parameters:

- `url`. Futbin URL to web scrap. Futbin webpage (https://www.futbin.com/players) can be used to make customised filters, and then copy the URL here. All the players found in the URL (and the next pages) will be automatically detected and downloaded.

- `platform`. Platform to get the prices from. Default is `ps4`. Other options are `xone` (XBox One) and `pc`.

- `sleep_time`. Time (in seconds) ellapsed between scraping one page and the next one. Please respect Futbin API.

- `verbose`. Optional. To show additional verbose about webpage used and number of players found.

The output of the function is a dataframe with all the players found at the URL.

### futbin_plot

`futbin_plot` makes an interactive radar plot of the stats of the players. It has the following parameters:

- `df` dataframe generated with columns `pac`, `sho`, `pas`, `dri`, `def`, `phy`. This dataframe can be obtained from function `futbin_search`.

- `gk` Optional. If `TRUE`, the labels of the plot are the main stats for goalkeepers: diving, handling, kicking, reflexes, speed and position.

The output of the function is an interactive radar plot of the stats.


## Citation

If you use this package, you can cite it as:


```
Redondo-Sanchez, Daniel (2020). rfutbin: R package to get price and stats of FIFA Ultimate Team players in Futbin
Redondo-Sanchez, Daniel (2021). rfutbin (v1.0.1): R package to get price and stats of FIFA Ultimate Team players in Futbin. https://github.com/danielredondo/rfutbin
```
655 changes: 0 additions & 655 deletions README.html

This file was deleted.

Loading

0 comments on commit e272d92

Please sign in to comment.