-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9a77ab
commit 1b2fbfc
Showing
17 changed files
with
182 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use maud::{html, Markup}; | ||
|
||
pub struct TextInput { | ||
pub placeholder: String, | ||
pub name: String, | ||
pub is_required: Option<bool>, | ||
} | ||
|
||
pub enum InputType { | ||
TextInput(TextInput), | ||
} | ||
|
||
pub fn gen_input(raw_input: InputType) -> Markup { | ||
match raw_input { | ||
InputType::TextInput(input) => { | ||
html! { | ||
input."w-full px-4 py-2 border border-gray-300 rounded text-white bg-zinc-700" type="text" name=(input.name) id=(input.name) placeholder=(input.placeholder) required=(input.is_required.unwrap_or(false)) {} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod input; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
pub mod buttons; | ||
pub mod header; | ||
|
||
pub mod forms; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pub mod scrape_activity_page; | ||
|
||
pub fn init(cfg: &mut actix_web::web::ServiceConfig) { | ||
cfg.service(scrape_activity_page::scrape_activity_page); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use actix_web::{post, web, HttpResponse, Responder}; | ||
use maud::html; | ||
|
||
use crate::scraping::parser::parse_url; | ||
|
||
#[derive(serde::Deserialize)] | ||
pub struct FormData { | ||
url: String, | ||
} | ||
|
||
#[post("/scrape-activity-page")] | ||
async fn scrape_activity_page(form: web::Form<FormData>) -> impl Responder { | ||
let url = &form.url; | ||
if let Some(new_url) = parse_url(url) { | ||
let markup = match new_url { | ||
crate::scraping::parser::URLType::Thread(thread) => { | ||
html! { | ||
div { | ||
"Thread: " (thread.thread_id) | ||
} | ||
} | ||
} | ||
crate::scraping::parser::URLType::Post(post) => { | ||
html! { | ||
div { | ||
"Post: " (post.post_id) | ||
} | ||
} | ||
} | ||
}; | ||
|
||
let html = markup.into_string(); | ||
return HttpResponse::Ok().body(html); | ||
} else { | ||
let markup = html! { | ||
div { | ||
"Invalid URL: " (url) | ||
} | ||
}; | ||
let html = markup.into_string(); | ||
return HttpResponse::Ok().body(html); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
pub mod main; | ||
use actix_web::web; | ||
pub mod api; | ||
pub mod not_found; | ||
pub mod test; | ||
pub mod pages; | ||
pub fn init(cfg: &mut actix_web::web::ServiceConfig) { | ||
cfg.configure(pages::init); | ||
cfg.service(web::scope("/api").configure(api::init)); | ||
cfg.default_service(web::route().to(not_found::not_found)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pub mod home; | ||
pub mod scraper; | ||
pub mod test; | ||
|
||
pub fn init(cfg: &mut actix_web::web::ServiceConfig) { | ||
cfg.service(home::main); | ||
cfg.service(test::test); | ||
cfg.service(scraper::scraper); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::components::{ | ||
buttons::{gen_button, ButtonType, FormSubmitButton}, | ||
forms::input::{gen_input, InputType, TextInput}, | ||
header::{generate_header, Header}, | ||
}; | ||
use actix_web::{get, HttpResponse, Responder}; | ||
use maud::html; | ||
|
||
#[get("/scraper")] | ||
async fn scraper() -> impl Responder { | ||
let header = generate_header(Header { | ||
title: "MafiaScum Scraper", | ||
}); | ||
|
||
let markup = html! { | ||
(header) | ||
body."bg-zinc-900 w-screen h-screen flex flex-col items-center justify-center" { | ||
h1 ."text-3xl text-white font-bold pb-2" { "MafiaScum Scraper" } | ||
div."text-xl text-white pb-2" { | ||
"Enter a URL to scrape from mafiascum.net" | ||
} | ||
form."text-center w-1/2 flex flex-col items-center justify-center" hx-post="/api/scrape-activity-page" hx-target="#response" { | ||
(gen_input(InputType::TextInput(TextInput { | ||
name: "url".to_string(), | ||
placeholder: "https://mafiascum.net".to_string(), | ||
is_required: Some(true), | ||
}))) | ||
(gen_button(ButtonType::FormSubmit(FormSubmitButton { | ||
text: "Submit".to_string(), | ||
}))) | ||
}; | ||
|
||
div."text-white" id="response" { | ||
"Response Here" | ||
} | ||
} | ||
}; | ||
|
||
let html = markup.into_string(); | ||
|
||
HttpResponse::Ok().body(html) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod parser; | ||
pub mod scraper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use url::Url; | ||
|
||
pub struct ThreadURL { | ||
pub thread_id: String, | ||
} | ||
|
||
pub struct PostURL { | ||
pub post_id: String, | ||
} | ||
|
||
pub enum URLType { | ||
Thread(ThreadURL), | ||
Post(PostURL), | ||
} | ||
|
||
pub fn parse_url(url_str: &str) -> Option<URLType> { | ||
if let Ok(parsed_url) = Url::parse(url_str) { | ||
if let Some((_, id)) = parsed_url.query_pairs().find(|(key, _)| key == "t") { | ||
return Some(URLType::Thread(ThreadURL { | ||
thread_id: id.to_string(), | ||
})); | ||
} | ||
|
||
if let Some((_, id)) = parsed_url.query_pairs().find(|(key, _)| key == "p") { | ||
return Some(URLType::Post(PostURL { | ||
post_id: id.to_string(), | ||
})); | ||
} | ||
} | ||
None | ||
} |
Empty file.