random styling and shit

This commit is contained in:
Joe Ardent 2023-10-22 13:35:41 -07:00
parent a09ec898f9
commit 5831d974ec
5 changed files with 62 additions and 56 deletions

View File

@ -1,10 +1,7 @@
use std::{ffi::OsString, time::Duration};
use clap::Parser;
use sqlx::{
query_as,
sqlite::{SqliteConnectOptions, SqlitePoolOptions},
};
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
use what2watch::{get_db_pool, import_utils::add_omega_watches};
#[derive(Debug, Parser)]
@ -42,7 +39,7 @@ fn main() {
let w2w_db = get_db_pool();
let dur = {
let (dur, rows) = {
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
@ -50,33 +47,16 @@ fn main() {
rt.block_on(async {
let dur = add_omega_watches(&w2w_db, &movie_db, num).await.unwrap();
let rows: i32 = sqlx::query_scalar("select count(*) from watches")
.fetch_one(&w2w_db)
.await
.unwrap();
w2w_db.close().await;
dur
(dur, rows)
})
};
let w2w_db = get_db_pool();
let movies: Vec<(String, f64, i64)> = {
let rt = tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()
.unwrap();
let movies = rt.block_on(
query_as(
"select julid_string(id), julid_seconds(id) * 1000, julid_counter(id) from watches",
)
.fetch_all(&w2w_db),
)
.unwrap();
rt.block_on(w2w_db.close());
movies
};
let rows = movies.len();
for m in movies.iter() {
println!("{}: {}ms, {} count", m.0, m.1, m.2);
}
println!(
"Added {rows} movies in {} seconds ({}ms, {}us)",
dur.as_secs_f64(),

View File

@ -7,7 +7,7 @@ use crate::{util::year_to_epoch, ShowKind, User, Watch, WatchQuest};
const USER_EXISTS_QUERY: &str = "select count(*) from users where id = $1";
const MOVIE_QUERY: &str = "select * from movies order by random() limit ?";
const MOVIE_QUERY: &str = "select * from movie_titles order by year, title asc limit ?";
//-************************************************************************
// the omega user is the system ID, but has no actual power in the app
@ -19,7 +19,7 @@ const BULK_INSERT: usize = 2_000;
pub struct ImportMovieOmega {
pub title: String,
pub year: Option<String>,
pub length: Option<String>,
pub runtime: Option<String>,
}
impl From<ImportMovieOmega> for Watch {
@ -28,7 +28,7 @@ impl From<ImportMovieOmega> for Watch {
id: OMEGA_ID, // this is ignored by the inserter
title: value.title,
release_date: year_to_epoch(value.year.as_deref()),
length: value.length.and_then(|v| v.parse::<i64>().ok()),
length: value.runtime.and_then(|v| v.parse::<i64>().ok()),
kind: ShowKind::Movie,
metadata_url: None,
added_by: OMEGA_ID,
@ -42,7 +42,7 @@ impl From<&ImportMovieOmega> for Watch {
id: OMEGA_ID,
title: value.title.to_string(),
release_date: year_to_epoch(value.year.as_deref()),
length: value.length.as_ref().and_then(|v| v.parse::<i64>().ok()),
length: value.runtime.as_ref().and_then(|v| v.parse::<i64>().ok()),
kind: ShowKind::Movie,
metadata_url: None,
added_by: OMEGA_ID,
@ -112,7 +112,7 @@ pub async fn add_omega_watches(
let title = &movie.title;
b.push_bind(ShowKind::Movie)
.push_bind(title)
.push_bind(movie.length.as_ref().and_then(|l| l.parse::<i64>().ok()))
.push_bind(movie.runtime.as_ref().and_then(|l| l.parse::<i64>().ok()))
.push_bind(year_to_epoch(movie.year.as_deref()))
.push_bind(omega);
});

View File

@ -1,3 +1,24 @@
p {
color: red
body {
background-color: darkgrey
}
#header {
text-align: end;
display: flex;
flex-direction: row;
justify-content: flex-end;
}
.warning {
background-color: goldenrod;
}
.watchlist {
background-color: ghostwhite;
}
.header_logged_in {
display: flex;
flex-direction: column;
}

View File

@ -4,14 +4,14 @@
{% when Some with (usr) %}
<div class="header_logged_in">
Hello, {{ usr.username }}!
</div>
<div>
<form action="/logout" enctype="application/x-www-form-urlencoded" method="post">
<button class="warning">
<input type="submit" value="sign out?">
<button>
<input type="submit" value="sign out?" class="warning">
</button>
</form>
</div>
</div>
{% else %} <!-- this is for the `when` statement -->
<div class="header_logged_out">
@ -19,8 +19,8 @@
</div>
{% endmatch %}
<hr />
{% else %} <!-- this is for whether or not the template has a user field or not -->
{% endif %}
<hr />

View File

@ -9,18 +9,13 @@
{% match user %}
{% when Some with (usr) %}
<div>
<p>
Hello, {{ usr.username }}! It's nice to see you.
</p>
</br>
<p>Here are your things to watch:</p>
<div class="watchlist">
<ul>
{% for watch in watches %}
<li><span class="watchtitle">{{watch.title}}</span> -- {% call m::get_or_default(watch.year(), "when??") %}: </li>
{% endfor %}
</ul>
</div>
<p>
<form action="/search" enctype="application/x-www-form-urlencoded" method="get">
<label for="search">Looking for something else to watch?</label>
@ -28,6 +23,16 @@ Hello, {{ usr.username }}! It's nice to see you.
<input type="submit" value="Let's go!">
</form>
</p>
<p>Here are your things to watch:</p>
<div class="watchlist">
<ul>
{% for watch in watches %}
<li><span class="watchtitle">{{watch.title}}</span> -- {% call m::get_or_default(watch.year(), "when??") %}:
</li>
{% endfor %}
</ul>
</div>
{% else %}
<p>
Heya, why don't you <a href="/login">log in</a> or <a href="/signup">sign up</a>?