<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/teasing-out-top-daily-topics-with-gdelts-television-explorer/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rud.is/b/2017/09/09/teasing-out-top-daily-topics-with-gdelts-television-explorer/"> R – rud.is</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>Earlier this year, the <a rel="nofollow" href="https://www.gdeltproject.org/" target="_blank">GDELT Project</a> released their <a rel="nofollow" href="https://television.gdeltproject.org/cgi-bin/iatv_ftxtsearch/iatv_ftxtsearch" target="_blank">Television Explorer</a> that enabled API access to closed-caption tedt from television news broadcasts. They’ve done an incredible job expanding and stabilizing the API and just recently released “<a rel="nofollow" href="https://blog.gdeltproject.org/television-explorer-toptrending-tables-now-available/" target="_blank">top trending tables</a>” which summarise what the “top” topics and phrases are across news stations every fifteen minutes. You should read that (long-ish) intro as there are many caveats to the data source and I’ve also found that the files aren’t always available (i.e. there are often gaps when retrieving a sequence of files).</p>
<p>The R <a rel="nofollow" href="https://github.com/hrbrmstr/newsflash" target="_blank"><code>newsflash</code></a> package has been able to work with the GDELT Television Explorer API since the inception of the service. It now has the ability work with this new “top topics” resource directly from R. </p>
<p>There are two interfaces to the top topics, but I’ll show you the easiest one to use in this post. Let’s chart the top 25 topics per day for the past ~3 days (this post was generated ~mid-day 2017-09-09). </p>
<p>To start, we’ll need the data!</p>
<p>We provide start and end <code>POSIXct</code> times in the current time zone (the <code>top_trending_range()</code> function auto-converts to GMT which is how the file timestamps are stored by GDELT). The function takes care of generating the proper 15-minute sequences. </p>
<pre><code>library(newsflash) # devtools::install_github(&quot;hrbrmstr/newsflash&quot;)
library(hrbrthemes)
library(tidyverse)

from &lt;- as.POSIXct(&quot;2017-09-07 00:00:00&quot;)
to &lt;- as.POSIXct(&quot;2017-09-09 12:00:00&quot;)

trends &lt;- top_trending_range(from, to)

glimpse(trends)
## Observations: 233
## Variables: 5
## $ ts                       </code></pre>