-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestExample5.awk
More file actions
50 lines (39 loc) · 1.24 KB
/
Copy pathrestExample5.awk
File metadata and controls
50 lines (39 loc) · 1.24 KB
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
BEGIN {
# These can also be specified on the command line.
IT = "rest";
FS = "[\t]";
# Put everything in DEFPROPS:
DEFPROPS["restQuery"] = "/_json/countries";
DEFPROPS["restIndent"] = 1;
DEFPROPS["httpUrl"] = "http://54.72.28.201:80/1.0/countries";
DEFPROPS["httpHeader.Accept"] = "application/json";
populationProps["httpHeader.Accept"] = "application/json";
}
# Check for invalid response code
isXmlNulNode(_$NODE) {
print getXmlNodeValue(_$NODE);
exit;
}
# else
{
country = getXmlNodeValue(getXmlNode(_$NODE, "text()"));
if (country ~/^[A-Z ]+$/) {
# Skip continents
print "Skipping continent", country;
next;
}
countryUrl = encodeUrl(country);
gsub(/\+/, "%20", countryUrl);
populationProps["httpUrl"] = "http://54.72.28.201:80/1.0/population/" countryUrl "/today-and-tomorrow";
loadRestNodeArray(populationProps, "_json/total_population/population/text()", populationNodeArray);
if (arrayLength(populationNodeArray) != 2) {
print "Skipping", country;
next;
}
delta = getXmlNodeValue(populationNodeArray[2]) - getXmlNodeValue(populationNodeArray[1]);
print country, ":", delta;
total += delta;
}
END {
print "Population will grow by approx.", total, "persons by tomorrow";
}