README.md

albopop - Generate RSS feeds

The following functions are implemented:

News

Installation

devtools::install_github("patperu/albopop")

Usage

library("albopop")
library("rvest")
## Loading required package: xml2

# current version
packageVersion("albopop")
## [1] '0.1.1'

The function ap_parse_page parse the content for different sites. The parameter site specify the type of input. Currently four providers are supported:

To parse the announcements for the Comune di Lu

res <- ap_parse_page(url = "http://albo.studiok.it/lu/albo", site = "studiok")
str(res)
## Classes 'albopop_srs' and 'data.frame':  44 obs. of  7 variables:
##  $ APNumero   : chr  "67 / 2016" "66 / 2016" "65 / 2016" "64 / 2016" ...
##  $ Descrizione: chr  "" "" "" "" ...
##  $ Tipo       : chr  "DETERMINA" "DETERMINA" "DELIBERA DI CONSIGLIO" "DELIBERA DI CONSIGLIO" ...
##  $ Oggetto    : chr  "[67 / 2016] DETERMINA RESPONSABILE SERVIZIO FINANZIARIO N. 3 DEL 17/02/2016" "[66 / 2016] DETERMINA RESPONSABILE SERVIZIO FINANZIARIO N. 2 DEL 15/02/2016" "[65 / 2016] DELIBERA CONSIGLIO COMUNALE N. 08 DEL 10/02/2016" "[64 / 2016] DELIBERA CONSIGLIO COMUNALE N. 07 DEL 10/02/2016" ...
##  $ Inizio     : chr  "24/02/2016" "24/02/2016" "24/02/2016" "24/02/2016" ...
##  $ Fino       : chr  "10/03/2016" "10/03/2016" "10/03/2016" "10/03/2016" ...
##  $ link       : chr  "http://albo.studiok.it/lu/albo/dettaglio.php?id=MES00000000672016" "http://albo.studiok.it/lu/albo/dettaglio.php?id=MES00000000662016" "http://albo.studiok.it/lu/albo/dettaglio.php?id=MES00000000652016" "http://albo.studiok.it/lu/albo/dettaglio.php?id=MES00000000642016" ...

The function ap_build_rss generates an RSS feed and writes a simple XML file in the local default directory feed. The input must contain at least three columns named Oggetto, Inizio and link. To write the file "Lu.xml":

ap_build_rss(res, 
             rss_title = "Comune di Lu", 
             rss_link  = "http://albo.studiok.it/lu/albo", 
             rss_file  = "Lu.xml")
## Warning in xmlRoot.XMLInternalDocument(currentNodes[[1]]): empty XML document

Send notifications with Telegram and Twitter

Before sending notifications it is necessary to set the appropriate Tokens for bit.ly, Telegram and Twitter.

library(urlshorteneR)

bitly_token <- bitly_auth(key    = Sys.getenv("bitly_key"),
                          secret = Sys.getenv("bitly_secret"))

res <- data.frame(Comune = "Alseno.xml",
                  title  = "[53 / 2016] AVVISO DI AVVENUTO RILASCIO DI...",
                  pubDate = "2016-02-20",
                  link =  "http://albo.studiok.it/alseno/albo/dettaglio.php?id=MES00000000532016",
                  stringsAsFactors = FALSE)

res_msg <- ap_build_msg(res)
str(res_msg)
# 'data.frame': 1 obs. of  7 variables:
# $ Comune      : chr "Alseno.xml"
# $ title       : chr "[53 / 2016] AVVISO DI AVVENUTO RILASCIO DI..."
# $ pubDate     : chr "2016-02-20"
# $ link        : chr "http://albo.studiok.it/alseno/albo/dettaglio.php?id=MES00000000532016"
# $ blyurl      : chr "http://bit.ly/214xeQJ"
# $ msg_Telegram: chr "[53 / 2016] AVVISO DI AVVENUTO RILASCIO DI..., http://bit.ly/214xeQJ"
# $ msg_Twitter : chr "[53 / 2016] AVVISO DI AVVENUTO RILASCIO DI..., http://bit.ly/214xeQJ"

The function ap_build_msg adds three columns to the input:

ap_send_telegram(res_msg$msg_Telegram, "LU_TOKEN", "LU_CHAT_ID")

To send a notification with Twitter

library('twitteR')

setup_twitter_oauth(Sys.getenv("twitter_api_key"),
                    Sys.getenv("twitter_api_secret"),
                    Sys.getenv("twitter_access_token"),
                    Sys.getenv("twitter_access_token_secret"))

tweet(res_msg$msg_Twitter)

Meta

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.



patperu/albopop documentation built on May 24, 2017, 1:23 a.m.