about summary refs log tree commit diff stats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs66
1 files changed, 63 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index dd532a4..ff6e8fd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -13,12 +13,12 @@ fn main() {
         .author("Ben Morrison (gbmor)")
         .about("Command-line community notices system")
         .subcommand(clap::SubCommand::with_name("post").about("Post a new notice"))
-        /*.subcommand(
+        .subcommand(
             clap::SubCommand::with_name("update")
                 .about("Update a notice you've posted")
                 .arg(clap::Arg::with_name("id").help("Numeric ID of the post")),
         )
-        .subcommand(
+        /*.subcommand(
             clap::SubCommand::with_name("delete")
                 .about("Delete a notice you've posted")
                 .arg(clap::Arg::with_name("id").help("Numeric ID of the post")),
@@ -28,7 +28,7 @@ fn main() {
     let start = time::Instant::now();
     logging::init();
     info!("clinte starting up!");
-    println!("clinte-0.1-dev");
+    println!("clinte v{}", clap::crate_version!());
     println!("a community notices system");
     println!();
 
@@ -39,6 +39,9 @@ fn main() {
     if arg_matches.subcommand_matches("post").is_some() {
         info!("New post...");
         post(&db);
+    } else if arg_matches.subcommand_matches("update").is_some() {
+        info!("Updating post ...");
+        update(&db);
     }
 
     list_matches(&db);
@@ -116,3 +119,60 @@ fn post(db: &db::Conn) {
 
     println!();
 }
+
+fn update(db: &db::Conn) {
+    let cur_user = users::get_current_username()
+        .unwrap()
+        .into_string()
+        .unwrap();
+
+    println!();
+    println!("ID number of your post to edit?");
+    let mut id_num_in = String::new();
+    io::stdin().read_line(&mut id_num_in).unwrap();
+    let id_num_in: u32 = id_num_in.trim().parse().unwrap();
+
+    let mut get_stmt = db
+        .conn
+        .prepare("SELECT * FROM posts WHERE id = :id")
+        .unwrap();
+
+    let row = get_stmt
+        .query_row_named(&[(":id", &id_num_in)], |row| {
+            let title: String = row.get(1).unwrap();
+            let author = row.get(2).unwrap();
+            let body = row.get(3).unwrap();
+            Ok(vec![title, author, body])
+        })
+        .unwrap();
+
+    if cur_user != row[1] {
+        println!();
+        println!("Username mismatch - can't update post!");
+        return;
+    }
+
+    let mut new_title = String::new();
+    let mut new_body = String::new();
+
+    println!("Updating post {}", id_num_in);
+    println!();
+    println!("Title: {}\n\nBody: {}", row[0], row[2]);
+    println!();
+    println!("Enter new title:");
+    io::stdin().read_line(&mut new_title).unwrap();
+    println!();
+    println!("Enter new body:");
+    io::stdin().read_line(&mut new_body).unwrap();
+    println!();
+
+    let new_title = new_title.trim();
+    let new_body = new_body.trim();
+
+    let title_stmt = format!("UPDATE posts SET title = :title WHERE id = {}", id_num_in);
+    let mut stmt = db.conn.prepare(&title_stmt).unwrap();
+    stmt.execute_named(&[(":title", &new_title)]).unwrap();
+    let body_stmt = format!("UPDATE posts SET body = :body WHERE id = {}", id_num_in);
+    let mut stmt = db.conn.prepare(&body_stmt).unwrap();
+    stmt.execute_named(&[(":body", &new_body)]).unwrap();
+}
eight: bold } /* Literal.Number.Integer.Long */
#+HTML_HEAD: <link rel="stylesheet" href="../../static/style.css">
#+HTML_HEAD: <link rel="icon" href="../../static/projects/cetus/favicon.png" type="image/png">
#+EXPORT_FILE_NAME: index
#+TITLE: Cetus

Cetus is a simple wallpaper management tool written in Go. It supports multiple
sources for fetching the background.

| Project Home | [[https://andinus.nand.sh/projects/cetus/][Cetus]]           |
| Source Code  | [[https://framagit.org/andinus/cetus][Andinus / Cetus]] |

*Note*: Cetus is a work in-progress & many features are yet to be implemented.

*Dependency*: [[https://feh.finalrewind.org/][feh]]

* NASA Astronomy Picture of the Day
cetus-nasa uses NASA's API to get the Astronomy Picture of the Day.

*Note*: If the returned media type is not image then cetus-nasa will only print
details & not try to set background.

** Features
- set APOD as background
- fetch information on APOD
- choose custom date
- choose date randomly
** Examples
#+BEGIN_SRC sh
# set currently APOD as background
cetus-nasa

# set date randomly
cetus-nasa -random

# set 2020-01-05 APOD as background
cetus-nasa -date 2020-01-05

# 2020-03-15 APOD is a video, cetus will only print details
cetus-nasa -date 2020-03-15

# change api endpoint & api key
cetus-nasa -api https://api.nasa.gov/planetary/apod \
           -api-key DEMO_KEY

# don't set background, just fetch information
cetus-nasa -fetch-only

# don't output anything
cetus-nasa -quiet

# don't set background, just fetch & don't output anything
cetus-nasa -quiet -fetch-only # why would anyone do this?
#+END_SRC
* Demo
I just run some cetus commands on my computer, nothing fancy. I'll make better
demo videos someday.

*Note*: Cetus was restructured multiple times & these demos may not work on the
latest release.

| Version | Video                                                                |
|---------+----------------------------------------------------------------------|
| v0.4.1  | https://diode.zone/videos/watch/a52cc728-93e5-4bba-9375-752e1dba306d |
| v0.3.1  | https://diode.zone/videos/watch/0808c512-315a-4dab-9526-4a537e8c3257 |
| v0.2.0  | https://diode.zone/videos/watch/12db31e1-3517-4888-ad06-55f3859447a1 |
* Installation
** Binary
framagit.org compiles cetus for OpenBSD & GNU/Linux amd64 on every release, to
get the binary goto [[https://framagit.org/andinus/cetus/pipelines?scope=tags&page=1][Pipelines - tags]].

To get the latest binary goto [[https://framagit.org/andinus/cetus/pipelines][Pipelines]].

** From Source
#+BEGIN_SRC sh
# get master branch archive
curl -o cetus-master.tar.gz \
     https://framagit.org/andinus/cetus/-/archive/master/cetus-master.tar.gz

# extract the archive
tar -xzf cetus-master.tar.gz

# install cetus
cd cetus-master && \
    go install ./cmd/cetus-nasa
#+END_SRC