Why Nostr? What is Njump?
2024-07-03 00:49:43

npub109…p6na7 on Nostr: commit fabc9bb2d5ad2aca596dcf168ab49406d0ed18f4 Author: randymcmillan ...

commit fabc9bb2d5ad2aca596dcf168ab49406d0ed18f4
Author: randymcmillan <[email protected]>
Date: Tue May 14 08:51:03 2024 -0400

src/watch_list.rs:parse_json:intermediate

diff --git a/bins/src/watch_list.rs b/bins/src/watch_list.rs
index 1a8e5381d..702a39e9a 100644
--- a/bins/src/watch_list.rs
+++ b/bins/src/watch_list.rs
@@ -1,8 +1,61 @@
//use futures::executor::block_on;
//use url::Url;

+use serde::{Deserialize, Serialize};
+use serde_json::{Result, Value};
+
use crate::get_relays_public;
-pub async fn parse_urls(urls_str: &str) -> Result<Vec<String>, url::ParseError> {
+
+#[derive(Serialize, Deserialize)]
+struct Relay {
+ url: String,
+}
+
+pub async fn parse_json(urls_str: &str) -> Result<Vec<String>> {
+ let mut urls: Vec<String> = Vec::new();
+ let mut part = String::new();
+ let mut collected = Vec::new();
+ let mut char_iter = urls_str.chars();
+ for url_str in urls_str.chars() {
+ if char_iter.next() == Some('[') {
+
+ }
+ //if char_iter.last() == Some(',') {}
+ loop {
+ match char_iter.next() {
+ Some(']') => {
+ print!("{{\"url\":\"wss://relay.gnostr.org\"}},\n");
+ print!("{{\"url\":\"wss://proxy.gnostr.org\"}}");
+ return std::result::Result::Ok(collected);
+ }
+ Some(',') | Some(' ') => {
+ if !part.is_empty() {
+
+
+ let relay = Relay {
+ url: part.to_owned(),
+ };
+
+ // Serialize it to a JSON string.
+ let j = serde_json::to_string(&relay)?;
+ //println!("{}, ", j);
+ print!("{},", format!("{}", j.clone().replace("\\\"", "")));
+
+
+ collected.push(part.clone());
+//print!("parse_json:char_iter.next()={} ", format!("{}", part.clone().replace("\"", "")));
+ part = String::new();
+
+ } //end if !part.is_empty()
+ },
+ //None => todo!(),
+ x => part.push(x.expect("REASON")),
+ } //end match
+ } //end loop
+ }
+ Ok(urls)
+}
+pub async fn parse_urls(urls_str: &str) -> Result<Vec<String>> {
let mut urls: Vec<String> = Vec::new();
let mut part = String::new();
let mut collected = Vec::new();
@@ -17,7 +70,7 @@ pub async fn parse_urls(urls_str: &str) -> Result<Vec<String>, url::ParseError>
Some(',') | Some(' ') => {
if !part.is_empty() {
collected.push(part.clone());
- print!("{}, ", format!("{}", part.clone().replace("\"", "")));
+ print!("char_iter.next()={}, ", format!("{}", part.clone().replace("\"", "")));
part = String::new();
}
},
@@ -25,15 +78,23 @@ pub async fn parse_urls(urls_str: &str) -> Result<Vec<String>, url::ParseError>
x => part.push(x.expect("REASON")),
}
} //end loop
+ for relay in collected {
+ print!("{}, ", format!("relay.clone()={}", relay.clone()));
+
+ }
}
Ok(urls)
}

-pub async fn print_watch_list() -> Result<Vec<String>, url::ParseError> {
+pub async fn print_watch_list() -> Result<Vec<String>> {
let vec_relay_list = parse_urls(&get_relays_public().unwrap().as_str()).await;
vec_relay_list //.expect("REASON")
}
-pub async fn get_watch_list() -> Result<Vec<String>, url::ParseError> {
+pub async fn get_watch_list() -> Result<Vec<String>> {
let vec_relay_list = parse_urls(&get_relays_public().unwrap().as_str()).await;
vec_relay_list //.expect("REASON")
}
+pub async fn get_watch_list_json() -> Result<Vec<String>> {
+ let vec_relay_list = parse_json(&get_relays_public().unwrap().as_str()).await;
+ vec_relay_list //.expect("REASON")
+}
Author Public Key
npub109t5lgu92ecqghn5eswj2mtagwchz3mj5cdetcdk8hwuhrqhaz7q6p6na7