260702_204657
This commit is contained in:
parent
3bf6e7b828
commit
d9b4a6f6cf
63
moira_db.go
63
moira_db.go
@ -39,6 +39,21 @@ type Film struct{
|
||||
//var db_film []Film
|
||||
|
||||
|
||||
func findURL_in_msg(in_msg string) (_ string,err error){
|
||||
i := strings.Index(in_msg, "http")
|
||||
if(i == -1){
|
||||
err = errors.New("No URL found in: " + in_msg)
|
||||
return
|
||||
}
|
||||
|
||||
j := strings.Index(in_msg[i:], " ")
|
||||
if(j == -1){
|
||||
j = len(in_msg)-i
|
||||
}
|
||||
|
||||
return in_msg[i:i+j], nil
|
||||
}
|
||||
|
||||
func resolve_redirs(in_url string) (string,error){
|
||||
resp, err := client.Get(in_url)
|
||||
if(err != nil){
|
||||
@ -216,6 +231,24 @@ func templates_register(template_renders map[string]string){
|
||||
}
|
||||
}
|
||||
|
||||
func hdlr_film_parseMsg(resp http.ResponseWriter, req *http.Request){
|
||||
fmt.Println("[srv] util", req.URL.Path)
|
||||
|
||||
req_text, err := io.ReadAll(req.Body)
|
||||
if err != nil{ return }
|
||||
fmt.Println(string(req_text))
|
||||
|
||||
t_url, _ := findURL_in_msg(string(req_text))
|
||||
fmt.Println(t_url)
|
||||
t_url_noRed, _ := resolve_redirs(t_url)
|
||||
fmt.Println(t_url_noRed)
|
||||
t_film, _ := fetch_filmInfo(t_url_noRed)
|
||||
t_json, _ := json.MarshalIndent(t_film, "", " ")
|
||||
fmt.Printf("%+v\n", string(t_json))
|
||||
|
||||
http.Redirect(resp, req, "/film/view/"+t_film.Title_orig, http.StatusFound)
|
||||
}
|
||||
|
||||
func main(){
|
||||
//t_film, _ := fetch_filmInfo("https://www.filmweb.pl/film/Spirited+Away%3A+W+krainie+Bog%C3%B3w-2001-33288")
|
||||
//t_film, _ := fetch_filmInfo("https://www.filmweb.pl/film/Pulp+Fiction-1994-1039")
|
||||
@ -223,24 +256,40 @@ func main(){
|
||||
//t_film, _ := fetch_filmInfo("https://www.imdb.com/title/tt0245429/?ref_=nv_sr_srsg_0_tt_8_nm_0_in_0_q_spirited")
|
||||
//t_film, _ := fetch_filmInfo("https://www.imdb.com/title/tt0110912/")
|
||||
//t_film, _ := fetch_filmInfo("https://www.imdb.com/title/tt8814476/")
|
||||
t_film, _ := fetch_filmInfo("https://www.imdb.com/title/tt0095456/?ref_=nv_sr_srsg_0_tt_1_nm_0_in_0_q_kl%C4%85twa%20doliny%20w%C4%99%C5%BC")
|
||||
t_json, _ := json.MarshalIndent(t_film, "", " ")
|
||||
fmt.Printf("%+v\n", string(t_json))
|
||||
|
||||
//t_url_noRed, _ := resolve_redirs("https://www.imdb.com/title/tt0095456/?ref_=nv_sr_srsg_0_tt_1_nm_0_in_0_q_kl%C4%85twa%20doliny%20w%C4%99%C5%BC")
|
||||
//t_url_noRed, _ := resolve_redirs("https://share.google/EsMXhLYol3eQTKcQH")
|
||||
|
||||
//t_url, _ := findURL_in_msg("https://share.google/EsMXhLYol3eQTKcQH")
|
||||
//t_url, _ := findURL_in_msg("abcabc https://share.google/EsMXhLYol3eQTKcQH abcabc")
|
||||
//t_url, _ := findURL_in_msg("abcabchttps://share.google/EsMXhLYol3eQTKcQH abcabc")
|
||||
//t_url, _ := findURL_in_msg("abcabchttps://share.google/EsMXhLYol3eQTKcQH")
|
||||
//t_url, _ := findURL_in_msg("Fantastyczny Pan Lis (2009) - Filmweb https://share.google/EsMXhLYol3eQTKcQH")
|
||||
//fmt.Println(t_url)
|
||||
|
||||
//t_url_noRed, _ := resolve_redirs(t_url)
|
||||
//fmt.Println(t_url_noRed)
|
||||
//t_film, _ := fetch_filmInfo(t_url_noRed)
|
||||
//t_json, _ := json.MarshalIndent(t_film, "", " ")
|
||||
//fmt.Printf("%+v\n", string(t_json))
|
||||
|
||||
template_renders := map[string]string {
|
||||
"/": "index.html",
|
||||
"/film/view/": "index.html",
|
||||
"/film/edit/": "index.html",
|
||||
"/list/view/": "index.html",
|
||||
"/list/edit/": "index.html",
|
||||
"/group/view/": "index.html",
|
||||
"/group/edit/": "index.html",
|
||||
//"/list/view/": "index.html",
|
||||
//"/list/edit/": "index.html",
|
||||
//"/group/view/": "index.html",
|
||||
//"/group/edit/": "index.html",
|
||||
}
|
||||
|
||||
templates_register(template_renders)
|
||||
http.HandleFunc("/", hdlr_root(template_renders))
|
||||
|
||||
|
||||
http.HandleFunc("/film/parse_msg/", hdlr_film_parseMsg)
|
||||
|
||||
|
||||
//fmt.Println("Welcome to moira_db!");
|
||||
log.Fatal(http.ListenAndServe(":8000", nil))
|
||||
}
|
||||
|
||||
19
website/static/utils/parse_msg.html
Normal file
19
website/static/utils/parse_msg.html
Normal file
@ -0,0 +1,19 @@
|
||||
<input type="text" id="inp_text">
|
||||
<input type="button" id="inp_bttn" value="Send">
|
||||
|
||||
<script>
|
||||
window.onload = () => {
|
||||
document.getElementById("inp_bttn").addEventListener("click", async ()=>{
|
||||
fetch("/film/parse_msg/", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "plain/text"
|
||||
},
|
||||
body: document.getElementById("inp_text").value
|
||||
})
|
||||
.then(resp => {
|
||||
window.location.href = resp.url;
|
||||
});
|
||||
});
|
||||
};
|
||||
</script>
|
||||
Loading…
x
Reference in New Issue
Block a user