File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ Version: 1.0
2
+
3
+ RestoreWorkspace: Default
4
+ SaveWorkspace: Default
5
+ AlwaysSaveHistory: Default
6
+
7
+ EnableCodeIndexing: Yes
8
+ UseSpacesForTab: Yes
9
+ NumSpacesForTab: 2
10
+ Encoding: UTF-8
11
+
12
+ RnwWeave: Sweave
13
+ LaTeX: pdfLaTeX
Original file line number Diff line number Diff line change
1
+ library(httr )
2
+ key = Sys.getenv(" MOT_key" ) # get API key
3
+ npages = 100000 # 59310
4
+ res <- list ()
5
+
6
+ pb = txtProgressBar(min = 1 , max = npages , initial = 1 ) # Make progress bar
7
+ for (i in 1 : npages ){
8
+ setTxtProgressBar(pb ,i )
9
+ # Request page
10
+ req <- GET(
11
+ url = " https://beta.check-mot.service.gov.uk/trade/vehicles/mot-tests" ,
12
+ query = list (
13
+ page = i
14
+ ),
15
+ add_headers(`Content-type` = " application/json" , `x-api-key` = key )
16
+ )
17
+ if (req $ status_code == 200 ){
18
+ # convert response content into text
19
+ data <- httr :: content(req , as = " text" , encoding = " UTF-8" )
20
+ data <- jsonlite :: fromJSON(data )
21
+ res [[i ]] <- data
22
+ rm(data )
23
+ }else if (req $ status_code == 404 ){
24
+ message(paste0(" Failed to get page " ,i ," page not found" ))
25
+ if (i > 90000 ){
26
+ stop(" must have run out of pages" )
27
+ }
28
+ }else {
29
+ message(paste0(" Failed to get page " ,i ," error " ,req $ status_code ))
30
+ }
31
+
32
+ if (i %% 100 == 0 ){
33
+ saveRDS(res ," F:/MOT_data/download_data.Rds" )
34
+ }
35
+
36
+ }
37
+
38
+ res <- dplyr :: bind_rows(res )
39
+ saveRDS(res ," F:/MOT_data/mot_history_all_2019_10_04.Rds" )
You can’t perform that action at this time.
0 commit comments