-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestExample3.awk
More file actions
44 lines (33 loc) · 1.18 KB
/
Copy pathrestExample3.awk
File metadata and controls
44 lines (33 loc) · 1.18 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
BEGIN {
# Use REST and a multidimensional array to get social media information:
# Tell compiler that this is an array.
temp2[0];
loadArray(http, "rest_example.xml");
# Users
http["httpUrl"] = "https://jsonplaceholder.typicode.com/users";
loadRestNodeArray(http, "/_json/_array/*", temp);
for (i in temp) {
id = getXmlNodeValue(getXmlNode(temp[i], "id/text()"));
users[id, "username"] = getXmlNode(temp[i], "username/text()");
users[id, "name"] = getXmlNode(temp[i], "name/text()");
userCount++;
}
# Posts and comments
http["httpUrl"] = "https://jsonplaceholder.typicode.com/posts";
loadRestNodeArray(http, "/_json/_array/*", temp);
for (i in temp) {
userId = getXmlNodeValue(getXmlNode(temp[i], "userId/text()"));
users[userId, "postCount"]++;
postId = getXmlNodeValue(getXmlNode(temp[i], "id/text()"));
http["httpUrl"] = "https://jsonplaceholder.typicode.com/comments?postId=" postId;
loadRestNodeArray(http, "/_json/_array/*", temp2);
users[userId, "commentCount"] += arrayLength(temp2);
}
for (i = 1; i <= userCount; i++) {
print users[i, "name"];
print users[i, "username"];
print users[i, "postCount"];
print users[i, "commentCount"];
print "";
}
}