feat(scraper): add scraper CLI

This commit is contained in:
Matthew Esposito 2024-10-21 20:54:05 -04:00
parent 49ef59e000
commit f3d2f0cc59
4 changed files with 114 additions and 3 deletions

View file

@ -11,6 +11,7 @@ use once_cell::sync::Lazy;
use regex::Regex;
use rinja::Template;
use rust_embed::RustEmbed;
use serde::Serialize;
use serde_json::Value;
use serde_json_path::{JsonPath, JsonPathExt};
use std::collections::{HashMap, HashSet};
@ -46,6 +47,7 @@ pub enum ResourceType {
}
// Post flair with content, background color and foreground color
#[derive(Serialize)]
pub struct Flair {
pub flair_parts: Vec<FlairPart>,
pub text: String,
@ -54,7 +56,7 @@ pub struct Flair {
}
// Part of flair, either emoji or text
#[derive(Clone)]
#[derive(Clone, Serialize)]
pub struct FlairPart {
pub flair_part_type: String,
pub value: String,
@ -96,12 +98,14 @@ impl FlairPart {
}
}
#[derive(Serialize)]
pub struct Author {
pub name: String,
pub flair: Flair,
pub distinguished: String,
}
#[derive(Serialize)]
pub struct Poll {
pub poll_options: Vec<PollOption>,
pub voting_end_timestamp: (String, String),
@ -129,6 +133,7 @@ impl Poll {
}
}
#[derive(Serialize)]
pub struct PollOption {
pub id: u64,
pub text: String,
@ -158,13 +163,14 @@ impl PollOption {
}
// Post flags with nsfw and stickied
#[derive(Serialize)]
pub struct Flags {
pub spoiler: bool,
pub nsfw: bool,
pub stickied: bool,
}
#[derive(Debug)]
#[derive(Debug, Serialize)]
pub struct Media {
pub url: String,
pub alt_url: String,
@ -264,6 +270,7 @@ impl Media {
}
}
#[derive(Serialize)]
pub struct GalleryMedia {
pub url: String,
pub width: i64,
@ -304,6 +311,7 @@ impl GalleryMedia {
}
// Post containing content, metadata and media
#[derive(Serialize)]
pub struct Post {
pub id: String,
pub title: String,
@ -470,7 +478,7 @@ pub struct Comment {
pub prefs: Preferences,
}
#[derive(Default, Clone)]
#[derive(Default, Clone, Serialize)]
pub struct Award {
pub name: String,
pub icon_url: String,
@ -484,6 +492,7 @@ impl std::fmt::Display for Award {
}
}
#[derive(Serialize)]
pub struct Awards(pub Vec<Award>);
impl std::ops::Deref for Awards {