diff --git a/.gitignore b/.gitignore index 9f0b9570d..3c49113be 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,5 @@ __pycache__ *.fls *.synctex.gz cache +/target +Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 000000000..26b10126b --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "dfm-cv" +version = "0.1.0" +authors = ["Dan Foreman-Mackey "] +edition = "2018" +readme = "README.md" +homepage = "https://github.com/dfm/cv" +repository = "https://github.com/dfm/cv.git" +description = "My CV" +license = "CC BY" + +[dependencies] +adsabs = "0.1" +serde_json = "1.0" +html-escape = "0.2" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 000000000..cc2b4cc32 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,26 @@ +use adsabs::prelude::*; + +fn main() -> Result<(), AdsError> { + let client = Ads::from_env()?; + + let docs = client + .search("author:\"Foreman-Mackey\" AND (doctype:\"article\" OR doctype:\"eprint\")") + .fl("id,title,author,doi,year,pubdate,pub,volume,page,identifier,doctype,citation_count,bibcode") + .sort("date") + .iter_docs().map(|doc| + { + // Here I'm just removing HTML encoding since the API will encode + // characters like '&' as '&', for example. + doc.map(|mut doc|{ + doc.title = doc.title.map(|t| { + t.iter() + .map(|t| html_escape::decode_html_entities(t).to_string()) + .collect::>() + }); + doc + }) + }).collect::, AdsError>>()?; + + std::fs::write("data/ads.json", serde_json::to_string_pretty(&docs)?)?; + Ok(()) +}