/
query.d
73 lines (62 loc) · 1.45 KB
/
query.d
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
70
71
72
73
import core.thread;
import std.json;
import std.stdio;
import std.file;
import std.string;
enum tokenFileName = "token.txt";
version (AE)
{
import ae.net.asockets;
import ae.net.http.client;
import ae.net.ssl.openssl;
string httpGet(string url)
{
auto request = new HttpRequest;
request.resource = url;
if (tokenFileName.exists)
request.headers["Authorization"] = "token " ~ readText(tokenFileName).strip();
string result;
httpRequest(request,
(Data data)
{
result = (cast(char[])data.contents).idup;
std.utf.validate(result);
},
(string error) { throw new Exception(error); }
);
socketManager.loop();
return result;
}
}
else
{
import std.net.curl;
HTTP http;
static this()
{
http = HTTP();
http.verifyPeer = false;
if (tokenFileName.exists)
http.addRequestHeader("Authorization", "token " ~ readText(tokenFileName).strip());
}
char[] httpGet(string url)
{
return get(url, http);
}
}
void main()
{
auto repos = httpGet("https://api.github.com/users/DerelictOrg/repos").parseJSON().array;
foreach (repo; repos)
{
auto name = repo["name"].str;
//writeln(name, ":");
Thread.sleep(1.seconds);
auto packages = httpGet("https://api.github.com/repos/DerelictOrg/" ~ name ~ "/contents/source/derelict").parseJSON().array;
auto p = packages[0]["name"].str;
//foreach (p; packages)
// writeln(p["name"].str);
writefln("%s\t%s\tsource/derelict/%s", p, repo["clone_url"].str, p);
stdout.flush();
}
}