-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dpdlGetNews.h
53 lines (38 loc) · 1.03 KB
/
dpdlGetNews.h
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
# File: app/getnews/dpdlGetNews.h
#
# Example: Download top 10 story news via json http get requests. Data is decoded and stored in a struct
#
# Author: A.Costa
# e-mail: info@dpdl.io
#
#
import('http')
import('json')
struct Story {
int id
string title
string url
}
# main
string stories_url = "https://hacker-news.firebaseio.com/v0/topstories.json"
string item_base_url = "https://hacker-news.firebaseio.com/v0/item/"
println("downloading news...")
string resp = http.getraw(stories_url)
raise(resp, "Error in downloading data")
object jsonobj = json.parse(resp, 0)
ids[] = array(jsonobj)
string story_url
struct Story storyobj
int c = 0
for(c < 10)
println("---------------------------------------------------------------------")
story_url = item_base_url + ids[c] + ".json"
resp = http.getraw(story_url)
raise(resp, "Error in downloading story")
storyobj = json.decode(resp, storyobj)
println("id: " + storyobj.id)
println("title: " + storyobj.title)
println("url: " + storyobj.url)
c = c+1
endfor
println("finished!")