Compare commits

..

No commits in common. "ad331ee121413890e969bd1159811544557c9963" and "7da61ae3ab889f4349532add56debbf812c7fe69" have entirely different histories.

5 changed files with 17 additions and 49 deletions

2
Cargo.lock generated
View file

@ -873,7 +873,7 @@ dependencies = [
[[package]]
name = "prose_dl"
version = "0.2.0"
version = "0.1.0"
dependencies = [
"clap",
"reqwest",

View file

@ -1,6 +1,6 @@
[package]
name = "prose_dl"
version = "0.2.0"
version = "0.1.0"
edition = "2021"
[dependencies]

View file

@ -20,9 +20,4 @@ folder named after your username:
$ prose_dl <username>
```
Will download the special files too:
```bash
$ prose_dl -s <username>
```
More info with the `--help` option.

View file

@ -1,46 +1,23 @@
/// Download all the posts
pub async fn download_posts(
posts: (String, Vec<String>),
dir: String,
download_special_files: bool,
) {
/// Download all the posts from the raw endpoint
pub async fn download_posts(posts: (String, Vec<String>), dir: String) {
// Create folder, silently ignore if already exists
std::fs::create_dir(&dir).unwrap_or_default();
// Download all the posts
for post in posts.1 {
download(&posts.0, &dir, post, "md").await;
}
// Check if specials files need to be downloaded
if download_special_files {
let special_files = [
(String::from("_readme"), "md"),
(String::from("_styles"), "css"),
];
for file in special_files {
download(&posts.0, &dir, file.0, file.1).await;
}
}
}
/// Download a file from the raw endpoint
async fn download(url: &String, output_dir: &String, post_name: String, extension: &str) {
// Endpoint name
let endpoint = "raw";
let data = reqwest::get(format!("{}/{}/{}", url, endpoint, post_name))
.await
.unwrap()
.text()
.await
for post in posts.1 {
let mut file = std::fs::File::create(format!("{}/{}.md", dir, post)).unwrap();
std::io::Write::write_all(
&mut file,
reqwest::get(format!("{}/{}/{}", posts.0, endpoint, post))
.await
.unwrap()
.text()
.await
.unwrap()
.as_bytes(),
)
.unwrap();
if data != "post not found\n" {
// Write file with the content
let mut file =
std::fs::File::create(format!("{}/{}.{}", output_dir, post_name, extension)).unwrap();
std::io::Write::write_all(&mut file, data.as_bytes()).unwrap();
}
}

View file

@ -26,10 +26,6 @@ struct Cli {
/// Scheme: HTTP/HTTPS
#[clap(long, value_parser, default_value = "https")]
scheme: String,
/// Download special files
#[clap(short, takes_value = false)]
special_files: bool,
}
#[tokio::main]
@ -51,5 +47,5 @@ async fn main() {
};
// Download the posts
download::download_posts(posts, directory, cli.special_files).await;
download::download_posts(posts, directory).await;
}