-
-
Save rigibun/5a2632eab71df2ae1767 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 import std.conv, | |
2 std.json, | |
3 std.stdio, | |
4 std.net.curl; | |
5 | |
6 auto getTemperatureString(in JSONValue temperature) in { | |
7 assert(temperature.type == JSON_TYPE.OBJECT); | |
8 } body { | |
9 if(temperature["max"].type != JSON_TYPE.NULL && temperature["min"].type != JSON_TYPE.NULL) | |
10 return "最高気温: " ~ temperature["max"].object["celsius"].str ~ "℃\n" | |
11 ~ "最低気温: " ~ temperature["min"].object["celsius"].str ~ "℃\n"; | |
12 else | |
13 return ""; | |
14 } | |
15 | |
16 auto makeReport(in JSONValue forecast) in { | |
17 assert(forecast.type == JSON_TYPE.OBJECT); | |
18 } body { | |
19 return forecast["dateLabel"].str ~ "の予報" ~ '\n' ~ "予報: " ~ forecast["telop"].str ~ '\n' | |
20 ~ forecast["temperature"].getTemperatureString; | |
21 } | |
22 | |
23 void main(string[] args) { | |
24 immutable cityNo = args.length > 1 ? args[1].to!uint : 130010u; | |
25 immutable restURI = "http://weather.livedoor.com/forecast/webservice/json/v1"; | |
26 immutable weather = get(restURI ~ "?city=" ~ cityNo.to!string).parseJSON; | |
27 immutable forecasts = weather["forecasts"].array; | |
28 immutable title = weather["title"].str; | |
29 | |
30 title.writeln; | |
31 writeln; | |
32 foreach(f; forecasts) { | |
33 f.makeReport.writeln; | |
34 } | |
35 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment