-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrestExample2.awk
More file actions
49 lines (35 loc) · 1.24 KB
/
Copy pathrestExample2.awk
File metadata and controls
49 lines (35 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
BEGIN {
# Use REST and an array of arrays to get social media information:
loadArray(http, "rest_example.xml");
# Users
http["httpUrl"] = "https://jsonplaceholder.typicode.com/users";
loadRestNodeArray(http, "/_json/_array/_record", temp);
for (i in temp) {
id = getXmlNodeValue(getXmlNode(temp[i], "id/text()"));
user["username"] = getXmlNode(temp[i], "username/text()");
user["name"] = getXmlNode(temp[i], "name/text()");
users[id] = cloneArray(user);
}
# Posts and comments
http["httpUrl"] = "https://jsonplaceholder.typicode.com/posts";
loadRestNodeArray(http, "/_json/_array/_record", temp);
for (i in temp) {
userId = getXmlNodeValue(getXmlNode(temp[i], "userId/text()"));
user = users[userId];
user["postCount"]++;
postId = getXmlNodeValue(getXmlNode(temp[i], "id/text()"));
http["httpUrl"] = "https://jsonplaceholder.typicode.com/comments?postId=" postId;
loadRestNodeArray(http, "/_json/_array/_record", temp2);
for (j in temp2) {
users[userId]["commentCount"]++;
}
}
for (i in users) {
user = users[i];
print "name =", user["name"];
print "username =", user["username"];
print "post count =", user["postCount"];
print "comments for post(s) = ", user["commentCount"];
print "";
}
}