aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-12-25 12:06:12 +0100
committerHarald Eilertsen <haraldei@anduin.net>2018-12-25 12:06:12 +0100
commit8b43e105beebbefcd1597cb51a28c78360d78197 (patch)
treef774ebfb7a71025ef694c8ebe35ae014a4ca8260 /src
downloadprimstav-8b43e105beebbefcd1597cb51a28c78360d78197.tar.gz
primstav-8b43e105beebbefcd1597cb51a28c78360d78197.tar.bz2
primstav-8b43e105beebbefcd1597cb51a28c78360d78197.zip
First commit, working but incomplete.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
new file mode 100644
index 0000000..c4996f5
--- /dev/null
+++ b/src/main.rs
@@ -0,0 +1,62 @@
+// primstav - look up marked days on the norwegian primstav.
+// Copyright (C) 2018 Harald Eilertsen <haraldei@anduin.net>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+use chrono;
+use inflector::Inflector;
+use serde_yaml;
+use std::io::BufReader;
+use std::iter::Iterator;
+use std::fs::File;
+use std::str::FromStr;
+use std::string::ToString;
+
+fn print_entry(d: &serde_yaml::Value) {
+ let name = d.get("name").unwrap();
+ println!("{}", name.as_str().unwrap().to_sentence_case());
+
+ if let Some(alt_names) = d.get("alternative_names") {
+ let names = alt_names.as_sequence().unwrap().iter()
+ .map(|v| v.as_str().unwrap().to_title_case())
+ .collect::<Vec<_>>();
+ println!("({})", names.join(", "));
+ }
+
+ if let Some(syms) = d.get("symbols") {
+ let s = syms.as_sequence().unwrap().iter()
+ .map(|v| v.as_str().unwrap())
+ .collect::<Vec<_>>();
+ println!("Symboler: {}", s.join(", "));
+ }
+}
+
+fn main() {
+ let f = BufReader::new(File::open("data/primstav.yml").unwrap());
+ let data: serde_yaml::Value = serde_yaml::from_reader(f).unwrap();
+
+ let mut args = std::env::args().skip(1);
+ let local_date = match args.next() {
+ Some(s) => chrono::NaiveDate::parse_from_str(&s, "%d-%m-%Y").unwrap(),
+ None => chrono::Local::today().naive_utc(),
+ };
+
+ println!("{}", local_date.format("%A %d. %b, %Y"));
+
+ let key = local_date.format("%d%m").to_string();
+ match data.get(serde_yaml::Value::Number(u32::from_str(&key).unwrap().into())) {
+ Some(d) => print_entry(&d),
+ None => ()
+ }
+}