-
Notifications
You must be signed in to change notification settings - Fork 2
/
hent-data.R
77 lines (59 loc) · 2.46 KB
/
hent-data.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
library(tidyverse)
library(readr)
library(guardianapi)
# kør og giv den api-nøglen i console
guardianapi::gu_api_key()
#obama
obama <- guardianapi::gu_content(query = "Obama", from_date = "2009-01-20", to_date = "2009-01-20")
obama %>%
filter(!(type %in% c("gallery", "audio", "video"))) %>%
filter(!(section_id %in% c("tv-and-radio",
"film",
"football",
"stage",
"theguardian",
"lifeandstyle",
"sport",
"media",
"travel",
"music"))) %>%
select(c(id, web_publication_date, pillar_name, headline,
standfirst, body_text)) %>%
mutate(id = row_number()) %>%
write_csv("episodes/data/obama.csv")
#trump
trump <- guardianapi::gu_content(query = "Trump", from_date = "2017-01-20", to_date = "2017-01-20")
trump %>%
filter(!(type %in% c("gallery", "audio", "video", "liveblog"))) %>%
filter(!(section_id %in% c("tv-and-radio",
"film",
"football",
"stage",
"theguardian",
"lifeandstyle",
"sport",
"media",
"travel",
"music",
"artanddesign",
"books",
"fashion"))) %>%
select(c(id, web_publication_date, pillar_name, headline,
standfirst, body_text)) %>%
mutate(id = row_number()) %>%
write_csv("episodes/data/trump.csv")
# read in files -----------------------------------------------------------
trumpOrg <- read_csv("episodes/data/trump.csv")
obamaOrg <- read_csv("episodes/data/obama.csv")
# tilrette datasæt --------------------------------------------------------
trump <- trumpOrg %>%
mutate(president = "trump", .after = id)
obama <- obamaOrg %>%
mutate(president = "obama", .after = id)
obamaTrump <- obama %>%
rbind(trump) %>%
mutate(id = row_number()) %>%
mutate(standfirst = str_replace_na(standfirst, replacement = "")) %>%
mutate(text = str_c(headline, standfirst, body_text, sep = " "), .after = president) %>%
select(-c(headline, standfirst, body_text))
write_csv(obamaTrump, "episodes/data/obamaTrump.csv")