Giter VIP home page Giter VIP logo

mediacloudr's Introduction

mediacloudr

Project Status: Active – The project has reached a stable, usable state and is being actively developed. Build Status Codecov test coverage

The goal of mediacloudr is to provide a consistent wrapper for the mediacloud.org API. The Media Cloud platform is an open-source platform, that collects all kind of news stories and provides various functionalities to query, download and analyze them. This packages tries to support R users by providing a set of functions to access various functionalities of the mediacloud.org.

Installation

The mediacloudr-package is now on CRAN 🎉 . You can install the released version of mediacloudr from CRAN with:

install.packages("mediacloudr")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("jandix/mediacloudr")

API key

Please register as a new user. Afterwards, you can copy your API key from your profile page.

I suggest to save the API key to your R environment file. The R environment file is loaded every time R is started/restarted. You should not add the key to your scripts, because other users could misuse your key. The following steps show how to add the key to your R environment file.

  1. Open your .Renviron file. The file is usually located in your home directory. If the file does not exist, just create one and name it .Renviron.
  2. Add a new line and enter your API key in the following format: MEDIACLOUD_API_KEY=<YOUR_API_KEY>.
  3. Save the file and restart your current R session to start using mediacloudr.

Request Limits

The mediacloud.org states the following for API request/rate limits:

“Each user is limited to 1,000 API calls and 20,000 stories returned in any 7 day period. Requests submitted beyond this limit will result in a status 403 error. Users who need access to more requests should email [email protected].”

Examples

Get a news story by id

You can query news stories by their ids. The ids can be found using the graphical interface or using the get_story_list function.

Note: You don’t have to add the api_key argument if you followed the steps to add the api key to your R environment file.

story_id <- 27456565L
story <- get_story(story_id = story_id)

Get a list with news stories

You can query a list of news stories using get_story_list. You can use the q and fq arguments to filter stories. A guide to the query parameters can be found here.

Note: You don’t have to add the api_key argument if you followed the steps to add the api key to your R environment file.

stories <- get_story_list(q = "trump")

Get a media source by id

You can query media sources by their ids. The ids can be found using the graphical online interface. mediacloud.org provides various meta data for their media sources.

Note: You don’t have to add the api_key argument if you followed the steps to add the api key to your R environment file.

media_id <- 1L
media_source <- get_media_source(media_id =  media_id)

Download article and extract social media meta data

You can use the article URL to download the complete article and extract social meta data. The meta data can be analyzed using techniques such as sentiment analysis or simply compared to the article content.

# load httr
library(httr)
# define article url
url <- "https://bits.blogs.nytimes.com/2013/04/07/the-potential-and-the-risks-of-data-science"
# download article
response <- GET(url)
# extract article html
html_document <- content(response, type = "text", encoding = "UTF-8")
# extract meta data from html document
meta_data <- extract_meta_data(html_doc = html_document)

mediacloudr's People

Contributors

jandix avatar

Stargazers

 avatar Bianca avatar Xudong Yu avatar Peter M. Dahlgren avatar David Sichinava avatar Mathias Felipe avatar Bryan Wang avatar Carlo R. M. A. Santagiustina avatar Abdullah Alrhmoun avatar Johannes Breuer avatar Jovan avatar Hugo Gruson avatar Johannes Gruber avatar Malte Kyhos avatar  avatar Leo avatar boB Rudis avatar Lisa Hehnke avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.