Changing from js to golang
This commit is contained in:
BIN
cmd/web/svevijesti
Normal file
BIN
cmd/web/svevijesti
Normal file
Binary file not shown.
@@ -2,12 +2,13 @@ package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
_ "github.com/lib/pq"
|
||||
"gitlab.com/kbr4/svevijesti/internal/model"
|
||||
"html/template"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
"gitlab.com/kbr4/svevijesti/internal/model"
|
||||
)
|
||||
|
||||
func InsertArticle(store *Store, article model.ScrapedArticle) (err error) {
|
||||
@@ -186,3 +187,48 @@ func PreviousAndNextArticleUrlByID(store *Store, ID int) (nextUrl string, previo
|
||||
|
||||
return nextResult, previousResult, nil
|
||||
}
|
||||
|
||||
func ArticleByCategory(store *Store, day time.Time) (cateogry []model.DisplayArticle, err error) {
|
||||
|
||||
result := []model.DisplayArticle{}
|
||||
query, err := store.Prepare(`select id,title,content,slug,created_at,source_id,category from articles where created_at > $1 and created_at < $2 and LENGTH(content) > 10 order by id desc;`)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
defer query.Close()
|
||||
|
||||
tomorow := day.AddDate(0, 0, 1)
|
||||
todayDate := day.Format("2024-01-26")
|
||||
tomorrowDate := tomorow.Format("2024:01:26")
|
||||
|
||||
rows, err := query.Query(todayDate, tomorrowDate)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
r := model.DisplayArticle{}
|
||||
err = rows.Scan(&r.ID, &r.Title, &r.Content, &r.Slug, &r.CreatedAt, &r.OriginalUrl, &r.SourceId, &r.CreatedAt, &r.Category)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
ago := time.Now().Sub(r.CreatedAt)
|
||||
hours := ago.Hours()
|
||||
|
||||
if hours < 1 {
|
||||
r.FormatedCreatedAt = fmt.Sprintf("Prije %d sati.", int(math.Floor(ago.Minutes())))
|
||||
} else if hours > 24 {
|
||||
r.FormatedCreatedAt = r.CreatedAt.Format("28.01.2024. 01:03:05")
|
||||
} else {
|
||||
r.FormatedCreatedAt = fmt.Sprintf("Prije %d sati.", int(math.Floor(ago.Minutes())))
|
||||
}
|
||||
|
||||
r.SourceName = model.SourceName(r.SourceId)
|
||||
|
||||
result = append(result, r)
|
||||
}
|
||||
return result, nil
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ type DisplayArticle struct {
|
||||
CreatedAt time.Time
|
||||
FormatedCreatedAt string
|
||||
SourceName string
|
||||
Category string
|
||||
}
|
||||
|
||||
const (
|
||||
|
||||
@@ -2,11 +2,12 @@ package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gorilla/mux"
|
||||
"gitlab.com/kbr4/svevijesti/internal/database"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"gitlab.com/kbr4/svevijesti/internal/database"
|
||||
)
|
||||
|
||||
func rootHandler(wr http.ResponseWriter, req *http.Request) {
|
||||
|
||||
34
internal/server/category.go
Normal file
34
internal/server/category.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"gitlab.com/kbr4/svevijesti/internal/database"
|
||||
"gitlab.com/kbr4/svevijesti/internal/model"
|
||||
)
|
||||
|
||||
func categoryHandler(wr http.ResponseWriter, r *http.Request) {
|
||||
|
||||
store, err := database.Connect()
|
||||
|
||||
if err != nil {
|
||||
http.Error(wr, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
articles, err := database.ArticleByCategory(store, time.Now())
|
||||
|
||||
articlesByCategory := make(map[string][]model.DisplayArticle)
|
||||
|
||||
for _, article := range articles {
|
||||
articlesByCategory[article.Category] = append(articlesByCategory[article.Category], article)
|
||||
}
|
||||
|
||||
for category, articles := range articlesByCategory {
|
||||
data := map[string]interface{}{"Category": category, "Articles": articles}
|
||||
err := templates.ExecuteTemplate(wr, "categoryHTML", data)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,12 @@ package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gorilla/mux"
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
var tPath = "./web/tpl/"
|
||||
@@ -42,5 +43,7 @@ func CreateRoutes() *mux.Router {
|
||||
r.HandleFunc("/dan/{date}", dailyArticlesHandler)
|
||||
r.HandleFunc("/{id:[0-9]+}/{slug}", articleHandler)
|
||||
r.HandleFunc("/", rootHandler)
|
||||
r.HandleFunc("/weather", WeatherHandler)
|
||||
r.HandleFunc("/{category}", categoryHandler)
|
||||
return r
|
||||
}
|
||||
|
||||
97
internal/server/weather.go
Normal file
97
internal/server/weather.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const apiKey = "abb35e21bdcbad6d1b00141a2b25cf5a"
|
||||
|
||||
type WeatherData struct {
|
||||
Coord struct {
|
||||
Lat float64 `json:"lat"`
|
||||
Lon float64 `json:"lon"`
|
||||
} `json:"coord"`
|
||||
Weather []struct {
|
||||
Description string `json:"description"`
|
||||
Icon string `json:"icon"`
|
||||
} `json:"weather"`
|
||||
Main struct {
|
||||
Temp float64 `json:"temp"`
|
||||
FellsLike float64 `json:"fells_like"`
|
||||
Preassure int `json:"preassure"`
|
||||
Humidity int `json:"humidity"`
|
||||
TempMin float64 `json:"temp_min"`
|
||||
TempMax float64 `json:"temp_max"`
|
||||
} `json:"main"`
|
||||
Wind struct {
|
||||
Speed float64 `json:"speed"`
|
||||
Deg float64 `json:"deg"`
|
||||
} `json:"wind"`
|
||||
Clouds struct {
|
||||
All int `json:"all"`
|
||||
} `json:"clouds"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func getWeather(city string) (WeatherData, error) {
|
||||
url := fmt.Sprintf("http://api.openweathermap.org/data/2.5/weather?q=%s&appid=%s&units=metric&lang=hr", city, apiKey)
|
||||
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return WeatherData{}, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return WeatherData{}, err
|
||||
}
|
||||
var weatherData WeatherData
|
||||
err = json.Unmarshal(body, &weatherData)
|
||||
if err != nil {
|
||||
return WeatherData{}, err
|
||||
}
|
||||
return weatherData, nil
|
||||
}
|
||||
|
||||
func WeatherHandler(w http.ResponseWriter, r *http.Request) {
|
||||
cities := []string{"Sarajevo", "Banja Luka", "Zenica", "Tuzla", "Mostar"}
|
||||
|
||||
var weatherInfo []WeatherData
|
||||
for _, city := range cities {
|
||||
data, err := getWeather(city)
|
||||
if err != nil {
|
||||
fmt.Printf("Error fetching weather for %s: %v\n", city, err)
|
||||
continue
|
||||
}
|
||||
weatherInfo = append(weatherInfo, data)
|
||||
}
|
||||
|
||||
title := "Vremenska Prognoza"
|
||||
data := map[string]interface{}{
|
||||
"title": title,
|
||||
"weatherInfo": weatherInfo,
|
||||
}
|
||||
|
||||
err := templates.ExecuteTemplate(w, "fullweatherHTML", data)
|
||||
if err != nil {
|
||||
fmt.Println("Error executing template:", err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
}
|
||||
for _, info := range weatherInfo {
|
||||
widgetData := map[string]interface{}{
|
||||
"Temperature": info.Main.Temp,
|
||||
"City": info.Name,
|
||||
}
|
||||
err := templates.ExecuteTemplate(w, "weatherwidgetHTML", widgetData)
|
||||
if err != nil {
|
||||
fmt.Println("Error executing template:", err)
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,6 +2,6 @@ OPENAI_API_KEY = "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"
|
||||
|
||||
DB_HOST =localhost
|
||||
DB_PORT =5432
|
||||
DB_USER =postgres
|
||||
DB_USER =svevijesti
|
||||
DB_PASSWORD =salmonela pljusti 221 hamo
|
||||
DB_NAME =svevijestiweb
|
||||
BIN
pyth/__pycache__/db_management.cpython-310.pyc
Normal file
BIN
pyth/__pycache__/db_management.cpython-310.pyc
Normal file
Binary file not shown.
BIN
pyth/__pycache__/get_articles.cpython-310.pyc
Normal file
BIN
pyth/__pycache__/get_articles.cpython-310.pyc
Normal file
Binary file not shown.
BIN
pyth/__pycache__/publishing_finals.cpython-310.pyc
Normal file
BIN
pyth/__pycache__/publishing_finals.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
BIN
pyth/__pycache__/tttt.cpython-310.pyc
Normal file
BIN
pyth/__pycache__/tttt.cpython-310.pyc
Normal file
Binary file not shown.
Binary file not shown.
241
pyth/articles.py
241
pyth/articles.py
@@ -1,241 +0,0 @@
|
||||
import psycopg2
|
||||
import numpy as np
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
from openai import OpenAI
|
||||
from langchain.embeddings import OpenAIEmbeddings
|
||||
from vectData import get_specific_data, modify_similar_data, insert_data, preparing_articles, calculate_cosine_similarity,get_titles_links_embeddings
|
||||
from scrapingsingle import num_tokens_from_string, slice_text_at_2k_tokens
|
||||
import json
|
||||
from json_repair import repair_json
|
||||
|
||||
load_dotenv()
|
||||
|
||||
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
||||
client = OpenAI()
|
||||
embeddings = OpenAIEmbeddings()
|
||||
|
||||
print(f"Checking for similar!")
|
||||
|
||||
def find_and_group_similar_articles(eps=0.5, min_samples=2, threshold=0.95):
|
||||
try:
|
||||
titles, links, embeddings = get_titles_links_embeddings()
|
||||
|
||||
processed_articles = set()
|
||||
grouped_similar_articles = []
|
||||
|
||||
for i, (title1, link1, embedding1) in enumerate(zip(titles, links, embeddings)):
|
||||
if (title1, link1) not in processed_articles:
|
||||
processed_articles.add((title1, link1))
|
||||
group = [(title1, link1)]
|
||||
|
||||
for j, (title2, link2, embedding2) in enumerate(zip(titles, links, embeddings)):
|
||||
if i != j and (title2, link2) not in processed_articles:
|
||||
similarity = calculate_cosine_similarity(embedding1, embedding2)
|
||||
|
||||
if similarity > threshold:
|
||||
processed_articles.add((title2, link2))
|
||||
group.append((title2, link2))
|
||||
|
||||
grouped_similar_articles.append(group)
|
||||
|
||||
return grouped_similar_articles
|
||||
|
||||
except psycopg2.Error as e:
|
||||
print(f"Error: {e}")
|
||||
return []
|
||||
|
||||
def processing_similar():
|
||||
grouped_similar_articles_result = find_and_group_similar_articles()
|
||||
|
||||
if grouped_similar_articles_result:
|
||||
for group in grouped_similar_articles_result:
|
||||
articles = []
|
||||
|
||||
if len(group) > 1:
|
||||
for article_tuple in group:
|
||||
if len(article_tuple) >= 2:
|
||||
title, link = article_tuple[:2]
|
||||
article = [title, link]
|
||||
articles.append(article)
|
||||
l = len(articles)
|
||||
|
||||
if l == 2:
|
||||
a_one = articles[0][0]
|
||||
a_two = articles[1][0]
|
||||
|
||||
get_one = get_specific_data(a_one)
|
||||
get_two = get_specific_data(a_two)
|
||||
|
||||
text1 = get_one[0][1]
|
||||
text2 = get_two[0][1]
|
||||
link1 = get_one[0][2]
|
||||
link2 = get_two[0][2]
|
||||
if link1 != link2:
|
||||
link = f"{link1}, {link2}"
|
||||
else:
|
||||
link = link1
|
||||
|
||||
ftoks = num_tokens_from_string(text1)
|
||||
stoks = num_tokens_from_string(text2)
|
||||
tokens = ftoks + stoks
|
||||
|
||||
similar_d = f"C: {a_one}, {a_two}"
|
||||
|
||||
modify_similar_data(similar_d, a_one)
|
||||
preparing_articles(False, a_one)
|
||||
|
||||
modify_similar_data(similar_d, a_two)
|
||||
preparing_articles(False, a_two)
|
||||
|
||||
if tokens > 2000:
|
||||
combined_text = f"{text1} {text2}"
|
||||
combined_text = slice_text_at_2k_tokens(combined_text)
|
||||
user_message = rf"Here is text {combined_text}, combined from 3 sources, filter text, and make news content, return as JSON only with single 'content' field"
|
||||
else:
|
||||
user_message = rf"Here are 2 texts {text1} {text2}, combine the following texts into a cohesive news remove any non-news related to both texts and provide the cleaned data as a JSON only with single 'content' field."
|
||||
|
||||
if l == 3:
|
||||
a_one = articles[0][0]
|
||||
a_two = articles[1][0]
|
||||
a_three = articles[2][0]
|
||||
|
||||
get_one = get_specific_data(a_one)
|
||||
get_two = get_specific_data(a_two)
|
||||
get_three = get_specific_data(a_three)
|
||||
|
||||
text1 = get_one[0][1]
|
||||
text2 = get_two[0][1]
|
||||
text3 = get_three[0][1]
|
||||
link1 = get_one[0][2]
|
||||
link2 = get_two[0][2]
|
||||
link3 = get_three[0][2]
|
||||
if link1 != link2:
|
||||
if link2 != link3:
|
||||
link = f"{link1}, {link2}, {link3}"
|
||||
else:
|
||||
link = f"{link1}, {link2}"
|
||||
else:
|
||||
if link2 != link3:
|
||||
link = f"{link1}, {link3}"
|
||||
else:
|
||||
link = link1
|
||||
ftoks = num_tokens_from_string(text1)
|
||||
stoks = num_tokens_from_string(text2)
|
||||
ttoks = num_tokens_from_string(text3)
|
||||
tokens = ftoks + stoks + ttoks
|
||||
|
||||
similar_d = f"C: {a_one}, {a_two}, {a_three}"
|
||||
modify_similar_data(similar_d, a_one)
|
||||
preparing_articles(False, a_one)
|
||||
|
||||
modify_similar_data(similar_d, a_two)
|
||||
preparing_articles(False, a_two)
|
||||
|
||||
modify_similar_data(similar_d, a_three)
|
||||
preparing_articles(False, a_three)
|
||||
|
||||
if tokens > 2000:
|
||||
combined_text = f"{text1} {text2} {text3}"
|
||||
combined_text = slice_text_at_2k_tokens(combined_text)
|
||||
user_message = rf"Here is text {combined_text}, combined from 3 sources, filter text, and make news content, return as JSON only with single 'content' field"
|
||||
else:
|
||||
user_message = rf"Here are 3 texts {text1} {text2} and {text3}, combine the following texts into a cohesive news remove any non-news related to both texts and provide the cleaned data as a JSON only with single 'content' field."
|
||||
if l == 4:
|
||||
a_one = articles[0][0]
|
||||
a_two = articles[1][0]
|
||||
a_three = articles[2][0]
|
||||
a_four = articles[3][0]
|
||||
|
||||
get_one = get_specific_data(a_one)
|
||||
get_two = get_specific_data(a_two)
|
||||
get_three = get_specific_data(a_three)
|
||||
get_four = get_specific_data(a_four)
|
||||
|
||||
text1 = get_one[0][1]
|
||||
text2 = get_two[0][1]
|
||||
text3 = get_three[0][1]
|
||||
text4 = get_four[0][1]
|
||||
link1 = get_one[0][2]
|
||||
link2 = get_two[0][2]
|
||||
link3 = get_three[0][2]
|
||||
link4 = get_four[0][2]
|
||||
|
||||
if link1 != link2:
|
||||
if link2 != link3:
|
||||
if link3 != link4:
|
||||
link = f"{link1}, {link2}, {link3}, {link4}"
|
||||
else:
|
||||
link = f"{link1}, {link2}, {link3}"
|
||||
else:
|
||||
if link3 != link4:
|
||||
link = f"{link1}, {link2}, {link4}"
|
||||
else:
|
||||
link = f"{link1}, {link2}"
|
||||
else:
|
||||
if link2 != link3:
|
||||
if link3 != link4:
|
||||
link = f"{link1}, {link3}, {link4}"
|
||||
else:
|
||||
link = f"{link1}, {link3}"
|
||||
else:
|
||||
if link3 != link4:
|
||||
link = f"{link1}, {link4}"
|
||||
else:
|
||||
link = link1
|
||||
|
||||
ftoks = num_tokens_from_string(text1)
|
||||
stoks = num_tokens_from_string(text2)
|
||||
ttoks = num_tokens_from_string(text3)
|
||||
frtoks = num_tokens_from_string(text4)
|
||||
|
||||
tokens = ftoks + stoks + ttoks + frtoks
|
||||
|
||||
similar_d = f"C: {a_one}, {a_two}, {a_three}, {a_four}"
|
||||
modify_similar_data(similar_d, a_one)
|
||||
preparing_articles(False, a_one)
|
||||
|
||||
modify_similar_data(similar_d, a_two)
|
||||
preparing_articles(False, a_two)
|
||||
|
||||
modify_similar_data(similar_d, a_three)
|
||||
preparing_articles(False, a_three)
|
||||
|
||||
modify_similar_data(similar_d, a_four)
|
||||
preparing_articles(False, a_four)
|
||||
|
||||
if tokens > 2000:
|
||||
combined_text = f"{text1} {text2} {text3} {text4}"
|
||||
combined_text = slice_text_at_2k_tokens(combined_text)
|
||||
user_message = rf"Here is text {combined_text}, combined from 4 sources, filter text, and make news content, return as JSON only with a single 'content' field"
|
||||
else:
|
||||
user_message = rf"Here are 4 texts {text1} {text2} {text3} and {text4}, combine the following texts into a cohesive news, remove any non-news related to all texts, and provide the cleaned data as a JSON only with a single 'content' field."
|
||||
try:
|
||||
completion = client.chat.completions.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": "Data analytic, Journalist and News reporter"},
|
||||
{"role": "user", "content": user_message}
|
||||
])
|
||||
generated_text = completion.choices[0].message.content
|
||||
|
||||
generated_text = repair_json(generated_text)
|
||||
|
||||
response_data = json.loads(generated_text)
|
||||
title = a_one
|
||||
text = response_data["content"]
|
||||
vector = embeddings.embed_query(generated_text)
|
||||
|
||||
insert_data(title, text, link, vector, similar_d)
|
||||
print(f"Inserting combined: {title}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
print(a_one)
|
||||
continue
|
||||
else:
|
||||
print("Done!.")
|
||||
else:
|
||||
print("No similar articles found.")
|
||||
if __name__=="__main__":
|
||||
processing_similar()
|
||||
122
pyth/checking_similar.py
Normal file
122
pyth/checking_similar.py
Normal file
@@ -0,0 +1,122 @@
|
||||
import psycopg2
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
from openai import OpenAI
|
||||
from langchain_openai import OpenAIEmbeddings
|
||||
from db_management import get_specific_data, modify_similar_data, insert_data, preparing_articles, calculate_cosine_similarity, get_titles_links_embeddings
|
||||
from get_articles import slice_text_at_2k_tokens
|
||||
import json
|
||||
from json_repair import repair_json
|
||||
from publishing_finals import publish_articles
|
||||
|
||||
load_dotenv()
|
||||
|
||||
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
||||
client = OpenAI()
|
||||
embeddings = OpenAIEmbeddings()
|
||||
|
||||
print("Checking for similar!")
|
||||
|
||||
|
||||
def find_and_group_similar_articles(eps=0.5, min_samples=2, threshold=0.95):
|
||||
try:
|
||||
titles, links, embeddings = get_titles_links_embeddings()
|
||||
|
||||
processed_articles = set()
|
||||
grouped_similar_articles = []
|
||||
|
||||
for i, (title1, link1, embedding1) in enumerate(zip(titles, links, embeddings)):
|
||||
if (title1, link1) not in processed_articles:
|
||||
processed_articles.add((title1, link1))
|
||||
group = [(title1, link1)]
|
||||
|
||||
for j, (title2, link2, embedding2) in enumerate(zip(titles, links, embeddings)):
|
||||
if i != j and (title2, link2) not in processed_articles:
|
||||
similarity = calculate_cosine_similarity(embedding1, embedding2)
|
||||
|
||||
if similarity > threshold:
|
||||
if link1 != link2:
|
||||
processed_articles.add((title2, link2))
|
||||
group.append((title2, link2, embedding2))
|
||||
|
||||
grouped_similar_articles.append(group)
|
||||
return grouped_similar_articles
|
||||
|
||||
except psycopg2.Error as e:
|
||||
print(f"Error: {e}")
|
||||
return []
|
||||
|
||||
|
||||
def processing_articles(articles):
|
||||
unique_links = set()
|
||||
|
||||
for article in articles:
|
||||
a_title, a_link = article[:2]
|
||||
get_data = get_specific_data(a_title)
|
||||
text = get_data[0][1]
|
||||
link = a_link
|
||||
|
||||
modify_similar_data(f"C: {', '.join(art[0] for art in articles)}", a_title)
|
||||
preparing_articles(False, a_title)
|
||||
|
||||
if link not in unique_links:
|
||||
unique_links.add(link)
|
||||
|
||||
combined_text = ' '.join(get_specific_data(art[0])[0][1] for art in articles)
|
||||
combined_text = slice_text_at_2k_tokens(combined_text)
|
||||
|
||||
if len(unique_links) == 1:
|
||||
link = next(iter(unique_links))
|
||||
else:
|
||||
link = ', '.join(unique_links)
|
||||
return combined_text, link
|
||||
|
||||
|
||||
def processing_similar():
|
||||
grouped_similar_articles_result = find_and_group_similar_articles()
|
||||
|
||||
if grouped_similar_articles_result:
|
||||
for group in grouped_similar_articles_result:
|
||||
articles = group
|
||||
|
||||
if len(articles) > 1:
|
||||
combined_text, link = processing_articles(articles)
|
||||
user_message = (
|
||||
rf"Here are {len(articles)} texts {combined_text}, combine the following texts into a cohesive news, "
|
||||
rf"remove any non-news related to all texts, and provide the cleaned data on Bosnian languageas and return as JSON only with a single 'content' field."
|
||||
)
|
||||
|
||||
try:
|
||||
completion = client.chat.completions.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": "Data analytic, Journalist and News reporter"},
|
||||
{"role": "user", "content": user_message}
|
||||
])
|
||||
generated_text = repair_json(completion.choices[0].message.content)
|
||||
|
||||
response_data = json.loads(generated_text)
|
||||
title = articles[0][0]
|
||||
text = response_data["content"]
|
||||
vector = embeddings.embed_query(generated_text)
|
||||
tmpCategory = get_specific_data(title)
|
||||
category = tmpCategory[0][5]
|
||||
|
||||
|
||||
|
||||
insert_data(title, text, link, vector, f"C: {', '.join(art[0] for art in articles)}", category)
|
||||
print(f"Inserting combined: {title} and Category: {category}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
print(articles[0][0])
|
||||
continue
|
||||
else:
|
||||
print("Done!.")
|
||||
else:
|
||||
print("No similar articles found.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
processing_similar()
|
||||
publish_articles()
|
||||
@@ -68,7 +68,7 @@ def is_similar_data(title, text, link, embedding, threshold=0.98):
|
||||
|
||||
def get_similar():
|
||||
cursor = conn.cursor()
|
||||
query = '''SELECT title,similar_d FROM vectorsvevijesti WHERE similar_d NOT IN ('NO', 'SOURCE')'''
|
||||
query = '''SELECT title, link, similar_d FROM vectorsvevijesti WHERE similar_d NOT IN ('NO', 'SOURCE')'''
|
||||
cursor.execute(query)
|
||||
similar_data = cursor.fetchall()
|
||||
cursor.close()
|
||||
@@ -87,18 +87,23 @@ def get_titles_links_embeddings():
|
||||
return titles, links, embeddings
|
||||
|
||||
|
||||
def insert_data(title, text, link, embedding, similar_d):
|
||||
def insert_data(title, text, link, embedding, similar_d,category):
|
||||
c_time = datetime.now()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
INSERT INTO vectorsvevijesti (title, text, link, embedding, similar_d, time, ready)
|
||||
VALUES (%s, %s, %s, %s, %s ,%s ,%s);
|
||||
''', (title, text, link, embedding , similar_d, c_time, True))
|
||||
INSERT INTO vectorsvevijesti (title, text, link, embedding, similar_d, time, ready, category)
|
||||
VALUES (%s, %s, %s, %s, %s ,%s ,%s ,%s);
|
||||
''', (title, text, link, embedding , similar_d, c_time, True , category))
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
def get_data():
|
||||
def insert_final(title,text,slug,link,source_id, category):
|
||||
with conn.cursor() as cursor:
|
||||
cursor.execute('''INSERT INTO articles (title, content, slug, original_url, source_id, category)
|
||||
VALUES (%s, %s, %s, %s, %s, %s)ON CONFLICT (original_url) DO NOTHING;''',(title , text, slug, link, source_id, category))
|
||||
conn.commit()
|
||||
|
||||
def get_data():
|
||||
cursor = conn.cursor()
|
||||
query = '''SELECT title,text,link FROM vectorsvevijesti;'''
|
||||
cursor.execute(query)
|
||||
@@ -108,7 +113,7 @@ def get_data():
|
||||
|
||||
def get_ready_data():
|
||||
cursor = conn.cursor()
|
||||
query = '''SELECT title, text, link, ready FROM vectorsvevijesti WHERE ready = %s;'''
|
||||
query = '''SELECT title, text, link, time, similar_d, category FROM vectorsvevijesti WHERE ready = %s;'''
|
||||
cursor.execute(query, ('True',))
|
||||
data = cursor.fetchall()
|
||||
cursor.close()
|
||||
@@ -122,14 +127,12 @@ def get_source_data():
|
||||
cursor.close()
|
||||
return data
|
||||
|
||||
|
||||
def modify_similar_data(new_value ,title):
|
||||
cursor = conn.cursor()
|
||||
query = '''UPDATE vectorsvevijesti SET similar_d = %s WHERE title = %s '''
|
||||
cursor.execute(query, (new_value, title))
|
||||
conn.commit()
|
||||
|
||||
|
||||
def preparing_articles(new_value ,title):
|
||||
cursor = conn.cursor()
|
||||
query = '''UPDATE vectorsvevijesti SET ready = %s WHERE title = %s '''
|
||||
@@ -138,13 +141,12 @@ def preparing_articles(new_value ,title):
|
||||
|
||||
def get_specific_data(title):
|
||||
cursor = conn.cursor()
|
||||
query = '''SELECT title, text, link, similar_d, embedding, ready FROM vectorsvevijesti WHERE title = %s'''
|
||||
query = '''SELECT title, text, link, similar_d, embedding, category, ready FROM vectorsvevijesti WHERE title = %s'''
|
||||
cursor.execute(query, (title,))
|
||||
specific_post = cursor.fetchall()
|
||||
cursor.close()
|
||||
return specific_post
|
||||
|
||||
|
||||
def get_all_links():
|
||||
cursor = conn.cursor()
|
||||
query = '''SELECT link FROM vectorsvevijesti'''
|
||||
@@ -153,6 +155,14 @@ def get_all_links():
|
||||
cursor.close()
|
||||
return db_links
|
||||
|
||||
def get_existing_titles():
|
||||
cursor = conn.cursor()
|
||||
query = '''SELECT title, original_url FROM articles'''
|
||||
cursor.execute(query)
|
||||
db_links = {link[0] for link in cursor.fetchall()}
|
||||
cursor.close()
|
||||
return db_links
|
||||
|
||||
def delete_specific(title):
|
||||
cursor = conn.cursor()
|
||||
query = '''DELETE FROM vectorsvevijesti WHERE title = %s'''
|
||||
@@ -192,4 +202,48 @@ def create_db():
|
||||
''')
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
def create_db():
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("CREATE EXTENSION IF NOT EXISTS vector")
|
||||
register_vector(conn)
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS vectorsvevijesti (
|
||||
id bigserial PRIMARY KEY,
|
||||
title VARCHAR,
|
||||
text VARCHAR,
|
||||
link VARCHAR,
|
||||
embedding vector(1536),
|
||||
similar_d VARCHAR,
|
||||
time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
ready BOOLEAN,
|
||||
category VARCHAR
|
||||
);
|
||||
''')
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
def create_ar_table():
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS "articles" (
|
||||
"id" bigserial PRIMARY KEY,
|
||||
"title" text NOT NULL UNIQUE,
|
||||
"content" text NOT NULL,
|
||||
"slug" text NOT NULL UNIQUE,
|
||||
"created_at" timestamptz DEFAULT NOW() NOT NULL,
|
||||
"original_url" text NOT NULL UNIQUE,
|
||||
"source_id" int NOT NULL,
|
||||
"category" VARCHAR
|
||||
|
||||
);
|
||||
''')
|
||||
conn.commit()
|
||||
cursor.close()
|
||||
|
||||
import psycopg2
|
||||
from psycopg2 import sql
|
||||
|
||||
|
||||
create_db()
|
||||
create_ar_table()
|
||||
2
pyth/delete_db.py
Normal file
2
pyth/delete_db.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from db_management import delete_tables
|
||||
delete_tables()
|
||||
@@ -3,8 +3,8 @@ import requests
|
||||
from urllib.parse import urljoin
|
||||
from openai import OpenAI
|
||||
import os
|
||||
from langchain.embeddings import OpenAIEmbeddings
|
||||
from vectData import (insert_data ,is_similar_data ,get_all_links,cleansing )
|
||||
from langchain_openai import OpenAIEmbeddings
|
||||
from db_management import (insert_data ,is_similar_data ,get_all_links,cleansing )
|
||||
import json
|
||||
from dotenv import load_dotenv
|
||||
import tiktoken
|
||||
@@ -18,7 +18,7 @@ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
||||
client = OpenAI()
|
||||
embeddings = OpenAIEmbeddings()
|
||||
|
||||
dlinks = ['https://klix.ba', 'https://srpskainfo.com', 'https://bljesak.info']
|
||||
dlinks = ['https://klix.ba', 'https://srpskainfo.com', 'https://bljesak.info','https://www.index.hr', 'https://avaz.ba', 'https://www.telegraf.rs', 'https://www.blic.rs', 'https://www.vijesti.me','https://dnevnik.hr','https://24sata.hr']
|
||||
headers = {'User-Agent': 'Mozilla/5.0 (Linux; Android 5.1.1; SM-G928X Build/LMY47X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.83 Mobile Safari/537.36'}
|
||||
|
||||
def num_tokens_from_string(string: str, model="gpt-3.5-turbo") -> int:
|
||||
@@ -97,50 +97,65 @@ final_links = fix_links(final_links)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
for link in final_links:
|
||||
response = requests.get(link,headers)
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
for link in final_links:
|
||||
if link not in db_links:
|
||||
print(f"Processing link: {link}")
|
||||
db_links.add(link)
|
||||
|
||||
titles = soup.find_all(['h2', 'h1','h3'])
|
||||
title_text = ' '.join([title.get_text(strip=True) for title in titles])
|
||||
response = requests.get(link,headers)
|
||||
soup = BeautifulSoup(response.text, 'html.parser')
|
||||
|
||||
texts = soup.find_all(['p'])
|
||||
text_text = ' '.join([text.get_text(strip=True) for text in texts])
|
||||
titles = soup.find_all(['h2', 'h1','h3'])
|
||||
title_text = ' '.join([title.get_text(strip=True) for title in titles])
|
||||
|
||||
text_text = text_text
|
||||
title_text = title_text
|
||||
texts = soup.find_all(['p'])
|
||||
text_text = ' '.join([text.get_text(strip=True) for text in texts])
|
||||
|
||||
text_text = text_text
|
||||
title_text = title_text
|
||||
|
||||
title_text = replace_with_spaces(title_text)
|
||||
title_text = replace_with_spaces(title_text)
|
||||
|
||||
text_text = slice_text_at_2k_tokens(text_text)
|
||||
text_text = replace_with_spaces(str(text_text))
|
||||
text_text = slice_text_at_2k_tokens(text_text)
|
||||
text_text = replace_with_spaces(str(text_text))
|
||||
|
||||
ttk = num_tokens_from_string(text_text)
|
||||
ttk = num_tokens_from_string(text_text)
|
||||
|
||||
if ttk > 1900:
|
||||
title_text = slice_title_if_needed(title_text)
|
||||
try:
|
||||
completion = client.chat.completions.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": "Data analytic, Journalist and News reporter"},
|
||||
{"role": "user", "content": rf"Extract relevant information from the following input: Title: {title_text}, Text: {text_text}. Remove any non-news element related to the current text and title, and provide the cleaned data make sure that its valid JSON object with 'title' field and 'content' field."}
|
||||
]
|
||||
)
|
||||
generated_text = completion.choices[0].message.content
|
||||
category_options = ['politics','business','sport','magazine','scitech']
|
||||
|
||||
generated_text = repair_json(generated_text)
|
||||
if ttk > 1900:
|
||||
title_text = slice_title_if_needed(title_text)
|
||||
try:
|
||||
completion = client.chat.completions.create(
|
||||
model="gpt-3.5-turbo",
|
||||
messages=[
|
||||
{"role": "system", "content": "Data analytic, Journalist and News reporter"},
|
||||
{"role": "user", "content": rf"Extract relevant information from the following input: Title: {title_text}, Text: {text_text}. Remove any non-news element related to the current text and title and remove 'FOTO' and 'VIDEO' from title and text, from {category_options} select category in wich that news belong, and provide the cleaned data make sure that its on Bosnian language and valid JSON object with 'title' field, 'category' and 'content' field."}
|
||||
])
|
||||
generated_text = completion.choices[0].message.content
|
||||
|
||||
response_data = json.loads(generated_text)
|
||||
title = response_data["title"]
|
||||
text = response_data["content"]
|
||||
vector = embeddings.embed_query(generated_text)
|
||||
generated_text = repair_json(generated_text)
|
||||
|
||||
response_data = json.loads(generated_text)
|
||||
title = response_data["title"]
|
||||
predicted_category = response_data["category"]
|
||||
text = response_data["content"]
|
||||
|
||||
if predicted_category.lower() in category_options:
|
||||
category = predicted_category.lower()
|
||||
else:
|
||||
category = 'other'
|
||||
|
||||
vector = embeddings.embed_query(generated_text)
|
||||
|
||||
print(f"Title: {title}")
|
||||
print(f"Category: {category}")
|
||||
|
||||
if not is_similar_data(title, text, link, vector, threshold=0.98):
|
||||
similar_d = "NO"
|
||||
insert_data(title, text, link, vector,similar_d)
|
||||
if not is_similar_data(title, text, link, vector, threshold=0.98):
|
||||
similar_d = "NO"
|
||||
insert_data(title, text, link, vector,similar_d,category)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error in completion: {e}")
|
||||
continue
|
||||
except Exception as e:
|
||||
print(f"Error in completion: {e}")
|
||||
continue
|
||||
|
||||
69
pyth/publishing_finals.py
Normal file
69
pyth/publishing_finals.py
Normal file
@@ -0,0 +1,69 @@
|
||||
from slugify import slugify
|
||||
import random
|
||||
from db_management import get_ready_data,insert_final,get_existing_titles
|
||||
|
||||
def create_slug(title):
|
||||
base_slug = "{} {}".format(random.randint(1, 1000), title)
|
||||
slug = slugify(base_slug)
|
||||
return slug
|
||||
|
||||
def get_source_id(link,similar):
|
||||
if similar == "NO":
|
||||
if "srpskainfo" in link:
|
||||
return 1
|
||||
elif "klix" in link:
|
||||
return 2
|
||||
elif "bljesak" in link:
|
||||
return 3
|
||||
elif "blic" in link:
|
||||
return 4
|
||||
elif "index.hr" in link:
|
||||
return 6
|
||||
elif "avaz" in link:
|
||||
return 7
|
||||
elif "telegraf" in link:
|
||||
return 8
|
||||
elif "vijesti.me" in link:
|
||||
return 9
|
||||
elif "dnevnik.hr" in link:
|
||||
return 10
|
||||
elif "24sata.hr" in link:
|
||||
return 11
|
||||
else:
|
||||
return 0
|
||||
else:
|
||||
return 5
|
||||
|
||||
data = get_ready_data()
|
||||
|
||||
def remove_braces_and_quotes(text):
|
||||
final_text = text.replace('{"', '')
|
||||
final_text = final_text.replace('"}', '')
|
||||
|
||||
return final_text
|
||||
|
||||
|
||||
def publish_articles():
|
||||
for d in data:
|
||||
title = d[0]
|
||||
text = d[1]
|
||||
link = d[2]
|
||||
similar_d = d[4]
|
||||
category = d[5]
|
||||
slug = create_slug(title)
|
||||
source_id = get_source_id(link,similar_d)
|
||||
|
||||
check = get_existing_titles()
|
||||
|
||||
title_check = any(title in t for t in check)
|
||||
link_check = any(link in l for l in check)
|
||||
|
||||
if title_check or link_check:
|
||||
continue
|
||||
else:
|
||||
text = remove_braces_and_quotes(text)
|
||||
title = remove_braces_and_quotes(title)
|
||||
print(f"Source: {source_id}")
|
||||
print(f"Link: {link}")
|
||||
insert_final(title, text, slug, link, source_id, category)
|
||||
print(f"Publishing: {title}")
|
||||
@@ -1,22 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Test Pyth</title>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<article>
|
||||
<h2>Test Title 1</h2>
|
||||
<p>Test Text 1</p>
|
||||
<a href="/article/one"> First</a>
|
||||
</article>
|
||||
<article>
|
||||
<h2>Test Title 2</h2>
|
||||
<p>Test Text 2</p>
|
||||
<a href="/article/two">Second</a>
|
||||
</article>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,12 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Article</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Test Title</h2>
|
||||
<p>Test Text</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,12 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Article</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Test Title</h2>
|
||||
<p>Test Text</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -7,7 +7,7 @@ from langchain.vectorstores.pgvector import PGVector
|
||||
from openai import OpenAI
|
||||
import json
|
||||
from dotenv import load_dotenv
|
||||
from scrapingsingle import get_article_links, insert_data, is_similar_data
|
||||
from pyth.get_articles import get_article_links, insert_data, is_similar_data
|
||||
import os
|
||||
|
||||
load_dotenv()
|
||||
|
||||
@@ -2,7 +2,7 @@ import unittest
|
||||
import numpy as np
|
||||
import psycopg2
|
||||
import os
|
||||
from vectData import calculate_cosine_similarity, is_similar_data, insert_data, get_data, create_db
|
||||
from pyth.db_management import calculate_cosine_similarity, is_similar_data, insert_data, get_data, create_db
|
||||
|
||||
class TestIntegration(unittest.TestCase):
|
||||
host = os.getenv("DB_HOST")
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
from flask import Flask , render_template , jsonify
|
||||
from vectData import get_ready_data
|
||||
from flask_cors import CORS
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
CORS(app)
|
||||
|
||||
@app.route('/')
|
||||
def index() :
|
||||
return render_template("index.html")
|
||||
|
||||
|
||||
@app.route('/article/one')
|
||||
def articleone():
|
||||
return render_template("one.html")
|
||||
|
||||
|
||||
@app.route('/article/two')
|
||||
def articletwo():
|
||||
return render_template("two.html")
|
||||
|
||||
@app.route('/data/get/news', methods=['GET'])
|
||||
def takenews():
|
||||
data = get_ready_data()
|
||||
return jsonify(data)
|
||||
|
||||
app.run(debug=True)
|
||||
4
run.sh
Normal file
4
run.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
exec kill -9 $(lsof -t -i:8080)
|
||||
exec go run cmd/web/web.go
|
||||
@@ -1,16 +1,82 @@
|
||||
{{define "articlesHTML"}}
|
||||
<ol reversed>
|
||||
{{range .articles}}
|
||||
<li>
|
||||
<div class="article_content">
|
||||
<a href="/{{.ID}}/{{.Slug}}">
|
||||
{{.Title}}</a></div>
|
||||
<div class="timestamp">{{.SourceName}} - {{ .FormatedCreatedAt }}</div>
|
||||
</li>
|
||||
<br><br>
|
||||
{{else}}
|
||||
Nema članaka za izabrani datum.
|
||||
{{end}}
|
||||
<script>
|
||||
function createPreview(content) {
|
||||
var slicedContent = content.slice(0, 200);
|
||||
if (content.length > 200) {
|
||||
slicedContent += '...';
|
||||
}
|
||||
return slicedContent;
|
||||
}
|
||||
</script>
|
||||
|
||||
</ol>
|
||||
<div class="list">
|
||||
<div class="slide-container">
|
||||
</div>
|
||||
{{range .articles}}
|
||||
<article class="news-article">
|
||||
<div class="article_content">
|
||||
<div class="ar-title">
|
||||
<a href="/{{.ID}}/{{.Slug}}">
|
||||
{{.Title}}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<a href="/{{.ID}}/{{.Slug}}">
|
||||
<div class="prewi" data-content="{{.Content}}" data-title="{{.Title}}" data-link="/{{.ID}}/{{.Slug}}"></div>
|
||||
</a>
|
||||
<div class="timestamp"> starenovine - {{ .FormatedCreatedAt }}</div>
|
||||
</article>
|
||||
{{else}}
|
||||
<div class="empty">
|
||||
Nema članaka za izabrani datum.
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let i = 1;
|
||||
let allArticles = []
|
||||
let lastArticles = []
|
||||
let previewDivs = document.querySelectorAll('.prewi');
|
||||
previewDivs.forEach(function (previewDiv) {
|
||||
let content = previewDiv.getAttribute('data-content');
|
||||
let title = previewDiv.getAttribute('data-title')
|
||||
let link = previewDiv.getAttribute('data-link')
|
||||
allArticles.push({content,title,link})
|
||||
if (allArticles.length > 4){
|
||||
previewDiv.textContent = createPreview(content);
|
||||
}
|
||||
else{
|
||||
lastArticles.push({title,content,link})
|
||||
}
|
||||
i = i+1;
|
||||
});
|
||||
slideArticles = lastArticles.slice(0, 4);
|
||||
function createSlide(){
|
||||
if (slideArticles.length > 0) {
|
||||
let temp = slideArticles.shift()
|
||||
document.querySelector('.slide-container').innerHTML = `
|
||||
<div class="ar-title">
|
||||
<a href="${temp.link}">
|
||||
${temp.title}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<a href="${temp.link}">
|
||||
<div class="prewi">${createPreview(temp.content)}</div>
|
||||
</a>
|
||||
`
|
||||
slideArticles.push(temp)
|
||||
}
|
||||
}
|
||||
createSlide();
|
||||
setInterval(createSlide, 5000)
|
||||
|
||||
let articleDivs = document.querySelectorAll('.news-article');
|
||||
for (let i = 0; i < 4; i++) {
|
||||
if (articleDivs[i]) {
|
||||
articleDivs[i].remove();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{{end}}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
{{define "footerHTML"}}
|
||||
|
||||
<center><div class="sign">SN</div></center>
|
||||
<footer>
|
||||
SN
|
||||
<div>
|
||||
<nav>
|
||||
<a href="{{.previous}}"><----</a> |
|
||||
<a href="/">Početna</a> |
|
||||
<a href="{{.next}}">----></a>
|
||||
</nav>
|
||||
</div>
|
||||
<center>
|
||||
<nav class="fot">
|
||||
<a href="{{.previous}}"><----</a> |
|
||||
<a href="/">Početna</a> |
|
||||
<a href="{{.next}}">----></a>
|
||||
</nav>
|
||||
</center>
|
||||
</footer>
|
||||
{{end}}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||
<meta property="og:site_name" content="starenovine">
|
||||
<meta name="twitter:card" content="preview">
|
||||
<meta property="og:title" content="{{.title}}">
|
||||
@@ -12,45 +12,377 @@
|
||||
<meta property="og:url" content="https://www.starenovine.com">
|
||||
<title>{{.title}} - stare novine</title>
|
||||
<link rel="canonical" href="https://www.starenovine.com/">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||
<style type="text/css">
|
||||
body {
|
||||
font-family: monospace;
|
||||
font-size: 1.5em;
|
||||
width: 90%;
|
||||
max-width: 98vw;
|
||||
}
|
||||
|
||||
h1#title {
|
||||
margin-block-end: 0;
|
||||
font-size: 1.7em;
|
||||
}
|
||||
|
||||
.timestamp {
|
||||
font-size: 0.8em;
|
||||
color: gray;
|
||||
}
|
||||
|
||||
.single_timestamp {
|
||||
font-size: 0.77em;
|
||||
margin-bottom: 0.7em;
|
||||
color: gray;
|
||||
}
|
||||
|
||||
#logo {
|
||||
font-size: 2vw;
|
||||
background: white;
|
||||
}
|
||||
|
||||
pre.article_content {
|
||||
background: white;
|
||||
}
|
||||
|
||||
html {
|
||||
margin: 0 auto;
|
||||
max-width: 98vw;
|
||||
overflow-x: hidden;
|
||||
:root {
|
||||
--ease: cubic-bezier(.2, 1, .3, 1);
|
||||
--icon-size: 60px;
|
||||
--border-radius: 0.5;
|
||||
--background: #2d2c3e;
|
||||
--background-b: #2d2c3e;
|
||||
--green: #16A085;
|
||||
--white: #FFFFFF;
|
||||
}
|
||||
|
||||
body {
|
||||
font-size: 1.5em;
|
||||
margin: 0 auto;
|
||||
overflow-x: hidden;
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
h1#title {
|
||||
background-color: #0B173B;
|
||||
color: white;
|
||||
margin-block-end: 0;
|
||||
font-size: 1.7em;
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
text-decoration: none;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.timestamp {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 0.8em;
|
||||
color: gray;
|
||||
}
|
||||
|
||||
.prewi{
|
||||
color: white;
|
||||
padding-top: 5px;
|
||||
padding-bottom: 2px;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.empty {
|
||||
width: 89vw;
|
||||
color: black;
|
||||
box-shadow: 0 4px 8px #0000004d;
|
||||
border: 1px solid black;
|
||||
background: linear-gradient(90deg, rgba(231, 214, 197, 1) 0%, rgba(241, 234, 227, 1) 100%);
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.ar-title {
|
||||
background-color: #0B173B;
|
||||
width: 100%;
|
||||
color: black;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 3px solid black;
|
||||
}
|
||||
.w-title{
|
||||
color:white;
|
||||
}
|
||||
|
||||
.ar-title > a {
|
||||
font-size: 1.2em;
|
||||
font-weight: 500;
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
.article_content {
|
||||
background-color: black;
|
||||
gap: 4px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.single_timestamp {
|
||||
font-size: 0.77em;
|
||||
margin-bottom: 0.7em;
|
||||
color: gray;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
#logo {
|
||||
width: 100%;
|
||||
font-size: 1.85vw;
|
||||
background: linear-gradient(90deg, rgba(1, 1, 1, 1) 0%, rgba(11, 23, 59, 1) 50%, rgba(0, 0, 0, 1) 100%);
|
||||
box-shadow: 2px 0 20px 6px rgba(11, 23, 59, 0.2);
|
||||
color: white;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.list {
|
||||
display: grid;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
list-style: none;
|
||||
margin-top: 15px;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.news-article > a {
|
||||
background: linear-gradient(90deg, rgba(231, 214, 197, 1) 0%, rgba(232, 232, 232, 1) 51%, rgba(231, 214, 197, 1) 100%);
|
||||
color: black;
|
||||
}
|
||||
.news-article:hover .ar-title{
|
||||
background-color: #FF0000;
|
||||
}
|
||||
|
||||
.article_body {
|
||||
color: white;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
.fot {
|
||||
display: flex;
|
||||
background-color: #0B173B;
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding-top: 5px;
|
||||
padding-bottom: 5px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||
gap: 5%;
|
||||
}
|
||||
|
||||
.fot > a {
|
||||
color: white;
|
||||
gap: 10px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.hed {
|
||||
background-color: #0B173B;
|
||||
text-decoration: none;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding-top: 5px;
|
||||
padding-bottom: 5px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||
gap: 5%;
|
||||
transition: background-color 0.5s var(--ease);
|
||||
}
|
||||
|
||||
.hed.fixed {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
width: 100%;
|
||||
z-index: 1000;
|
||||
box-shadow: 0 4px 12px -4px rgba(255, 65, 54, 0.5);
|
||||
}
|
||||
|
||||
.hed > a {
|
||||
color: white;
|
||||
gap: 10px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.article_content > a {
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.news-article {
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
|
||||
border: 1px solid;
|
||||
border-image: linear-gradient(90deg, rgba(8, 8, 8, 1) 0%, rgba(179, 150, 121, 1) 21%, rgba(0, 0, 0, 1) 37%, rgba(98, 87, 75, 1) 63%, rgba(0, 0, 0, 1) 100%);
|
||||
border-image-slice: 1;
|
||||
}
|
||||
|
||||
pre.article_content {
|
||||
background: white;
|
||||
}
|
||||
|
||||
.news-article > a {
|
||||
text-decoration: none;
|
||||
color: black;
|
||||
}
|
||||
|
||||
#weather {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: fit-content;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.weather-container {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
margin-top: 50px;
|
||||
color: white;
|
||||
}
|
||||
.weather-container > div {
|
||||
text-size-adjust: auto;
|
||||
}
|
||||
.weather-w {
|
||||
border: 1px solid #ccc;
|
||||
width: 20%;
|
||||
text-align: center;
|
||||
color: white;
|
||||
background-color: #0B173B;
|
||||
}
|
||||
.weather-w h3 {
|
||||
margin-top: 0;
|
||||
color: white;
|
||||
}
|
||||
.weather-info {
|
||||
margin-top: 10px;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.w-link{
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.weather-widget {
|
||||
width: 19%;
|
||||
height: 50px;
|
||||
display: grid;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: white;
|
||||
background-color: #0B173B;
|
||||
border: 1px solid;
|
||||
border-image: linear-gradient(90deg, rgba(8, 8, 8, 1) 0%, rgba(179, 150, 121, 1) 21%, rgba(0, 0, 0, 1) 37%, rgba(98, 87, 75, 1) 63%, rgba(0, 0, 0, 1) 100%);
|
||||
border-image-slice: 1;
|
||||
box-shadow: 0 4px 12px -4px rgba(255, 65, 54, 0.5);
|
||||
}
|
||||
|
||||
.weather-widget > div {
|
||||
font-size: 10;
|
||||
}
|
||||
|
||||
.weather-widget > div > span {
|
||||
font-size: 8;
|
||||
}
|
||||
|
||||
|
||||
@media only screen and (max-width: 600px) {
|
||||
|
||||
#weather {
|
||||
display: grid;
|
||||
margin-bottom: 4%;
|
||||
}
|
||||
|
||||
.weather-widget {
|
||||
width: 90vw;
|
||||
height: 20px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.weather-container {
|
||||
display: grid;
|
||||
color: white;
|
||||
gap: 2%;
|
||||
}
|
||||
.weather-w{
|
||||
width: 100vw;
|
||||
}
|
||||
}
|
||||
|
||||
html {
|
||||
margin: 0 auto;
|
||||
width: 90%;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.arr-pr-nx {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.arr-pr-nx svg {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
margin: 0 1rem;
|
||||
cursor: pointer;
|
||||
overflow: visible;
|
||||
fill: white;
|
||||
}
|
||||
|
||||
.arr-pr-nx svg polygon,
|
||||
.arr-pr-nx path {
|
||||
transition: all 0.5s var(--ease);
|
||||
}
|
||||
|
||||
.arr-pr-nx svg:hover polygon,
|
||||
.arr-pr-nx svg:hover path {
|
||||
transition: all 1s var(--ease);
|
||||
fill: #FF0000;
|
||||
}
|
||||
|
||||
.arr-pr-nx svg:hover .arrow {
|
||||
animation: arrow-anim 2.5s var(--ease) infinite;
|
||||
}
|
||||
|
||||
.arr-pr-nx svg:hover .arrow-fixed {
|
||||
animation: arrow-fixed-anim 2.5s var(--ease) infinite;
|
||||
}
|
||||
|
||||
@keyframes arrow-anim {
|
||||
0% {
|
||||
opacity: 1;
|
||||
transform: translateX(0);
|
||||
}
|
||||
5% {
|
||||
transform: translateX(-0.1rem);
|
||||
}
|
||||
100% {
|
||||
transform: translateX(1rem);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes arrow-fixed-anim {
|
||||
5% {
|
||||
opacity: 0;
|
||||
}
|
||||
20% {
|
||||
opacity: 0.4;
|
||||
}
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.home-icon {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
background-color: #0B173B;
|
||||
border-radius: 50%;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.5s var(--ease);
|
||||
}
|
||||
|
||||
.home-icon:hover {
|
||||
background-color: #FF0000;
|
||||
}
|
||||
|
||||
.home-icon i {
|
||||
font-size: 2rem;
|
||||
color: white;
|
||||
transition: color 0.5s var(--ease);
|
||||
}
|
||||
|
||||
.home-icon:hover i {
|
||||
color: #FF0000;
|
||||
}
|
||||
|
||||
|
||||
|
||||
</style>
|
||||
</head>
|
||||
{{end}}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
{{define "headerHTML"}}
|
||||
<header>
|
||||
<center>
|
||||
<a href="/" class="logo">
|
||||
<pre id="logo">
|
||||
_____ ______ ____ ____ ___ ____ ___ __ __ ____ ____ ___
|
||||
/ ___/| | / || \ / _]| \ / \ | | || || \ / _]
|
||||
@@ -10,11 +12,51 @@
|
||||
\___| |__| |__|__||__|\_||_____||__|__| \___/ \_/ |____||__|__||_____|
|
||||
|
||||
</pre>
|
||||
<br>
|
||||
<nav>
|
||||
<a href="{{.previous}}"><----</a> |
|
||||
<a href="/">Početna</a> |
|
||||
<a href="{{.next}}">----></a>
|
||||
</nav>
|
||||
</a>
|
||||
</center>
|
||||
<nav class="hed">
|
||||
<a href="{{.previous}}">
|
||||
<div class="arr-pr-nx" title="Prethodna">
|
||||
<svg width="18px" height="17px" viewBox="0 0 18 17" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g id="prev" transform="translate(8.500000, 8.500000) scale(-1, 1) translate(-8.500000, -8.500000)">
|
||||
<polygon class="arrow" points="16.3746667 8.33860465 7.76133333 15.3067621 6.904 14.3175671 14.2906667 8.34246869 6.908 2.42790698 7.76 1.43613596"></polygon>
|
||||
<polygon class="arrow-fixed" points="16.3746667 8.33860465 7.76133333 15.3067621 6.904 14.3175671 14.2906667 8.34246869 6.908 2.42790698 7.76 1.43613596"></polygon>
|
||||
<path d="M-1.48029737e-15,0.56157424 L-1.48029737e-15,16.1929159 L9.708,8.33860465 L-2.66453526e-15,0.56157424 L-1.48029737e-15,0.56157424 Z M1.33333333,3.30246869 L7.62533333,8.34246869 L1.33333333,13.4327013 L1.33333333,3.30246869 L1.33333333,3.30246869 Z"></path>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
</a>
|
||||
<a href="/">
|
||||
<div class="home-icon" title="Pocetna">
|
||||
<i class="fa fa-home" style="font-size:48px;color:white"></i>
|
||||
</div>
|
||||
</a>
|
||||
<a href="{{.next}}">
|
||||
<div class="arr-pr-nx" title="Sledeca">
|
||||
<svg width="18px" height="17px" viewBox="-1 0 18 17" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g>
|
||||
<polygon class="arrow" points="16.3746667 8.33860465 7.76133333 15.3067621 6.904 14.3175671 14.2906667 8.34246869 6.908 2.42790698 7.76 1.43613596"></polygon>
|
||||
<polygon class="arrow-fixed" points="16.3746667 8.33860465 7.76133333 15.3067621 6.904 14.3175671 14.2906667 8.34246869 6.908 2.42790698 7.76 1.43613596"></polygon>
|
||||
<path d="M-4.58892184e-16,0.56157424 L-4.58892184e-16,16.1929159 L9.708,8.33860465 L-1.64313008e-15,0.56157424 L-4.58892184e-16,0.56157424 Z M1.33333333,3.30246869 L7.62533333,8.34246869 L1.33333333,13.4327013 L1.33333333,3.30246869 L1.33333333,3.30246869 Z"></path>
|
||||
</g>
|
||||
</svg>
|
||||
</div>
|
||||
</a>
|
||||
</nav>
|
||||
<br>
|
||||
</header>
|
||||
<script>
|
||||
const handleScroll = function(event) {
|
||||
const top = window.scrollY;
|
||||
const header = document.querySelector('.hed');
|
||||
const headerBottom = header.offsetTop + header.offsetHeight;
|
||||
|
||||
if (top >= headerBottom) {
|
||||
header.classList.add('fixed');
|
||||
} else {
|
||||
header.classList.remove('fixed');
|
||||
}
|
||||
}
|
||||
window.addEventListener('scroll', handleScroll);
|
||||
</script>
|
||||
{{end}}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
{{with .article }}
|
||||
<div class="article_content">
|
||||
<h1 id="title">{{.Title}}</h1>
|
||||
<div class="single_timestamp">{{.SourceName}} - {{ .FormatedCreatedAt }}</div>
|
||||
<div class="single_timestamp"> starenovine - {{ .FormatedCreatedAt }}</div>
|
||||
<div class="article_body">
|
||||
{{.Content}}
|
||||
</div>
|
||||
|
||||
80
web/data/weatherapi.html
Normal file
80
web/data/weatherapi.html
Normal file
@@ -0,0 +1,80 @@
|
||||
{{define "weatherHTML"}}
|
||||
<a class="w-link" href="/weather">
|
||||
<div id="weather">
|
||||
<div class="weather-widget" id="weather-widget-sarajevo">
|
||||
<div><span id="city-sarajevo">Učitavanje...</span></div>
|
||||
<div id="temperature-sarajevo">Učitavanje...</div>
|
||||
</div>
|
||||
<div class="weather-widget" id="weather-widget-banja-luka">
|
||||
<div><span id="city-banja-luka">Učitavanje...</span></div>
|
||||
<div id="temperature-banja-luka">Učitavanje...</div>
|
||||
</div>
|
||||
<div class="weather-widget" id="weather-widget-tuzla">
|
||||
<div><span id="city-tuzla">Učitavanje...</span></div>
|
||||
<div id="temperature-tuzla">Učitavanje...</div>
|
||||
</div>
|
||||
<div class="weather-widget" id="weather-widget-zenica">
|
||||
<div><span id="city-zenica">Učitavanje...</span></div>
|
||||
<div id="temperature-zenica">Učitavanje...</div>
|
||||
</div>
|
||||
<div class="weather-widget" id="weather-widget-mostar">
|
||||
<div><span id="city-mostar">Učitavanje...</span></div>
|
||||
<div id="temperature-mostar">Učitavanje...</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
|
||||
|
||||
<script>
|
||||
const apiKey = 'abb35e21bdcbad6d1b00141a2b25cf5a';
|
||||
|
||||
const cities = [
|
||||
{ name: 'Sarajevo', id: 'sarajevo' },
|
||||
{ name: 'Banja Luka', id: 'banja-luka' },
|
||||
{ name: 'Tuzla', id: 'tuzla' },
|
||||
{ name: 'Zenica', id:'zenica'},
|
||||
{ name: 'Mostar', id: 'mostar' }
|
||||
];
|
||||
|
||||
async function getWeatherData(city) {
|
||||
const apiUrl = `https://api.openweathermap.org/data/2.5/weather?q=${city.name}&appid=${apiKey}&units=metric&lang=hr`;
|
||||
try {
|
||||
const response = await fetch(apiUrl);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! Status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
updateUI(data, city.id);
|
||||
} catch (error) {
|
||||
console.error(`Error fetching data for ${city.name}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
function updateUI(data, cityId) {
|
||||
const cityElement = document.getElementById(`city-${cityId}`);
|
||||
const temperatureElement = document.getElementById(`temperature-${cityId}`);
|
||||
|
||||
cityElement.textContent = data.name;
|
||||
temperatureElement.textContent = `${data.main.temp}°C`;
|
||||
}
|
||||
|
||||
function cToL(text) {
|
||||
const cyrillicChars = 'АБВГДЂЕЖЗИЈКЛЉМНЊОПРСТЋУФХЦЧЏШабвгдђежзијклљмнњопрстћуфхцчџш';
|
||||
const latinChars = 'ABVGĐEŽZIJKLJMNJOPRSTĆUFHCČDŽŠabvgdđežzijkljmnjoprstćufhčdžš';
|
||||
|
||||
return text
|
||||
.split('')
|
||||
.map(char => {
|
||||
const index = cyrillicChars.indexOf(char);
|
||||
return index !== -1 ? latinChars[index] : char;
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
|
||||
cities.forEach(city => {
|
||||
getWeatherData(city);
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
{{end}}
|
||||
@@ -4,6 +4,9 @@
|
||||
<body>
|
||||
{{template "headerHTML" .}}
|
||||
|
||||
{{template "weatherHTML"}}
|
||||
|
||||
|
||||
{{template "singleArticleHTML" .}}
|
||||
|
||||
{{template "footerHTML" .}}
|
||||
|
||||
47
web/tpl/category.html
Normal file
47
web/tpl/category.html
Normal file
@@ -0,0 +1,47 @@
|
||||
{{define "categoryHTML"}}
|
||||
|
||||
{{template "headHTML" .}}
|
||||
<body>
|
||||
{{template "headerHTML" .}}
|
||||
|
||||
{{template "weatherHTML"}}
|
||||
|
||||
|
||||
<h1>{{.Category}}</h1>
|
||||
{{range .Articles}}
|
||||
<article class="news-article">
|
||||
<div class="article_content">
|
||||
<div class="ar-title">
|
||||
<a href="/{{.ID}}/{{.Slug}}">
|
||||
{{.Title}}
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<a href="/{{.ID}}/{{.Slug}}">
|
||||
<div class="prewi" data-content="{{.Content}}" data-title="{{.Title}}" data-link="/{{.ID}}/{{.Slug}}"></div>
|
||||
</a>
|
||||
<div class="timestamp"> starenovine - {{ .FormatedCreatedAt }}</div>
|
||||
</article>
|
||||
{{else}}
|
||||
<div class="empty">
|
||||
Nema članaka za izabrani datum.
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
<script>
|
||||
function createPreview(content) {
|
||||
let slicedContent = content.slice(0,200);
|
||||
if (content.length > 200){
|
||||
slicedContent += '...'
|
||||
}
|
||||
}
|
||||
let previewDiv = document.querySelectorAll(".prewi");
|
||||
previewDivs.forEach(function (previewDiv) {
|
||||
let content = document.getAttribute('data-content')
|
||||
previewDiv.textContent = createPreview(content)
|
||||
})
|
||||
</script>
|
||||
{{template "footerHTML" .}}
|
||||
</body>
|
||||
</html>
|
||||
{{end}}
|
||||
@@ -4,6 +4,8 @@
|
||||
<body>
|
||||
{{template "headerHTML" .}}
|
||||
|
||||
{{template "weatherHTML"}}
|
||||
|
||||
{{template "articlesHTML" .}}
|
||||
|
||||
{{template "footerHTML" .}}
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
<body>
|
||||
{{template "headerHTML" .}}
|
||||
|
||||
{{template "weatherHTML"}}
|
||||
|
||||
{{template "articlesHTML" .}}
|
||||
|
||||
{{template "footerHTML" .}}
|
||||
|
||||
30
web/tpl/weather.html
Normal file
30
web/tpl/weather.html
Normal file
@@ -0,0 +1,30 @@
|
||||
{{define "fullweatherHTML"}}
|
||||
|
||||
{{template "headHTML" .}}
|
||||
<body>
|
||||
{{template "headerHTML" .}}
|
||||
|
||||
<h2 class="w-title">{{.title}}</h2>
|
||||
<div class="weather-container">
|
||||
{{range .weatherInfo}}
|
||||
<div class="weather-w">
|
||||
<h3>{{.Name}}</h3>
|
||||
{{with index .Weather 0}}
|
||||
<div class="weather-info">Opis: {{.Description}}</div>
|
||||
{{end}}
|
||||
<div class="weather-info">Temperatura: {{.Main.Temp}}°C</div>
|
||||
<div class="weather-info">Osecaj: {{.Main.FellsLike}}°C</div>
|
||||
<div class="weather-info">Pritisak:{{.Main.Preassure}} hPa</div>
|
||||
<div class="weather-info">Vlaznost: {{.Main.Humidity}}%</div>
|
||||
<div class="weather-info">Min Temp: {{.Main.TempMin}}°C</div>
|
||||
<div class="weather-info">Max Temp: {{.Main.TempMax}}°C</div>
|
||||
<div class="weather-info">Vetar: {{.Wind.Speed}} m/s</div>
|
||||
<div class="weather-info">Oblaci: {{.Clouds.All}}%</div>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
{{template "footerHTML" .}}
|
||||
</body>
|
||||
</html>
|
||||
{{end}}
|
||||
Reference in New Issue
Block a user