├── .gitignore
├── LICENSE
├── R
├── sysdata.rda
├── utils.R
├── mockup-timeline.R
└── mockup-status.R
├── tools
└── readme
│ ├── ex.png
│ ├── ex2.png
│ ├── ex3.png
│ └── ex.html
├── .Rbuildignore
├── NAMESPACE
├── DESCRIPTION
├── mocktwitter.Rproj
├── make.R
├── man
├── mocktwitter_timeline.Rd
└── mocktwitter_status.Rd
├── LICENSE.md
├── README.md
└── README.Rmd
/.gitignore:
--------------------------------------------------------------------------------
1 | .Rhistory
2 | .RData
3 | .Rproj.user
4 | make.R
5 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | YEAR: 2018
2 | COPYRIGHT HOLDER: Michael Wayne Kearney
3 |
--------------------------------------------------------------------------------
/R/sysdata.rda:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkearney/mocktwitter/HEAD/R/sysdata.rda
--------------------------------------------------------------------------------
/tools/readme/ex.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkearney/mocktwitter/HEAD/tools/readme/ex.png
--------------------------------------------------------------------------------
/tools/readme/ex2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkearney/mocktwitter/HEAD/tools/readme/ex2.png
--------------------------------------------------------------------------------
/tools/readme/ex3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mkearney/mocktwitter/HEAD/tools/readme/ex3.png
--------------------------------------------------------------------------------
/.Rbuildignore:
--------------------------------------------------------------------------------
1 | ^README\.Rmd$
2 | ^LICENSE\.md$
3 | ^mocktwitter\.Rproj$
4 | ^\.Rproj\.user$
5 | \.DS_Store$
6 |
--------------------------------------------------------------------------------
/NAMESPACE:
--------------------------------------------------------------------------------
1 | # Generated by roxygen2: do not edit by hand
2 |
3 | S3method(mocktwitter_status,character)
4 | S3method(mocktwitter_status,data.frame)
5 | S3method(mocktwitter_status,factor)
6 | S3method(mocktwitter_timeline,character)
7 | S3method(mocktwitter_timeline,factor)
8 | export(mocktwitter_status)
9 | export(mocktwitter_timeline)
10 |
--------------------------------------------------------------------------------
/DESCRIPTION:
--------------------------------------------------------------------------------
1 | Package: mocktwitter
2 | Version: 0.0.0.9000
3 | Title: What the Package Does (One Line, Title Case)
4 | Description: Generates mockup HTML Twitter pages.
5 | License: MIT + file LICENSE
6 | Encoding: UTF-8
7 | LazyData: true
8 | ByteCompile: true
9 | Authors@R: person("Michael Wayne", "Kearney", ,
10 | "kearneymw@missouri.edu", role = c("aut", "cre"),
11 | comment = c(ORCID = "0000-0002-0730-4694"))
12 | license: MIT
13 | RoxygenNote: 6.0.1.9000
14 |
--------------------------------------------------------------------------------
/mocktwitter.Rproj:
--------------------------------------------------------------------------------
1 | Version: 1.0
2 |
3 | RestoreWorkspace: No
4 | SaveWorkspace: No
5 | AlwaysSaveHistory: Default
6 |
7 | EnableCodeIndexing: Yes
8 | UseSpacesForTab: Yes
9 | NumSpacesForTab: 2
10 | Encoding: UTF-8
11 |
12 | RnwWeave: knitr
13 | LaTeX: XeLaTeX
14 |
15 | AutoAppendNewline: Yes
16 | StripTrailingWhitespace: Yes
17 |
18 | BuildType: Package
19 | PackageUseDevtools: Yes
20 | PackageInstallArgs: --no-multiarch --with-keep.source
21 | PackageRoxygenize: rd,collate,namespace
22 |
--------------------------------------------------------------------------------
/make.R:
--------------------------------------------------------------------------------
1 |
2 | library(usethis)
3 | use_description()
4 | devtools::document()
5 | devtools::install()
6 | use_git_config()
7 | use_readme_rmd()
8 | use_git()
9 | use_git_ignore()
10 |
11 |
12 | devtools::load_all()
13 |
14 | writeLines(template, "/tmp/tmp.html")
15 |
16 | con <- file("/tmp/tmp.html")
17 | x <- readLines(con, warn = FALSE, encoding = "UTF-8")
18 | close(con)
19 |
20 | template <- x
21 |
22 | save(template, file = "R/sysdata.rda")
23 | rmarkdown::render("README.Rmd")
24 | unlink("README.html")
25 |
26 | rdt <- rtweet::lookup_statuses("1010900865602019329")
27 |
28 | mocktwitter("1010900865602019329")
29 | traceback()
--------------------------------------------------------------------------------
/man/mocktwitter_timeline.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/mockup-timeline.R
3 | \name{mocktwitter_timeline}
4 | \alias{mocktwitter_timeline}
5 | \title{Create a mockup of a Twitter timeline}
6 | \usage{
7 | mocktwitter_timeline(x, file = NULL)
8 | }
9 | \arguments{
10 | \item{x}{Twitter timeline data frame (as returned by rtweet).}
11 |
12 | \item{file}{File name to save as. Defaults to temporary file.}
13 | }
14 | \value{
15 | Saves an html file
16 | }
17 | \description{
18 | Generates HTML twitter timeline page.
19 | }
20 | \examples{
21 | \dontrun{
22 | ## create mock-up of Twitter timeline
23 |
24 | ## the timeline URL
25 | mocktwitter_timeline("https://twitter.com/kearneymw")
26 |
27 | ## the screen name or user ID
28 | mocktwitter_timeline("kearneymw")
29 |
30 | ## or get timeline data from rtweet
31 | kmw <- rtweet::get_timeline("kearneymw")
32 | mocktwitter_timeline(kmw)
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/man/mocktwitter_status.Rd:
--------------------------------------------------------------------------------
1 | % Generated by roxygen2: do not edit by hand
2 | % Please edit documentation in R/mockup-status.R
3 | \name{mocktwitter_status}
4 | \alias{mocktwitter_status}
5 | \title{Create a mockup of a Twitter status}
6 | \usage{
7 | mocktwitter_status(x, file = NULL)
8 | }
9 | \arguments{
10 | \item{x}{Twitter status data frame (as returned by rtweet).}
11 |
12 | \item{file}{File name to save as. Defaults to temporary file.}
13 | }
14 | \value{
15 | Saves an html file
16 | }
17 | \description{
18 | Generates HTML twitter status page.
19 | }
20 | \examples{
21 | \dontrun{
22 | ## create mock-up of Twitter status about rtweet release using
23 |
24 | ## the status URL
25 | mocktwitter_status("https://twitter.com/kearneymw/status/1009431823791902720")
26 |
27 | ## the status_id
28 | mocktwitter_status("1009431823791902720")
29 |
30 | ## or pick a tweet from my timeline to display
31 | kmw <- rtweet::get_timeline("kearneymw")
32 | mocktwitter_status(kmw[1, ])
33 |
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # MIT License
2 |
3 | Copyright (c) 2018 Michael Wayne Kearney
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/R/utils.R:
--------------------------------------------------------------------------------
1 | read_source <- function(x) {
2 | x <- httr::GET(x)
3 | httr::warn_for_status(x)
4 | httr::content(x, as = "text", encoding = "UTF-8")
5 | }
6 |
7 |
8 | is_id <- function(x) {
9 | x <- gsub("\\s|/", "", x)
10 | nchar(gsub("\\d", "", x)) == 0
11 | }
12 |
13 | is_token_configured <- function() {
14 | if (exists(".rtweet_token_config")) {
15 | return(get("rtweet_token_config", envir = .rtweet_token_config))
16 | }
17 | .rtweet_token_config <- new.env()
18 | assign(".rtweet_token_config", .rtweet_token_config, envir = .GlobalEnv)
19 | if (identical(Sys.getenv("TWITTER_PAT"), "")) {
20 | assign("rtweet_token_config", FALSE, envir = .rtweet_token_config)
21 | return(FALSE)
22 | }
23 | token <- readRDS(Sys.getenv("TWITTER_PAT"))
24 | if (!inherits(token, c("Token", "Token1.0"))) {
25 | assign("rtweet_token_config", FALSE, envir = .rtweet_token_config)
26 | return(FALSE)
27 | }
28 | x <- tryCatch(rtweet:::authenticating_user_name(token),
29 | error = function(e) return(FALSE),
30 | warning = function(w) return(FALSE))
31 | if (identical(x, FALSE) || length(x) != 1L || !is.character(x)) {
32 | assign("rtweet_token_config", FALSE, envir = .rtweet_token_config)
33 | return(FALSE)
34 | }
35 | assign("rtweet_token_config", TRUE, envir = .rtweet_token_config)
36 | TRUE
37 | }
38 |
39 | is_status_id <- function(x) {
40 | x <- tryCatch(rtweet::lookup_statuses(x),
41 | error = function(e) return(NULL),
42 | warning = function(w) return(NULL))
43 | is.data.frame(x) && nrow(x) == 1L
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | # mocktwitter
5 |
6 | 🐧🐦 Generate HTML pages for Twitter statuses.
7 |
8 | ## Installation
9 |
10 | You can install the current version of mocktwitter from
11 | [Github](https://github.com) with:
12 |
13 | ``` r
14 | ## install from github
15 | devtools::install_github("mkearney/mocktwitter")
16 | ```
17 |
18 | ## `mocktwitter_status()`
19 |
20 | Use `mocktwitter_status()` with a status URL, status ID, or tweets data
21 | returned by [**{rtweet}**](http://rtweet.info) to create a [mock-up of a
22 | Twitter status HTML page](htols/readme/ex.html):
23 |
24 | ``` r
25 | ## (1) URL to twitter status data byrealDonaldTrump
26 | mocktwitter_status("https://twitter.com/realDonaldTrump/status/1010900865602019329")
27 |
28 | ## (2) mockup an HTML twitter page for a readDonaldTrump status
29 | mocktwitter_status("1010900865602019329")
30 |
31 | ## (3) twitter status data from rtweet for a realDonaldTrump tweet
32 | rdt <- rtweet::lookup_statuses("1010900865602019329")
33 |
34 | ## override with custom text
35 | rdt$text <- "Give me your tired, your poor, your huddled masses yearning to breathe free, the wretched refuse of your teeming shore. Send these, the homeless, tempest-tossed to me, I lift my lamp beside the golden door!"
36 |
37 | ## mock-up an HTML twitter page
38 | mocktwitter_status(rdt, file = "tools/readme/ex.html")
39 | ```
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | In Rstudio, a preview will be displayed in the viewer pane.
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 | ## `mocktwitter_timeline()` (**dev in progress**)
56 |
57 | Use `mocktwitter_timeline()` with a user URL, screen name, user ID, or
58 | timeline data returned by [**{rtweet}**](http://rtweet.info) to create a
59 | [mock-up of a Twitter status HTML page](tools/readme/ex2.html):
60 |
61 | ``` r
62 | ## (1) URL to a twitter timeline
63 | mocktwitter_timeline("https://twitter.com/kearneymw")
64 |
65 | ## (2) screen name or user ID of twitter account
66 | mocktwitter_timeline("kearneymw", file = "tools/readme/ex2.html")
67 | ```
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/README.Rmd:
--------------------------------------------------------------------------------
1 | ---
2 | output: github_document
3 | ---
4 |
5 |
6 |
7 | ```{r setup, include = FALSE}
8 | knitr::opts_chunk$set(
9 | collapse = TRUE,
10 | eval = FALSE,
11 | comment = "#>",
12 | fig.path = "man/figures/README-",
13 | out.width = "100%"
14 | )
15 | ```
16 | # mocktwitter
17 |
18 | 🐧🐦 Generate HTML pages for Twitter statuses.
19 |
20 | ## Installation
21 |
22 | You can install the current version of mocktwitter from [Github](https://github.com) with:
23 |
24 | ```{r}
25 | ## install from github
26 | devtools::install_github("mkearney/mocktwitter")
27 | ```
28 |
29 | ## `mocktwitter_status()`
30 |
31 | Use `mocktwitter_status()` with a status URL, status ID, or tweets data returned by [**{rtweet}**](http://rtweet.info) to create a [mock-up of a Twitter status HTML page](htols/readme/ex.html):
32 |
33 | ```{r}
34 | ## (1) URL to twitter status data byrealDonaldTrump
35 | mocktwitter_status("https://twitter.com/realDonaldTrump/status/1010900865602019329")
36 |
37 | ## (2) mockup an HTML twitter page for a readDonaldTrump status
38 | mocktwitter_status("1010900865602019329")
39 |
40 | ## (3) twitter status data from rtweet for a realDonaldTrump tweet
41 | rdt <- rtweet::lookup_statuses("1010900865602019329")
42 |
43 | ## override with custom text
44 | rdt$text <- "Give me your tired, your poor, your huddled masses yearning to breathe free, the wretched refuse of your teeming shore. Send these, the homeless, tempest-tossed to me, I lift my lamp beside the golden door!"
45 |
46 | ## mock-up an HTML twitter page
47 | mocktwitter_status(rdt, file = "tools/readme/ex.html")
48 | ```
49 |
50 |
51 |
52 | In Rstudio, a preview will be displayed in the viewer pane.
53 |
54 |
55 |
56 | ## `mocktwitter_timeline()` (**dev in progress**)
57 |
58 | Use `mocktwitter_timeline()` with a user URL, screen name, user ID, or timeline
59 | data returned by [**{rtweet}**](http://rtweet.info) to create a [mock-up of a Twitter status HTML page](tools/readme/ex2.html):
60 |
61 |
62 | ```{r}
63 | ## (1) URL to a twitter timeline
64 | mocktwitter_timeline("https://twitter.com/kearneymw")
65 |
66 | ## (2) screen name or user ID of twitter account
67 | mocktwitter_timeline("kearneymw", file = "tools/readme/ex2.html")
68 | ```
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/R/mockup-timeline.R:
--------------------------------------------------------------------------------
1 | #' Create a mockup of a Twitter timeline
2 | #'
3 | #' Generates HTML twitter timeline page.
4 | #'
5 | #' @param x Twitter timeline data frame (as returned by rtweet).
6 | #' @param file File name to save as. Defaults to temporary file.
7 | #' @return Saves an html file
8 | #' @examples
9 | #' \dontrun{
10 | #' ## create mock-up of Twitter timeline
11 | #'
12 | #' ## the timeline URL
13 | #' mocktwitter_timeline("https://twitter.com/kearneymw")
14 | #'
15 | #' ## the screen name or user ID
16 | #' mocktwitter_timeline("kearneymw")
17 | #'
18 | #' ## or get timeline data from rtweet
19 | #' kmw <- rtweet::get_timeline("kearneymw")
20 | #' mocktwitter_timeline(kmw)
21 | #'
22 | #' }
23 | #' @export
24 | mocktwitter_timeline <- function(x, file = NULL) {
25 | UseMethod("mocktwitter_timeline")
26 | }
27 |
28 | mocktwitter_timeline.default <- function(x, file = NULL) {
29 | stop("must supply screen name, user id, or twitter timeline data frame ",
30 | "returned by an rtweet function")
31 | }
32 |
33 | #' @export
34 | mocktwitter_timeline.factor <- function(x, file = NULL) {
35 | x <- as.character(x)
36 | mocktwitter_timeline(x, file)
37 | }
38 |
39 | #' @export
40 | mocktwitter_timeline.character <- function(x, file = NULL) {
41 | stopifnot(length(x) == 1L)
42 | if (!is_token_configured()) {
43 | stop("please setup your Twitter API token, see: ",
44 | "http://rtweet.info/articles/auth.html or ",
45 | "vignette(\"auth\", package = \"rtweet\") for more information")
46 | }
47 | if (grepl("^http", x)) {
48 | x <- gsub(
49 | "https://[[:graph:]]{0,30}twitter\\.com/|/$",
50 | "", x)
51 | }
52 | mocktwitter_mytimeline(x, file)
53 | }
54 |
55 |
56 | mocktwitter_mytimeline <- function(user, file) {
57 | tml <- read_source(sprintf("https://twitter.com/%s", user))
58 | tml <- sub(".{0,97}signin-l.{0,148}", "", tml)
59 | tml <- sub(
60 | ".{0,112}SignupCallOut.*personalized timeline.*signup_callout.{0,60}",
61 | "", tml)
62 | tml <- sub(".{0,12}nav secondary-nav session-dropdown.*page-outer",
63 | "\n\n\n\n\n
1426 | You can add location information to your Tweets, such as your city or precise location, from the web and via third-party applications. You always have the option to delete your Tweet location history.
1427 | Learn more
1428 |
Give me your tired, your poor, your huddled masses yearning to breathe free, the wretched refuse of your teeming shore. Send these, the homeless, tempest-tossed to me, I lift my lamp beside the golden door!