Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hrbrmstr/newsflash
Browse files Browse the repository at this point in the history
  • Loading branch information
hrbrmstr committed Jan 29, 2017
2 parents 9691cb6 + b3ee5d1 commit 78766b2
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 39 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: newsflash
Type: Package
Title: Tools to Work with the Internet Archive and GDELT Television Explorer
Version: 0.3.0
Version: 0.3.1
Date: 2017-01-26
Author: Bob Rudis (bob@@rud.is)
Maintainer: Bob Rudis <[email protected]>
Expand All @@ -19,7 +19,7 @@ Imports:
jsonlite,
dplyr,
tidyr,
anytime,
lubridate,
rvest,
xml2,
stringi,
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export(query_tv)
export(top_text)
import(httr)
importFrom(DT,datatable)
importFrom(anytime,anytime)
importFrom(dplyr,"%>%")
importFrom(dplyr,as_data_frame)
importFrom(dplyr,count)
Expand All @@ -15,6 +14,7 @@ importFrom(dplyr,mutate)
importFrom(dplyr,select)
importFrom(dplyr,tbl_df)
importFrom(jsonlite,fromJSON)
importFrom(lubridate,ymd_hms)
importFrom(purrr,map_df)
importFrom(rvest,html_attr)
importFrom(rvest,html_nodes)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.3.1
* sub out `anytime` for `lubridate` to handle hour resolution in `top_matches`

0.3.0
* `top_text()` returns a tidy data frame by default

Expand Down
2 changes: 1 addition & 1 deletion R/newsflash-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' @importFrom rvest html_nodes html_attr html_text
#' @importFrom stringi stri_match_all_regex
#' @importFrom xml2 read_html
#' @importFrom anytime anytime
#' @importFrom lubridate ymd_hms
#' @importFrom tidyr unnest
#' @importFrom dplyr tbl_df %>% mutate data_frame count as_data_frame select
#' @importFrom purrr map_df
Expand Down
8 changes: 4 additions & 4 deletions R/newsflash.r
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ query_tv <- function(primary_keyword, context_keywords=NULL,
res$query_details <- dplyr::tbl_df(res$query_details)

res$timeline <- tidyr::unnest(res$timeline, station_values) %>%
dplyr::mutate(date_start=anytime::anytime(date_start),
date_end=anytime::anytime(date_end)) %>%
dplyr::mutate(date_start=as.Date(lubridate::ymd_hms(date_start)),
date_end=as.Date(lubridate::ymd_hms(date_end))) %>%
dplyr::tbl_df()

res$station_histogram <- dplyr::tbl_df(res$station_histogram)

res$top_matches <- dplyr::tbl_df(res$top_matches) %>%
dplyr::mutate(date=anytime::anytime(date),
show_date=anytime::anytime(show_date))
dplyr::mutate(date=as.Date(lubridate::ymd_hms(date)),
show_date=lubridate::ymd_hms(show_date))

class(res) <- c("newsflash", class(res))

Expand Down
4 changes: 2 additions & 2 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ head(top_text(query_tv("cheese", filter_network="AFFNETALL"), tidy=FALSE))

You can, of course, do other things with the various bits of data returned:

```{r cache=TRUE}
```{r}
orange <- query_tv("trump")
```

Expand All @@ -82,7 +82,7 @@ arrange(orange$station_histogram, value) %>%
```{r fig.height=6, fig.retina=2}
ggplot(orange$timeline, aes(date_start, value)) +
geom_area(aes(group=station, fill=station), position="stack") +
scale_x_datetime(name=NULL, expand=c(0,0)) +
scale_x_date(name=NULL, expand=c(0,0)) +
scale_y_continuous(name="# Mentions", label=scales::comma, limits=c(0, 8000), expand=c(0,0)) +
ggthemes::scale_fill_tableau(name=NULL) +
labs(title="Timeline") +
Expand Down
58 changes: 29 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ library(hrbrmisc)
packageVersion("newsflash")
```

## [1] '0.3.0'
## [1] '0.3.1'

See what networks & associated corpus date ranges are available:

Expand All @@ -49,21 +49,21 @@ list_networks(widget=FALSE)
## <chr> <chr> <chr>
## 1 NATIONAL All National Networks (See individual networks for dates)
## 2 ALJAZAM Aljazeera America (8/20/2013 - 4/13/2016)
## 3 BLOOMBERG Bloomberg (12/5/2013 - 1/25/2017)
## 4 CNBC CNBC (7/2/2009 - 1/25/2017)
## 5 CNN CNN (7/2/2009 - 1/25/2017)
## 6 FBC FOX Business (8/20/2012 - 1/25/2017)
## 7 FOXNEWSW FOX News (7/16/2011 - 1/25/2017)
## 8 MSNBC MSNBC (7/2/2009 - 1/25/2017)
## 3 BLOOMBERG Bloomberg (12/5/2013 - 1/27/2017)
## 4 CNBC CNBC (7/2/2009 - 1/27/2017)
## 5 CNN CNN (7/2/2009 - 1/27/2017)
## 6 FBC FOX Business (8/20/2012 - 1/27/2017)
## 7 FOXNEWSW FOX News (7/16/2011 - 1/27/2017)
## 8 MSNBC MSNBC (7/2/2009 - 1/26/2017)
## 9 INTERNATIONAL All International Networks (See individual networks for dates)
## 10 BBCNEWSSEG BBC News (1/1/2017 - 1/26/2017)
## 11 AFFNETALL All Affiliate Networks (See individual networks for dates)
## 12 AFFNET_ABC ABC Affiliate Stations (7/2/2009 - 1/26/2017)
## 13 AFFNET_CBS CBS Affiliate Stations (7/2/2009 - 1/26/2017)
## 14 AFFNET_FOX FOX Affiliate Stations (7/3/2009 - 1/26/2017)
## 12 AFFNET_ABC ABC Affiliate Stations (7/2/2009 - 1/27/2017)
## 13 AFFNET_CBS CBS Affiliate Stations (7/2/2009 - 1/27/2017)
## 14 AFFNET_FOX FOX Affiliate Stations (7/3/2009 - 1/27/2017)
## 15 AFFNET_MYTV MYTV Affiliate Stations (12/11/2015 - 12/2/2016)
## 16 AFFNET_NBC NBC Affiliate Stations (7/2/2009 - 1/26/2017)
## 17 AFFNET_PBS PBS Affiliate Stations (7/14/2010 - 1/26/2017)
## 16 AFFNET_NBC NBC Affiliate Stations (7/2/2009 - 1/27/2017)
## 17 AFFNET_PBS PBS Affiliate Stations (7/14/2010 - 1/27/2017)
## 18 AFFMARKALL All Affiliate Markets (See individual networks for dates)
## 19 AFFMARKET_Boston Boston Affiliate Stations (9/30/2015 - 12/2/2016)
## 20 AFFMARKET_Cedar Rapids Cedar Rapids Affiliate Stations (10/19/2015 - 12/2/2016)
Expand All @@ -86,19 +86,19 @@ list_networks(widget=FALSE)
## 37 AFFMARKET_Newport KY Newport KY Affiliate Stations (1/6/2016 - 3/23/2016)
## 38 AFFMARKET_Norfolk Norfolk Affiliate Stations (1/6/2016 - 3/9/2016)
## 39 AFFMARKET_Orlando Orlando Affiliate Stations (1/6/2016 - 3/23/2016)
## 40 AFFMARKET_Philadelphia Philadelphia Affiliate Stations (6/6/2014 - 1/26/2017)
## 40 AFFMARKET_Philadelphia Philadelphia Affiliate Stations (6/6/2014 - 1/27/2017)
## 41 AFFMARKET_Portsmouth Portsmouth Affiliate Stations (1/6/2016 - 3/9/2016)
## 42 AFFMARKET_Pueblo Pueblo Affiliate Stations (1/19/2016 - 3/9/2016)
## 43 AFFMARKET_Raleigh Raleigh Affiliate Stations (1/13/2016 - 12/2/2016)
## 44 AFFMARKET_Reno Reno Affiliate Stations (1/1/2016 - 3/2/2016)
## 45 AFFMARKET_Roanoke Roanoke Affiliate Stations (1/26/2016 - 3/1/2016)
## 46 AFFMARKET_San Francisco San Francisco Affiliate Stations (7/14/2010 - 1/26/2017)
## 46 AFFMARKET_San Francisco San Francisco Affiliate Stations (7/14/2010 - 1/27/2017)
## 47 AFFMARKET_Shaker Heights Shaker Heights Affiliate Stations (1/6/2016 - 12/2/2016)
## 48 AFFMARKET_Sioux City Sioux City Affiliate Stations (10/13/2015 - 3/2/2016)
## 49 AFFMARKET_St. Petersburg St. Petersburg Affiliate Stations (1/6/2016 - 12/2/2016)
## 50 AFFMARKET_Tampa Tampa Affiliate Stations (1/6/2016 - 12/2/2016)
## 51 AFFMARKET_Virginia Beach Virginia Beach Affiliate Stations (1/7/2016 - 3/8/2016)
## 52 AFFMARKET_Washington DC Washington DC Affiliate Stations (7/2/2009 - 1/26/2017)
## 52 AFFMARKET_Washington DC Washington DC Affiliate Stations (7/2/2009 - 1/27/2017)
## 53 AFFMARKET_Waterloo Waterloo Affiliate Stations (10/19/2015 - 12/2/2016)

Basic search:
Expand Down Expand Up @@ -176,18 +176,18 @@ top_text(query_tv("cheese", filter_network="AFFNETALL"))
```

## # A tibble: 40,649 × 4
## station show show_date word
## <chr> <chr> <dttm> <chr>
## 1 NBC - Goldsboro (WNCN) North Carolina News at 530AM 2016-11-25 telephone
## 2 NBC - Goldsboro (WNCN) North Carolina News at 530AM 2016-11-25 rings
## 3 NBC - Goldsboro (WNCN) North Carolina News at 530AM 2016-11-25 o.k
## 4 NBC - Goldsboro (WNCN) North Carolina News at 530AM 2016-11-25 say
## 5 NBC - Goldsboro (WNCN) North Carolina News at 530AM 2016-11-25 cheese
## 6 NBC - Goldsboro (WNCN) North Carolina News at 530AM 2016-11-25 cheese
## 7 NBC - Goldsboro (WNCN) North Carolina News at 530AM 2016-11-25 cheese
## 8 NBC - Goldsboro (WNCN) North Carolina News at 500AM 2016-11-25 hmm
## 9 NBC - Goldsboro (WNCN) North Carolina News at 500AM 2016-11-25 really
## 10 NBC - Goldsboro (WNCN) North Carolina News at 500AM 2016-11-25 what
## station show show_date word
## <chr> <chr> <dttm> <chr>
## 1 NBC - Goldsboro (WNCN) North Carolina News at 530AM 2016-11-25 10:30:00 telephone
## 2 NBC - Goldsboro (WNCN) North Carolina News at 530AM 2016-11-25 10:30:00 rings
## 3 NBC - Goldsboro (WNCN) North Carolina News at 530AM 2016-11-25 10:30:00 o.k
## 4 NBC - Goldsboro (WNCN) North Carolina News at 530AM 2016-11-25 10:30:00 say
## 5 NBC - Goldsboro (WNCN) North Carolina News at 530AM 2016-11-25 10:30:00 cheese
## 6 NBC - Goldsboro (WNCN) North Carolina News at 530AM 2016-11-25 10:30:00 cheese
## 7 NBC - Goldsboro (WNCN) North Carolina News at 530AM 2016-11-25 10:30:00 cheese
## 8 NBC - Goldsboro (WNCN) North Carolina News at 500AM 2016-11-25 10:00:00 hmm
## 9 NBC - Goldsboro (WNCN) North Carolina News at 500AM 2016-11-25 10:00:00 really
## 10 NBC - Goldsboro (WNCN) North Carolina News at 500AM 2016-11-25 10:00:00 what
## # ... with 40,639 more rows

``` r
Expand Down Expand Up @@ -224,7 +224,7 @@ arrange(orange$station_histogram, value) %>%
``` r
ggplot(orange$timeline, aes(date_start, value)) +
geom_area(aes(group=station, fill=station), position="stack") +
scale_x_datetime(name=NULL, expand=c(0,0)) +
scale_x_date(name=NULL, expand=c(0,0)) +
scale_y_continuous(name="# Mentions", label=scales::comma, limits=c(0, 8000), expand=c(0,0)) +
ggthemes::scale_fill_tableau(name=NULL) +
labs(title="Timeline") +
Expand Down Expand Up @@ -255,7 +255,7 @@ library(testthat)
date()
```

## [1] "Fri Jan 27 19:02:24 2017"
## [1] "Sat Jan 28 22:16:43 2017"

``` r
test_dir("tests/")
Expand Down
Binary file modified README_files/figure-markdown_github/unnamed-chunk-10-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 78766b2

Please sign in to comment.