Open bmitch opened 5 years ago
Cool looking forward to it!
On Mon, Aug 19, 2019, 6:50 PM Noah Trupin, notifications@github.com wrote:
I’m going to look into this tonight/tomorrow. To do so, I’m going to have to use another library: reqwest https://docs.rs/reqwest/0.9.19/reqwest/.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bmitch/relogio/issues/3?email_source=notifications&email_token=AA6S7ZJCCP3TDUV3ONMCPULQFNEVJA5CNFSM4ILQQZV2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4UZMUI#issuecomment-522819153, or mute the thread https://github.com/notifications/unsubscribe-auth/AA6S7ZMPJLWMLYOYSENBM4LQFNEVJANCNFSM4ILQQZVQ .
I've broken it down into three parts:
Query https://api.usno.navy.mil/moon/phase?date=[MM/DD/YYYY]&nump=1
using reqwest.
let ref_date = Local::now().date();
let moon_req_body = reqwest::get(&format!("https://api.usno.navy.mil/moon/phase?date={}&nump=1", format!("{}", ref_date.format("%m/%d/%Y").to_string())).to_string()).unwrap();
Parse the JSON to get the moon phase (you can use serde)
let moon_req_data = moon_req_body.text().unwrap();
// Do JSON parsing on the string.
Print different structures to the screen based on the moon phase using the same elements you currently use. It could be in the shape of the light part of the moon. For example, build the shape using:
window.printw("█");
I'm currently on vacation, so I don't know how easy it will be for me to fit this in, but here's a blueprint if you'd like to give it a shot!
Fantastic @ntrupin thanks! I may give it a shot but feel free to do it if you have time as well. But vacation should take priority! :)
For what to show I'm thinking of:
○ - Full Moon
◑ - Third Quarter
● - New Moon
◐ - First Quarter
I wrote a function to fetch the data (see #22). I'm working on deserializing it, and have fallen into a bit of a rabbit hole with Serde, having to manually implement Deserialize
because of the way moon phases are represented in the json. I have an enum to represent moon phase, but the json has "Full Moon" with a space, and enum variants can't have spaces, so auto-deriving doesn't work. I don't think manually implementing Deserialize
will be too hard, but I suspect there might be an easier way. Let me know if you have any ideas.
Thanks @robbystk that's great.
I'm a Rust newbie so you probably have a better idea than I do :)
No rush at all though. Take your time and if you don't want to look at it any further I can take it from where you left off. Thanks for the help!
I just realized there is an easier way. Instead of making custom data structures to hold all the data, we can parse the json with serde_json::from_str()
, then just pick out what we need. This will also remove serde as a dependency.
Thank you so much @robbystk - I am very busy until Thursday so may not get a chance to review. Your contribution is very much appreciated!
I’m going to look into this tonight/tomorrow. To do so, I’m going to have to use another library: reqwest.