Skip to content

Commit b2bdf70

Browse files
committed
first commit
0 parents  commit b2bdf70

16 files changed

+344
-0
lines changed

.Rbuildignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
^.*\.Rproj$
2+
^\.Rproj\.user$
3+
^data-raw$
4+
^LICENSE\.md$
5+
^CODE_OF_CONDUCT\.md$

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData
4+
.Ruserdata

CODE_OF_CONDUCT.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Contributor Code of Conduct
2+
3+
As contributors and maintainers of this project, we pledge to respect all people who
4+
contribute through reporting issues, posting feature requests, updating documentation,
5+
submitting pull requests or patches, and other activities.
6+
7+
We are committed to making participation in this project a harassment-free experience for
8+
everyone, regardless of level of experience, gender, gender identity and expression,
9+
sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
10+
11+
Examples of unacceptable behavior by participants include the use of sexual language or
12+
imagery, derogatory comments or personal attacks, trolling, public or private harassment,
13+
insults, or other unprofessional conduct.
14+
15+
Project maintainers have the right and responsibility to remove, edit, or reject comments,
16+
commits, code, wiki edits, issues, and other contributions that are not aligned to this
17+
Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed
18+
from the project team.
19+
20+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by
21+
opening an issue or contacting one or more of the project maintainers.
22+
23+
This Code of Conduct is adapted from the Contributor Covenant
24+
(https://www.contributor-covenant.org), version 1.0.0, available at
25+
https://contributor-covenant.org/version/1/0/0/.

DESCRIPTION

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Package: phishr
2+
Title: Phish.net API Wrapper
3+
Version: 0.1
4+
Authors@R:
5+
person(given = "Maya",
6+
family = "Gans",
7+
role = c("cre", "aut"),
8+
email = "jaffe.maya@gmail.com")
9+
Description: An API wrapper for the phish.net website to extract
10+
setlist, rating, and jamchart data.
11+
License: MIT + file LICENSE
12+
URL: http://this
13+
BugReports: http://that
14+
Imports:
15+
attempt,
16+
curl,
17+
httr,
18+
jsonlite,
19+
purrr,
20+
textreadr,
21+
dplyr,
22+
stringr,
23+
zoo
24+
Encoding: UTF-8
25+
LazyData: true
26+
RoxygenNote: 6.1.1
27+
Suggests:
28+
testthat

LICENSE

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
YEAR: 2019
2+
COPYRIGHT HOLDER: Maya GANS

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MIT License
2+
3+
Copyright (c) 2019 Maya GANS
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

NAMESPACE

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(get_setlist)
4+
import(httr)
5+
import(jsonlite)
6+
importFrom(attempt,stop_if_all)
7+
importFrom(attempt,stop_if_not)
8+
importFrom(curl,has_internet)
9+
importFrom(dplyr,filter)
10+
importFrom(httr,GET)
11+
importFrom(httr,status_code)
12+
importFrom(jsonlite,fromJSON)
13+
importFrom(purrr,compact)
14+
importFrom(stringr,str_split_fixed)
15+
importFrom(textreadr,read_html)
16+
importFrom(zoo,na.locf)

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# phishr 0.1
2+
3+
* Added a `NEWS.md` file to track changes to the package.

R/get_setlist.R

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#' Search for Setlist
2+
#' @param apikey apikey
3+
#' @param setlist the show setlist in YYYY-MM-DD format
4+
#'
5+
#' @importFrom attempt stop_if_all
6+
#' @importFrom purrr compact
7+
#' @importFrom jsonlite fromJSON
8+
#' @importFrom httr GET
9+
#' @export
10+
#' @import jsonlite
11+
#' @importFrom textreadr read_html
12+
#' @import httr
13+
#' @importFrom dplyr filter
14+
#' @importFrom stringr str_split_fixed
15+
#' @importFrom zoo na.locf
16+
#' @rdname getsetlist
17+
#'
18+
#' @return the results from the search
19+
#' @examples
20+
#' \dontrun{
21+
#' get_setlist(apikey = "<apikey>", showdate = "1999-12-31")
22+
#' }
23+
24+
get_setlist <- function(apikey = NULL,
25+
showdate = NULL){
26+
27+
args <- list(apikey = apikey, showdate = showdate)
28+
29+
# Check that at least one argument is not null
30+
# stop_if_all(apikey, is.null, "You need to specify the API key!")
31+
# Chek for internet
32+
check_internet()
33+
# Create the
34+
res <- GET(
35+
paste0(
36+
base_url,
37+
"setlists/get?apikey=",
38+
apikey,
39+
"&showdate=",
40+
showdate,
41+
sep=""))
42+
43+
# Check the result
44+
check_status(res)
45+
cont <- content(res)
46+
47+
# Get the content and return it as a data.frame
48+
# using an if statements lets deal with the shows that do have data
49+
50+
set <- list()
51+
52+
if (length(cont$response$data) > 0) {
53+
54+
# cont$response$data[[1]]$setlistdata
55+
# contains the setlist data in html which is a hot mess
56+
# cont$response$data[[1]]$setlistdata
57+
# contains the setlist data in html which is a hot mess
58+
set_html <- textreadr::read_html(cont$response$data[[1]]$setlistdata)
59+
60+
# combine the colon with the previous line
61+
# because colons are found with "Set 1:", "Set 2:" etc.
62+
ind.colon <- which(set_html == ":")
63+
ind.set <- ind.colon - 1
64+
65+
# paste the colon and the prior line together
66+
# to concatenate Set 1 and :
67+
set_html[ind.set] <- paste(set_html[ind.set], set_html[ind.colon], sep = "")
68+
69+
# make into data frame
70+
set_html <- data.frame(set_html)
71+
# call the song column Text
72+
set_html$Text <- as.character(set_html$set_html)
73+
set_html$set_html <- NULL
74+
75+
# remove cells containing brackets, this is a vestage of show notes
76+
# remove cells only containing special characters
77+
set_html <- filter(set_html, !grepl("\\[",set_html$Text))
78+
set_html <- filter(set_html, !grepl("^:$",set_html$Text))
79+
80+
# create a character string for song names
81+
# the easiest filter is that they should include all alphabetical characters
82+
# but then we also need to search for the songs that are numbers
83+
# call others false
84+
boo <- c("[a-zA-Z]+", "1999", "555", "5:15")
85+
86+
# now we can set our songs to true and the rest to false
87+
set_html$Boolian <- grepl(paste(boo, collapse = "|"), set_html$Text)
88+
89+
# now we can take the cells that were returned as false
90+
# and put those into a new column for segues
91+
ind.FALSE <- which(set_html$Boolian == FALSE)
92+
ind.CAT <- ind.FALSE - 1
93+
94+
set_html$Text[ind.CAT] <- paste(set_html$Text[ind.CAT], set_html$Text[ind.FALSE], sep = "__")
95+
set_html <- filter(set_html, set_html$Boolian == TRUE)
96+
set_html <- str_split_fixed(set_html$Text, "__", 2)
97+
colnames(set_html) <- c("Text", "Segue")
98+
99+
set_html <- data.frame(set_html)
100+
101+
# now we can remove the rows containing the set
102+
# and use that data to populate which set each show belongs in
103+
# we will use a combination of a colon and the colon being
104+
# the last character in the string (because of RS song 5:15)
105+
106+
substrRight <- function(x, n){
107+
substr(x, nchar(x)-n+1, nchar(x))
108+
}
109+
110+
set_html$Set <- ifelse(substrRight(as.character(set_html$Text), 1) == ":", paste(set_html$Text), NA)
111+
set_html$Set <- na.locf(set_html$Set)
112+
set_html <- filter(set_html, set_html$Text != set_html$Set)
113+
114+
115+
} else {
116+
# in the case that the show had no data set that list element to NA
117+
set_html <- NA
118+
}
119+
return(set_html)
120+
}
121+
122+
#' @export
123+
#' @rdname getsetlist

R/utils.R

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#' @importFrom attempt stop_if_not
2+
#' @importFrom curl has_internet
3+
check_internet <- function(){
4+
stop_if_not(.x = has_internet(), msg = "Please check your internet connexion")
5+
}
6+
7+
#' @importFrom httr status_code
8+
check_status <- function(res){
9+
stop_if_not(.x = status_code(res),
10+
.p = ~ .x == 200,
11+
msg = "The API returned an error")
12+
}
13+
14+
base_url <- "https://api.phish.net/v3/"

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
2+
3+
lease note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md).
4+
By participating in this project you agree to abide by its terms.

data-raw/DATASET.R

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## code to prepare `DATASET` dataset goes here
2+
3+
usethis::use_data("DATASET")

data-raw/devstuff.R

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
library(devtools)
2+
library(usethis)
3+
library(desc)
4+
5+
# Remove default DESC
6+
unlink("DESCRIPTION")
7+
# Create and clean desc
8+
my_desc <- description$new("!new")
9+
10+
# Set your package name
11+
my_desc$set("Package", "phishr")
12+
13+
#Set your name
14+
my_desc$set("Authors@R", "person('Maya', 'Gans', email = 'jaffe.maya@gmail.com',
15+
role = c('cre', 'aut'))")
16+
17+
# Remove some author fields
18+
my_desc$del("Maintainer")
19+
20+
# Set the version
21+
my_desc$set_version("0.1")
22+
23+
# The title of your package
24+
my_desc$set(Title = "Phish.net API Wrapper")
25+
# The description of your package
26+
my_desc$set(Description = "An API wrapper for the phish.net website to extract setlist, rating, and jamchart data.")
27+
# The urls
28+
my_desc$set("URL", "http://this")
29+
my_desc$set("BugReports", "http://that")
30+
# Save everyting
31+
my_desc$write(file = "DESCRIPTION")
32+
33+
# If you want to use the MIT licence, code of conduct, and lifecycle badge
34+
use_mit_license(name = "Maya GANS")
35+
use_code_of_conduct()
36+
use_lifecycle_badge("Experimental")
37+
use_news_md()
38+
39+
# Get the dependencies
40+
use_package("httr")
41+
use_package("jsonlite")
42+
use_package("curl")
43+
use_package("attempt")
44+
use_package("purrr")
45+
use_package("textreadr")
46+
47+
# Clean your description
48+
use_tidy_description()

man/getsetlist.Rd

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phishr.Rproj

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: Default
4+
SaveWorkspace: Default
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 2
10+
Encoding: UTF-8
11+
12+
RnwWeave: Sweave
13+
LaTeX: pdfLaTeX
14+
15+
AutoAppendNewline: Yes
16+
StripTrailingWhitespace: Yes
17+
18+
BuildType: Package
19+
PackageUseDevtools: Yes
20+
PackageInstallArgs: --no-multiarch --with-keep.source

tests/testthat.R

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
library(testthat)
2+
library(phishr)
3+
4+
test_check("phishr")

0 commit comments

Comments
 (0)