Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jaromilfrossard/rstatsvideo

twitter bot
https://github.com/jaromilfrossard/rstatsvideo

twitter

Last synced: 3 months ago
JSON representation

twitter bot

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```

# rstatsvideo

Brain of the twitter bot `rstatsvideo` twitter bot https://twitter.com/rstatsvideo.

`rstatsvideo` re-tweets the new videos from the youtube channels listed on "data/channel.txt".

```{r message=FALSE, warning=FALSE, include=FALSE}
library(dplyr)
library(tidyr)
library(lubridate)
library(readr)
library(purrr)
library(glue)
library(ggplot2)
library(ggiraph)
library(stringr)
library(scales)

tb_perf<- readr::read_delim("data/performance.csv", delim =";",col_types = cols(
name_channel = col_character(), id_channel = col_character(),
id_video = col_character(), ymd_hms_video = col_datetime(format = ""),
id_twitter = col_character(), count_view = col_integer(),
count_comment = col_integer(), url_channel = col_character(),
url_video = col_character(), ymd_update = col_date(format = "")
),lazy = F)

tb_perf_channel <-
tb_perf%>%
group_by(name_channel,id_channel,url_channel)%>%
summarise(count_video = n(),
count_view = sum(count_view),
count_comment = sum(count_comment),.groups = "drop")%>%
mutate(channel = glue("{name_channel}\n{url_channel}"))

num_format = comma_format(accuracy = 1, big.mark = " ", decimal.mark = ".")

range_update = tb_perf%>%pull(ymd_update)%>%range()

```

### Most productive channels

```{r echo=FALSE,dev="svg"}
gg_channel<-
tb_perf_channel%>%
arrange(desc(count_video))%>%
slice(1:10)%>%
mutate(name_channel = reorder(name_channel, count_video))%>%
ggplot(aes(x =name_channel, y= count_video,fill = name_channel))+
geom_col()+
coord_flip()+
geom_text(aes(label=num_format(count_video)),hjust=1.1)+
scale_y_continuous(expand = expansion(c(0, 0.05) ),
labels = num_format)+
theme_bw()+
labs(title = "Top 10: Most productive channels",
subtitle = glue("Data collected using {tuber}",.open = "{{", .close="}}"),
y= "Number of videos",x =NULL,
caption = glue("Last update: {range_update[2]}"))+
theme(legend.position = "none")
gg_channel
```

### Most viewed videos

```{r echo=FALSE, dev="svg"}
options(scipen = 999)
gg_video<-
tb_perf%>%
arrange(desc(count_view))%>%
slice(1:10)%>%
mutate(title_video = str_remove(title_video,fixed("- YouTube")))%>%
mutate(title_video = str_trim((title_video)))%>%
mutate(title_video = case_when(
nchar(title_video)>50~glue("{stringr::str_sub(title_video,1,47)}..."),
TRUE~title_video))%>%
mutate(title = glue("{title_video}\n{name_channel}"))%>%
mutate(title = reorder(title, count_view))%>%
ggplot(aes(x =title , y= count_view,fill = title))+
geom_col()+
coord_flip()+
geom_text(aes(label=num_format(count_view)),hjust=1.1)+
scale_y_continuous(expand = expansion(c(0, 0.05) ),
labels = num_format)+
theme_bw()+
labs(title = "Top 10: Most viewed videos",
subtitle = glue("Data collected using {tuber}",.open = "{{", .close="}}"),
y= "Total of views",x =NULL,
caption = glue("Data updated between {range_update[1]} and {range_update[2]}"))+
theme(legend.position = "none")
gg_video
```