-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron_job.R
56 lines (45 loc) · 1.18 KB
/
cron_job.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
packages <- list(
"httr",
"dplyr",
"tidyr",
"stringr",
"jsonlite",
"rvest",
"readr",
"countrycode",
"xml2",
"devtools")
package.check <- lapply(
packages,function(x) {
if (!require(x, character.only = TRUE)) {
install.packages(x, dependencies = TRUE)
library(x, character.only = TRUE)
}
}
)
devtools::install_github("elliottmess/pcodesocha")
library(httr)
library(dplyr)
library(tidyr)
library(stringr)
library(jsonlite)
library(rvest)
library(readr)
library(countrycode)
library(purrr)
library(xml2)
library(pcodesOCHA)
source("R/pcodes_scrapping.R")
source("R/utils.R")
all_pcodes_df <- all_pcodes()
all_pcodes_df <- all_pcodes_df[,colSums(is.na(all_pcodes_df))<nrow(all_pcodes_df)] %>%
distinct()
write_csv(all_pcodes_df, paste0("output/all_pcodes", ".csv"))
countries_list <- available_countries()
write_csv(countries_list, "output/available_countries.csv")
if(!dir.exists("output/countries")){
dir.create("output/countries")
}
country_iso3 <- purrr::map(countries_list$country_iso3code,
~ write_csv(country_pcodes_iso3(.x),
paste0("output/countries/", .x,"_pcodes", ".csv")))