Skip to content

Commit

Permalink
feat(#30) - Subreddit Download & Command refactor
Browse files Browse the repository at this point in the history
* New args parser

* Changes

* Add cargo publish to CI

* New logging system

* debug now raises log level

* I promise this is the last logging commit

* Adding subreddit downloading

* Perfecting Subreddit export; removing auth need etc

* Fixing one test

* Docs
  • Loading branch information
MPult authored May 10, 2023
1 parent f5b54bc commit 02c6329
Show file tree
Hide file tree
Showing 17 changed files with 632 additions and 134 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ jobs:
git push
git tag "v${{ github.event.inputs.version }}"
git push --tags
- name: cargo publish
run: |
cargo login
cargo publish
publish:
name: Publish for ${{ matrix.os }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
# REXIT EXPORT FILES
/out
/out1
*.log
146 changes: 145 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ console = { version = "0.15.*", features = ["windows-console-colors"] }
html-escape = "0.2.13"
inquire = "0.6.*"
log = "0.4.*"
log4rs = "1.2.0"
pretty_env_logger = "0.4.*"
regex = "1.7.3"
reqwest = {version = "0.11.*", features = ["blocking", "multipart", "cookies", "gzip"]}
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,27 @@ Options:

Currently, you need to specify the formats, and it will ask for the username and password (or bearer token with that auth flow).

To get messages:
```bash
$ rexit --formats csv,json,txt --images
$ rexit messages --images
> Your Reddit Username: <USERNAME>
> Your Reddit Password: <PASSWORD>
```

To get saved posts:
```bash
$ rexit saved --images
> Your Reddit Username: <USERNAME>
> Your Reddit Password: <PASSWORD>
```

To download a Subreddit:
```bash
$ rexit subreddit r/redditDev --images
> Your Reddit Username: <USERNAME>
> Your Reddit Password: <PASSWORD>
```

It will save the files to the current directory. For CSV and TXT it is split by room. If an image (.jpg, .gif, .png, etc.) was sent the filename will be displayed as the message content, along with the prefix `FILE`.

## Installation
Expand Down
20 changes: 16 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@ set windows-shell := ["powershell.exe"]
set dotenv-load := true
default: test

run:
cargo run -- -f txt,json,csv --images
messages:
cargo run -- messages -f txt,json,csv --images

debug:
cargo run -- -f txt,json,csv --images --debug
messages-dbg:
cargo run -- messages -f txt,json,csv --images --debug

subreddit:
cargo run -- subreddit -n r/rexitTest -f txt,json,csv --images

subreddit-dbg:
cargo run -- subreddit -n r/rexitTest -f txt,json,csv --images --debug

saved:
cargo run -- saved -f txt,json,csv --images

saved-dbg:
cargo run -- saved -f txt,json,csv --images --debug

test:
cargo test
Expand Down
1 change: 1 addition & 0 deletions src/ReAPI/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use console::style;
use serde::Serialize;
use std::path::PathBuf;
use url::Url;
use log::{error, info};

#[derive(std::hash::Hash, Clone, Debug, Serialize)]
pub struct Image {
Expand Down
4 changes: 2 additions & 2 deletions src/ReAPI/login.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use console::style;
use regex::Regex;
use log::{debug};

impl super::Client {
pub fn logged_in(&self) -> bool {
Expand Down Expand Up @@ -108,7 +109,6 @@ impl super::Client {
for i in bearer_regex.captures_iter(&response.text().await.unwrap()) {
for i in i.get(1).iter() {
bearer_token = String::from(i.as_str().clone());
debug!("Bearer Token: {}", bearer_token.trim());
}
}

Expand All @@ -117,7 +117,7 @@ impl super::Client {
"{{\"type\":\"com.reddit.token\",\"token\":\"{bearer_token}\",\"initial_device_display_name\":\"Reddit Web Client\"}}"
);

debug!("Matrix request body: {:#?}", data);
debug!("Matrix request body: {:?}", data);

let response = self.reqwest_client
.post("https://matrix.redditspace.com/_matrix/client/r0/login")
Expand Down
4 changes: 2 additions & 2 deletions src/ReAPI/messages.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::{images, Client};
use chrono::{TimeZone, Utc};
use serde::{Deserialize, Serialize};
use log::{debug};

/// Struct for a singular message.
#[derive(Debug, Clone, Serialize)]
Expand Down Expand Up @@ -129,8 +130,7 @@ mod tests {

let rooms = super::super::download_rooms(&client, true);

let messages = super::list_messages(&client, rooms.await[1].clone().id, true).await;
println!("{:#?}", messages);
let _messages = super::list_messages(&client, rooms.await[1].clone().id, true).await;
}

fn get_login() -> (String, String) {
Expand Down
9 changes: 7 additions & 2 deletions src/ReAPI/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ mod images;
mod login;
mod messages;
mod rooms;
mod saved_posts;
mod users;
pub(crate) mod saved_posts;
pub(crate) mod subreddit;

pub use images::Image;

pub use rooms::download_rooms;
pub use rooms::Room;

pub use saved_posts::download_saved_posts;
pub use saved_posts::Post;
pub use saved_posts::SavedPost;

pub use subreddit::download_subreddit;
pub use subreddit::Post;


pub use messages::Content;
pub use messages::Message;
Expand Down
Loading

0 comments on commit 02c6329

Please sign in to comment.