-
Notifications
You must be signed in to change notification settings - Fork 6
/
pip_test.ado
69 lines (61 loc) · 2.06 KB
/
pip_test.ado
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
/*==================================================
project: Test last PIP queries
Author: R.Andres Castaneda
----------------------------------------------------
Creation Date: 6 Jun 2023 - 18:25:32
==================================================*/
/*==================================================
0: Program set up
==================================================*/
program define pip_test, rclass
version 16.1
if ("${pip_last_queries}" == "") {
noi disp "{err}{cmd:pip} has not been executed in this Stata session"
error
}
noi disp _n "{txt}{title:Metadata of last query/ies}" _n
local j = 1
foreach query of global pip_last_queries {
local queryfull "${pip_host}/`query'"
local incsv = ustrtrim(`"`queryfull'"')
local injson: subinstr local incsv "&format=csv" ""
if ustrregexm("`incsv'","(.+)/(.+)\?(.+)") {
local host = ustrregexs(1)
local endpoint = ustrregexs(2)
local parameters = ustrregexs(3)
}
noi disp "{txt}{ul:Query `j'}"
noi disp "{txt}{p2col 10 36 36 30:attribute}{dup 8: }value{p_end}" /*
*/ "{p2colset 10 30 32 30}" /*
*/ "{res}{p2line}" /*
*/ "{p2col :{res:host}} {txt:`host'}{p_end}" /*
*/ "{p2col :{res:endpoint}} {txt:`endpoint'}{p_end}"
tokenize "`parameters'", parse("&")
local i = 1
while ("`1'" != "") {
if ("`1'" == "&") {
macro shift
continue
}
if (`i' == 1) {
local aname "parameters"
local i = `i' + 1
}
else local aname "."
noi disp "{p2col :{res:`aname'}} {txt:`1'}{p_end}"
macro shift
}
noi disp "{p2line}"
//------------ Build Stata calls
mata: st_local("fuse", pathjoin("${pip_cachedir}", "`hash'.dta"))
local duse `"use "`fuse'", clear "'
local ddelete `"pip_cache delete, piphash(`hash')"'
noi disp "{break}{col 10}{ul:{res:ACTION:}}{col 20}" /*
*/ `" {browse "`injson'":see in browser} or {col 35}"' /*
*/ `"{browse "`incsv'":download .csv}"' _n
local j = `j' + 1
}
end
exit
/* End of do-file */
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><