Skip to content

Commit

Permalink
Merge pull request #1 from hrbrmstr/master
Browse files Browse the repository at this point in the history
Updating fork to master changes
  • Loading branch information
MikeGruz authored Aug 20, 2018
2 parents 2752bec + af38d8e commit d8d4fbc
Show file tree
Hide file tree
Showing 48 changed files with 684 additions and 818 deletions.
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ Version: 0.6.0
Date: 2017-10-01
Author: Bob Rudis (bob@rud.is)
Authors@R: c(
person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre")),
person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5670-2640")),
person("Abe", "Neuwirth", role = c("ctb")),
person("Mike", "Gruszczynski", role = c("ctb"))
)
Encoding: UTF-8
Maintainer: Bob Rudis <bob@rud.is>
Description: The 'GDELT' Television Explorer (<http://television.gdeltproject.org/cgi-bin/iatv_ftxtsearch/iatv_ftxtsearch>)
provides a simple and straighforward interface for searching through current and historical
Expand Down Expand Up @@ -38,4 +40,4 @@ Imports:
txtplot,
readr,
utils
RoxygenNote: 6.0.1
RoxygenNote: 6.0.1.9000
8 changes: 3 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Generated by roxygen2: do not edit by hand

S3method(print,newsflash)
export(gd_top_trending)
export(iatv_top_trending)
export(list_chyrons)
export(list_networks)
export(query_tv)
export(read_chyrons)
export(top_text)
export(top_trending)
export(top_trending_range)
export(view_clip)
export(word_cloud)
import(httr)
importFrom(DT,datatable)
importFrom(curl,curl_fetch_memory)
Expand Down
8 changes: 8 additions & 0 deletions R/gd-top-trending.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#' Top Trending (GDELT)
#'
#' Retrieve current (last 15 minute) "top topics" being discussed on stations
#' @export
gd_top_trending <- function() {
query_tv("", mode = "TrendingTopics")
}

23 changes: 13 additions & 10 deletions R/networks.r
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@
#' the console by passing in \code{widget=FALSE}
#'
#' @export
#' @param widget if `TRUE` then an HTML widget will be displayed to make it easier to
#' sift through stations/networks
#' @return data frame
#' @examples
#' list_networks() # widget
#' list_networks(FALSE) # console
list_networks <- function(widget=interactive()) {
#' print(list_networks(FALSE)) # no widget
list_networks <- function(widget = interactive()) {

xml2::read_html("http://television.gdeltproject.org/cgi-bin/iatv_ftxtsearch/iatv_ftxtsearch") %>%
rvest::html_nodes("select[name='filter_network'] > option") -> networks
xdf <- jsonlite::fromJSON("https://api.gdeltproject.org/api/v2/tv/tv?mode=stationdetails&format=json")

detail_text <- rvest::html_text(networks) %>% gsub("=*> (.*)", "All \\1 (See individual networks for dates)", .)
xdf$station_details %>%
mutate(StartDate = as.Date(anytime::anytime(StartDate))) %>%
mutate(EndDate = as.Date(anytime::anytime(StartDate))) -> xdf

stri_match_all_regex(detail_text, "(.*) (\\(.*\\))") %>%
map_df(~tbl_df(setNames(as.list(.[,2:3]), c("network", "date_range")))) %>%
mutate(keyword=rvest::html_attr(networks, "value")) %>%
select(keyword, network, date_range) -> df
if (widget) DT::datatable(xdf)

if (widget) DT::datatable(df) else print(df, n=nrow(df))
class(xdf) <- c("tbl_df", "tbl", "data.frame")

xdf

}

277 changes: 138 additions & 139 deletions R/newsflash.r

Large diffs are not rendered by default.

48 changes: 0 additions & 48 deletions R/print_ndf.r

This file was deleted.

16 changes: 8 additions & 8 deletions R/top-tending-range.r
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Top Trending Tables (Ranged)
#' Top Trending Topics (Internet Archive TV Archive)
#'
#' Provide start & end times in current time zone and this function will generate
#' the proper "every 15-second" values, convert them to GMT values and issue the queries,
Expand All @@ -20,16 +20,16 @@
#' processed hours later).
#'
#' @md
#' @param from,to start and end `POSIXct` values in **current** time zone.
#' @param from,to start and end date/time ranges (will auto-convert if properly formatted strings)
#' @param .progress show a progress bar? Defaukts to `TRUE` if in an interactive session.
#' @note The times are auto-converted to GMT
#' @export
#' @examples
#' # This gets the from/to times in current time zone
#' from <- as.POSIXct("2017-09-08 18:00:00")
#' to <- as.POSIXct("2017-09-09 06:00:00")
#'
#' top_trending_range(from, to)
top_trending_range <- function(from, to, .progress=interactive()) {
#' top_trending("2017-09-08 18:00", "2017-09-09 06:00")
iatv_top_trending <- function(from, to, .progress=interactive()) {

from <- anytime::anytime(from)
to <- anytime::anytime(to)

base_url <- "http://data.gdeltproject.org/gdeltv3/iatv_trending/%s.tvtrending.v3.15min.json"

Expand Down
65 changes: 0 additions & 65 deletions R/top-trending.r

This file was deleted.

24 changes: 0 additions & 24 deletions R/top_text.r

This file was deleted.

12 changes: 0 additions & 12 deletions R/view-clip.r

This file was deleted.

27 changes: 27 additions & 0 deletions R/word-cloud.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#' Retrieve top words that appear most frequently in clips matching your search
#'
#' The API takes the 200 most relevant clips that match your search and returns the
#' terms for a "word cloud" of up to the top 200 most frequent words that appeared in
#' those clips (common stop words are automatically removed). This is a powerful way
#' of understanding the topics and words dominating the relevant coverage and
#' suggesting additional contextual search terms to narrow or evolve your search.
#' Note that if there are too few matching clips for your query, the word cloud may
#' be blank.
#'
#' @md
#' @param query query string in GDELT format. See `QUERY` in https://blog.gdeltproject.org/gdelt-2-0-television-api-debuts/
#' for details; use [list_networks()] to obtain valid station/network identifiers
#' @param start_date,end_date start/end dates. Leaving both `NULL` searches all archive history.
#' Leaving just `start_date` `NULL` sets the start date to July 2009. Leaving just `end_date`
#' `NULL` sets the end date to today.
#' @export
word_cloud <- function(query, start_date = NULL, end_date = NULL) {

query_tv(
query = query,
mode = "WordCloud",
start_date = start_date,
end_date = end_date
)

}
5 changes: 5 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.onLoad <- function(libname, pkgname) {

packageStartupMessage("NOTE: There are breaking changes to the package API due to GDELT's v2 API")

}
Loading

0 comments on commit d8d4fbc

Please sign in to comment.