gemini_ai/content_gen/
rag_search.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use std::{
    io::{BufRead, BufReader, Read, Write},
    net::TcpStream,
    panic,
};

use native_tls::TlsConnector;
use regex::Regex;

pub fn search(source: &str) -> String {
    let domain = domain(source);
    let stream = format!("{}:443", domain);
    let tls = TlsConnector::new().unwrap();
    let stream = TcpStream::connect(stream).unwrap();
    let mut client = tls.connect(&domain, stream).unwrap();

    let get = format!("GET {} HTTP/1.1\r\n\r\n", source);
    client.write_all(get.as_bytes());
    client.flush();

    let mut reader = BufReader::new(client);
    // for lines in reader.lines() {
    //     println!("{}", lines.unwrap());
    // }
    // let mut source = String::new();
    let mut body = String::new();
    loop {
        let mut line = String::new();
        reader.read_line(&mut line);
        // println!("{}", line);

        let size = usize::from_str_radix(&line.trim(), 16).unwrap();
        println!("{}", size);
        // if size == 0 {
        //     break;
        // }

        // let mut esponse = vec![0; size];
        // reader.read_exact(&mut esponse);
        // let response = String::from_utf8_lossy(&esponse);
        // body.push_str(&response);
        // // println!("{}", response);

        // let mut trail = vec![0; 2];
        // reader.read_exact(&mut trail);
    }
    // println!("{}", source);
    String::new()
}

// https://en.wikipedia.org/wiki/Mark_Zuckerberg
pub fn domain(source: &str) -> String {
    match source.starts_with("https") {
        true => {
            let start = source.find("https://").unwrap() + "https://".len();
            let billionaire = &source[start..];
            let end = billionaire.find("/").unwrap();
            let domain = &billionaire[..end];
            domain.to_string()
        }
        false => {
            panic!("provide url starts with https")
        }
    }
}