Skip to content

feat: Add URL capabilities #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ serde = "1.0.164"
serde_derive = "1.0.164"
almanac = "0.4.0"
ctrlc = "3.4.0"
reqwest = { version = "0.11", features = ["blocking"] }

[dependencies.ical]
version = "0.8.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ cargo install calio

Then you'll be able to run `calio` from whichever directory you're in.


## How-To

**Calio** is easy to use, just provide a file path or stdin to read the
ics contents:

```
calio /some/file/path/cal.ics
calio https://gist.githubusercontent.com/DeMarko/6142417/raw/1cd301a5917141524b712f92c2e955e86a1add19/sample.ics
cat /some/file/path.cal.ics | calio
```

Expand Down
28 changes: 25 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::env;
use std::fs::File;
use std::io::BufReader;
use std::path::Path;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;

Expand Down Expand Up @@ -160,9 +161,30 @@ Tiny CLI tool that helps to visualize iCal file content in the terminal.
if args.len() > 2 {
keep_alive = args[2] == "--keep-alive".to_string();
}
let file = File::open(&args[1]).unwrap();
let buf = BufReader::new(file);
let calendars = Calendar::parse(buf).unwrap();

let path = Path::new(&args[1]);
let calendars = if path.exists() {
let file = File::open(path).unwrap();
let buf = BufReader::new(file);
Calendar::parse(buf).unwrap()
} else {
// Print out a message while the calendar gets downloaded
let s = format!(
"{}{}",
"Fetching calendar from ".dimmed(),
&args[1].dimmed()
);
print!("{}", s);
// Download the calendar from the given URL
let url_text = reqwest::blocking::get(&args[1]).unwrap().text().unwrap();
// Clear the printed message with \r
// https://stackoverflow.com/a/35280799/14555505
print!("\r{: <1$}", "", s.len());
// Convert the url to a buffered reader
let buf = BufReader::new(url_text.as_bytes());
// Convert the buffered reader to a Calendar
Calendar::parse(buf).unwrap()
};
print_events(calendars.iter());
};

Expand Down