Add weather
This commit is contained in:
parent
27ebdeebe7
commit
2069704c80
11 changed files with 363 additions and 12 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -205,3 +205,4 @@ Temporary Items
|
|||
# User specific
|
||||
.idea/
|
||||
static/css/style.css
|
||||
storage/
|
||||
|
|
|
@ -8,15 +8,13 @@ import (
|
|||
"io"
|
||||
"launchpad/message"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
Bookmarks []Bookmark
|
||||
}
|
||||
|
||||
var Bookmarks []Bookmark
|
||||
|
||||
const StorageDir = "storage/"
|
||||
const IconsDir = StorageDir + "icons/"
|
||||
const folder = "bookmark/"
|
||||
const bookmarksFile = "bookmarks.json"
|
||||
|
||||
|
@ -27,7 +25,7 @@ func init() {
|
|||
}
|
||||
|
||||
func createFolderStructure() {
|
||||
folders := []string{StorageDir}
|
||||
folders := []string{StorageDir, IconsDir}
|
||||
err := folderCreate.CreateFolders(folders, 0755)
|
||||
if err != nil {
|
||||
logrus.WithField("error", err).Fatal(message.CannotCreate.String())
|
||||
|
@ -68,6 +66,14 @@ func readBookmarksFile() []byte {
|
|||
return byteValue
|
||||
}
|
||||
|
||||
func replaceIconString() {
|
||||
for i, v := range Bookmarks {
|
||||
if !strings.Contains(v.Icon, "http") {
|
||||
Bookmarks[i].Icon = "/" + IconsDir + v.Icon
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func parseBookmarks() {
|
||||
byteValue := readBookmarksFile()
|
||||
err := json.Unmarshal(byteValue, &Bookmarks)
|
||||
|
@ -75,6 +81,7 @@ func parseBookmarks() {
|
|||
logrus.WithField("file", bookmarksFile).Error(message.CannotParse.String())
|
||||
return
|
||||
}
|
||||
replaceIconString()
|
||||
}
|
||||
|
||||
func watchBookmarks() {
|
||||
|
|
2
main.go
2
main.go
|
@ -3,10 +3,12 @@ package main
|
|||
import (
|
||||
"launchpad/logging"
|
||||
"launchpad/server"
|
||||
"launchpad/weather"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logging.NewGlobalLogger()
|
||||
weather.NewWeather()
|
||||
s := server.NewServer(3000)
|
||||
s.Listen()
|
||||
}
|
||||
|
|
|
@ -7,4 +7,5 @@ import (
|
|||
func setupRouter(router *chi.Mux) {
|
||||
router.Get("/", launchpad)
|
||||
serveStatic(router, "static")
|
||||
serveStatic(router, "storage/icons")
|
||||
}
|
||||
|
|
|
@ -3,14 +3,20 @@ package server
|
|||
import (
|
||||
"launchpad/bookmark"
|
||||
"launchpad/files"
|
||||
"launchpad/weather"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type LaunchpadInformation struct {
|
||||
Title string
|
||||
Bookmarks []bookmark.Bookmark
|
||||
Weather weather.OpenWeatherApiResponse
|
||||
}
|
||||
|
||||
func launchpad(w http.ResponseWriter, r *http.Request) {
|
||||
files.ParseHtml(w, "index.gohtml", LaunchpadInformation{Title: "Launchpad", Bookmarks: bookmark.Bookmarks})
|
||||
files.ParseHtml(w, "index.gohtml", LaunchpadInformation{
|
||||
Title: "Launchpad",
|
||||
Bookmarks: bookmark.Bookmarks,
|
||||
Weather: weather.CurrentOpenWeather,
|
||||
})
|
||||
}
|
||||
|
|
4
static/css/global.css
Normal file
4
static/css/global.css
Normal file
|
@ -0,0 +1,4 @@
|
|||
.link:hover .img {
|
||||
opacity: 1;
|
||||
transition: opacity ease-in 0.2s;
|
||||
}
|
|
@ -14,9 +14,164 @@
|
|||
<meta name="msapplication-TileColor" content="#da532c" />
|
||||
<meta name="theme-color" content="#da532c" />
|
||||
|
||||
<link rel="stylesheet" href="/static/css/global.css" />
|
||||
<link rel="stylesheet" href="/static/css/style.css" />
|
||||
</head>
|
||||
|
||||
<body></body>
|
||||
<body class="bg-slate-100 dark:bg-slate-800 text-slate-800 dark:text-slate-50">
|
||||
<div class="mx-auto max-w-7xl px-5 lg:px-8 my-3 md:my-10 lg:my-18 xl:my-28">{{ template "content" . }}</div>
|
||||
</body>
|
||||
</html>
|
||||
{{ end }}
|
||||
|
||||
{{ define "content" }}{{ end }}
|
||||
|
||||
{{ define "weatherIcons" }}
|
||||
<svg xmlns="http://www.w3.org/2000/svg" style="display: none">
|
||||
<symbol id="01d" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M8 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0zm0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13zm8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5zM3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8zm10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0zm-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zm9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707zM4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="01n" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M6 .278a.768.768 0 0 1 .08.858 7.208 7.208 0 0 0-.878 3.46c0 4.021 3.278 7.277 7.318 7.277.527 0 1.04-.055 1.533-.16a.787.787 0 0 1 .81.316.733.733 0 0 1-.031.893A8.349 8.349 0 0 1 8.344 16C3.734 16 0 12.286 0 7.71 0 4.266 2.114 1.312 5.124.06A.752.752 0 0 1 6 .278z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="02d" viewBox="0 0 16 16">
|
||||
<path fill="currentColor" d="M11.473 11a4.5 4.5 0 0 0-8.72-.99A3 3 0 0 0 3 16h8.5a2.5 2.5 0 0 0 0-5h-.027z" />
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M10.5 1.5a.5.5 0 0 0-1 0v1a.5.5 0 0 0 1 0v-1zm3.743 1.964a.5.5 0 1 0-.707-.707l-.708.707a.5.5 0 0 0 .708.708l.707-.708zm-7.779-.707a.5.5 0 0 0-.707.707l.707.708a.5.5 0 1 0 .708-.708l-.708-.707zm1.734 3.374a2 2 0 1 1 3.296 2.198c.199.281.372.582.516.898a3 3 0 1 0-4.84-3.225c.352.011.696.055 1.028.129zm4.484 4.074c.6.215 1.125.59 1.522 1.072a.5.5 0 0 0 .039-.742l-.707-.707a.5.5 0 0 0-.854.377zM14.5 6.5a.5.5 0 0 0 0 1h1a.5.5 0 0 0 0-1h-1z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="02n" viewBox="0 0 16 16">
|
||||
<path fill="currentColor" d="M11.473 11a4.5 4.5 0 0 0-8.72-.99A3 3 0 0 0 3 16h8.5a2.5 2.5 0 0 0 0-5h-.027z" />
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M11.286 1.778a.5.5 0 0 0-.565-.755 4.595 4.595 0 0 0-3.18 5.003 5.46 5.46 0 0 1 1.055.209A3.603 3.603 0 0 1 9.83 2.617a4.593 4.593 0 0 0 4.31 5.744 3.576 3.576 0 0 1-2.241.634c.162.317.295.652.394 1a4.59 4.59 0 0 0 3.624-2.04.5.5 0 0 0-.565-.755 3.593 3.593 0 0 1-4.065-5.422z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="03d" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M4.406 3.342A5.53 5.53 0 0 1 8 2c2.69 0 4.923 2 5.166 4.579C14.758 6.804 16 8.137 16 9.773 16 11.569 14.502 13 12.687 13H3.781C1.708 13 0 11.366 0 9.318c0-1.763 1.266-3.223 2.942-3.593.143-.863.698-1.723 1.464-2.383z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="03n" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M4.406 3.342A5.53 5.53 0 0 1 8 2c2.69 0 4.923 2 5.166 4.579C14.758 6.804 16 8.137 16 9.773 16 11.569 14.502 13 12.687 13H3.781C1.708 13 0 11.366 0 9.318c0-1.763 1.266-3.223 2.942-3.593.143-.863.698-1.723 1.464-2.383z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="04d" viewBox="0 0 16 16">
|
||||
<path fill="currentColor" d="M11.473 9a4.5 4.5 0 0 0-8.72-.99A3 3 0 0 0 3 14h8.5a2.5 2.5 0 1 0-.027-5z" />
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M14.544 9.772a3.506 3.506 0 0 0-2.225-1.676 5.502 5.502 0 0 0-6.337-4.002 4.002 4.002 0 0 1 7.392.91 2.5 2.5 0 0 1 1.17 4.769z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="04n" viewBox="0 0 16 16">
|
||||
<path fill="currentColor" d="M11.473 9a4.5 4.5 0 0 0-8.72-.99A3 3 0 0 0 3 14h8.5a2.5 2.5 0 1 0-.027-5z" />
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M14.544 9.772a3.506 3.506 0 0 0-2.225-1.676 5.502 5.502 0 0 0-6.337-4.002 4.002 4.002 0 0 1 7.392.91 2.5 2.5 0 0 1 1.17 4.769z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="09d" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M4.158 12.025a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 0 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317zm6 0a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 0 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317zm-3.5 1.5a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 0 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317zm6 0a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 1 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317zm.747-8.498a5.001 5.001 0 0 0-9.499-1.004A3.5 3.5 0 1 0 3.5 11H13a3 3 0 0 0 .405-5.973z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="09n" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M4.158 12.025a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 0 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317zm6 0a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 0 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317zm-3.5 1.5a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 0 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317zm6 0a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 1 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317zm.747-8.498a5.001 5.001 0 0 0-9.499-1.004A3.5 3.5 0 1 0 3.5 11H13a3 3 0 0 0 .405-5.973z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="10d" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M4.158 12.025a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 1 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317zm3 0a.5.5 0 0 1 .316.633l-1 3a.5.5 0 1 1-.948-.316l1-3a.5.5 0 0 1 .632-.317zm3 0a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 1 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317zm3 0a.5.5 0 0 1 .316.633l-1 3a.5.5 0 1 1-.948-.316l1-3a.5.5 0 0 1 .632-.317zm.247-6.998a5.001 5.001 0 0 0-9.499-1.004A3.5 3.5 0 1 0 3.5 11H13a3 3 0 0 0 .405-5.973z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="10n" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M4.158 12.025a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 1 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317zm3 0a.5.5 0 0 1 .316.633l-1 3a.5.5 0 1 1-.948-.316l1-3a.5.5 0 0 1 .632-.317zm3 0a.5.5 0 0 1 .316.633l-.5 1.5a.5.5 0 1 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.317zm3 0a.5.5 0 0 1 .316.633l-1 3a.5.5 0 1 1-.948-.316l1-3a.5.5 0 0 1 .632-.317zm.247-6.998a5.001 5.001 0 0 0-9.499-1.004A3.5 3.5 0 1 0 3.5 11H13a3 3 0 0 0 .405-5.973z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="11d" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M2.658 11.026a.5.5 0 0 1 .316.632l-.5 1.5a.5.5 0 1 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.316zm9.5 0a.5.5 0 0 1 .316.632l-.5 1.5a.5.5 0 0 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.316zm-7.5 1.5a.5.5 0 0 1 .316.632l-.5 1.5a.5.5 0 1 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.316zm9.5 0a.5.5 0 0 1 .316.632l-.5 1.5a.5.5 0 0 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.316zm-7.105-1.25A.5.5 0 0 1 7.5 11h1a.5.5 0 0 1 .474.658l-.28.842H9.5a.5.5 0 0 1 .39.812l-2 2.5a.5.5 0 0 1-.875-.433L7.36 14H6.5a.5.5 0 0 1-.447-.724l1-2zm6.352-7.249a5.001 5.001 0 0 0-9.499-1.004A3.5 3.5 0 1 0 3.5 10H13a3 3 0 0 0 .405-5.973z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="11n" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M2.658 11.026a.5.5 0 0 1 .316.632l-.5 1.5a.5.5 0 1 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.316zm9.5 0a.5.5 0 0 1 .316.632l-.5 1.5a.5.5 0 0 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.316zm-7.5 1.5a.5.5 0 0 1 .316.632l-.5 1.5a.5.5 0 1 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.316zm9.5 0a.5.5 0 0 1 .316.632l-.5 1.5a.5.5 0 0 1-.948-.316l.5-1.5a.5.5 0 0 1 .632-.316zm-7.105-1.25A.5.5 0 0 1 7.5 11h1a.5.5 0 0 1 .474.658l-.28.842H9.5a.5.5 0 0 1 .39.812l-2 2.5a.5.5 0 0 1-.875-.433L7.36 14H6.5a.5.5 0 0 1-.447-.724l1-2zm6.352-7.249a5.001 5.001 0 0 0-9.499-1.004A3.5 3.5 0 1 0 3.5 10H13a3 3 0 0 0 .405-5.973z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="13d" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M2.625 11.5a.25.25 0 0 1 .25.25v.57l.501-.287a.25.25 0 0 1 .248.434l-.495.283.495.283a.25.25 0 0 1-.248.434l-.501-.286v.569a.25.25 0 1 1-.5 0v-.57l-.501.287a.25.25 0 0 1-.248-.434l.495-.283-.495-.283a.25.25 0 0 1 .248-.434l.501.286v-.569a.25.25 0 0 1 .25-.25zm2.75 2a.25.25 0 0 1 .25.25v.57l.5-.287a.25.25 0 0 1 .249.434l-.495.283.495.283a.25.25 0 0 1-.248.434l-.501-.286v.569a.25.25 0 1 1-.5 0v-.57l-.501.287a.25.25 0 0 1-.248-.434l.495-.283-.495-.283a.25.25 0 0 1 .248-.434l.501.286v-.569a.25.25 0 0 1 .25-.25zm5.5 0a.25.25 0 0 1 .25.25v.57l.5-.287a.25.25 0 0 1 .249.434l-.495.283.495.283a.25.25 0 0 1-.248.434l-.501-.286v.569a.25.25 0 0 1-.5 0v-.57l-.501.287a.25.25 0 0 1-.248-.434l.495-.283-.495-.283a.25.25 0 0 1 .248-.434l.501.286v-.569a.25.25 0 0 1 .25-.25zm-2.75-2a.25.25 0 0 1 .25.25v.57l.5-.287a.25.25 0 0 1 .249.434l-.495.283.495.283a.25.25 0 0 1-.248.434l-.501-.286v.569a.25.25 0 1 1-.5 0v-.57l-.501.287a.25.25 0 0 1-.248-.434l.495-.283-.495-.283a.25.25 0 0 1 .248-.434l.501.286v-.569a.25.25 0 0 1 .25-.25zm5.5 0a.25.25 0 0 1 .25.25v.57l.5-.287a.25.25 0 0 1 .249.434l-.495.283.495.283a.25.25 0 0 1-.248.434l-.501-.286v.569a.25.25 0 0 1-.5 0v-.57l-.501.287a.25.25 0 1 1-.248-.434l.495-.283-.495-.283a.25.25 0 0 1 .248-.434l.501.286v-.569a.25.25 0 0 1 .25-.25zm-.22-7.223a5.001 5.001 0 0 0-9.499-1.004A3.5 3.5 0 1 0 3.5 10.25H13a3 3 0 0 0 .405-5.973z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="13n" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M2.625 11.5a.25.25 0 0 1 .25.25v.57l.501-.287a.25.25 0 0 1 .248.434l-.495.283.495.283a.25.25 0 0 1-.248.434l-.501-.286v.569a.25.25 0 1 1-.5 0v-.57l-.501.287a.25.25 0 0 1-.248-.434l.495-.283-.495-.283a.25.25 0 0 1 .248-.434l.501.286v-.569a.25.25 0 0 1 .25-.25zm2.75 2a.25.25 0 0 1 .25.25v.57l.5-.287a.25.25 0 0 1 .249.434l-.495.283.495.283a.25.25 0 0 1-.248.434l-.501-.286v.569a.25.25 0 1 1-.5 0v-.57l-.501.287a.25.25 0 0 1-.248-.434l.495-.283-.495-.283a.25.25 0 0 1 .248-.434l.501.286v-.569a.25.25 0 0 1 .25-.25zm5.5 0a.25.25 0 0 1 .25.25v.57l.5-.287a.25.25 0 0 1 .249.434l-.495.283.495.283a.25.25 0 0 1-.248.434l-.501-.286v.569a.25.25 0 0 1-.5 0v-.57l-.501.287a.25.25 0 0 1-.248-.434l.495-.283-.495-.283a.25.25 0 0 1 .248-.434l.501.286v-.569a.25.25 0 0 1 .25-.25zm-2.75-2a.25.25 0 0 1 .25.25v.57l.5-.287a.25.25 0 0 1 .249.434l-.495.283.495.283a.25.25 0 0 1-.248.434l-.501-.286v.569a.25.25 0 1 1-.5 0v-.57l-.501.287a.25.25 0 0 1-.248-.434l.495-.283-.495-.283a.25.25 0 0 1 .248-.434l.501.286v-.569a.25.25 0 0 1 .25-.25zm5.5 0a.25.25 0 0 1 .25.25v.57l.5-.287a.25.25 0 0 1 .249.434l-.495.283.495.283a.25.25 0 0 1-.248.434l-.501-.286v.569a.25.25 0 0 1-.5 0v-.57l-.501.287a.25.25 0 1 1-.248-.434l.495-.283-.495-.283a.25.25 0 0 1 .248-.434l.501.286v-.569a.25.25 0 0 1 .25-.25zm-.22-7.223a5.001 5.001 0 0 0-9.499-1.004A3.5 3.5 0 1 0 3.5 10.25H13a3 3 0 0 0 .405-5.973z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="50d" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M8.5 2a5.001 5.001 0 0 1 4.905 4.027A3 3 0 0 1 13 12H3.5A3.5 3.5 0 0 1 .035 9H5.5a.5.5 0 0 0 0-1H.035a3.5 3.5 0 0 1 3.871-2.977A5.001 5.001 0 0 1 8.5 2zm-6 8a.5.5 0 0 0 0 1h9a.5.5 0 0 0 0-1h-9zM0 13.5a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="50n" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M8.5 2a5.001 5.001 0 0 1 4.905 4.027A3 3 0 0 1 13 12H3.5A3.5 3.5 0 0 1 .035 9H5.5a.5.5 0 0 0 0-1H.035a3.5 3.5 0 0 1 3.871-2.977A5.001 5.001 0 0 1 8.5 2zm-6 8a.5.5 0 0 0 0 1h9a.5.5 0 0 0 0-1h-9zM0 13.5a.5.5 0 0 1 .5-.5h9a.5.5 0 0 1 0 1h-9a.5.5 0 0 1-.5-.5z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="sunset" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M7.646 4.854a.5.5 0 0 0 .708 0l1.5-1.5a.5.5 0 0 0-.708-.708l-.646.647V1.5a.5.5 0 0 0-1 0v1.793l-.646-.647a.5.5 0 1 0-.708.708l1.5 1.5zm-5.303-.51a.5.5 0 0 1 .707 0l1.414 1.413a.5.5 0 0 1-.707.707L2.343 5.05a.5.5 0 0 1 0-.707zm11.314 0a.5.5 0 0 1 0 .706l-1.414 1.414a.5.5 0 1 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zM11.709 11.5a4 4 0 1 0-7.418 0H.5a.5.5 0 0 0 0 1h15a.5.5 0 0 0 0-1h-3.79zM0 10a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 0 1h-2A.5.5 0 0 1 0 10zm13 0a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 0 1h-2a.5.5 0 0 1-.5-.5z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="sunrise" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M7.646 1.146a.5.5 0 0 1 .708 0l1.5 1.5a.5.5 0 0 1-.708.708L8.5 2.707V4.5a.5.5 0 0 1-1 0V2.707l-.646.647a.5.5 0 1 1-.708-.708l1.5-1.5zM2.343 4.343a.5.5 0 0 1 .707 0l1.414 1.414a.5.5 0 0 1-.707.707L2.343 5.05a.5.5 0 0 1 0-.707zm11.314 0a.5.5 0 0 1 0 .707l-1.414 1.414a.5.5 0 1 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zM11.709 11.5a4 4 0 1 0-7.418 0H.5a.5.5 0 0 0 0 1h15a.5.5 0 0 0 0-1h-3.79zM0 10a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 0 1h-2A.5.5 0 0 1 0 10zm13 0a.5.5 0 0 1 .5-.5h2a.5.5 0 0 1 0 1h-2a.5.5 0 0 1-.5-.5z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="humidity" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
fill-rule="evenodd"
|
||||
d="M7.21.8C7.69.295 8 0 8 0c.109.363.234.708.371 1.038.812 1.946 2.073 3.35 3.197 4.6C12.878 7.096 14 8.345 14 10a6 6 0 0 1-12 0C2 6.668 5.58 2.517 7.21.8zm.413 1.021A31.25 31.25 0 0 0 5.794 3.99c-.726.95-1.436 2.008-1.96 3.07C3.304 8.133 3 9.138 3 10c0 0 2.5 1.5 5 .5s5-.5 5-.5c0-1.201-.796-2.157-2.181-3.7l-.03-.032C9.75 5.11 8.5 3.72 7.623 1.82z"
|
||||
/>
|
||||
<path fill="currentColor" fill-rule="evenodd" d="M4.553 7.776c.82-1.641 1.717-2.753 2.093-3.13l.708.708c-.29.29-1.128 1.311-1.907 2.87l-.894-.448z" />
|
||||
</symbol>
|
||||
<symbol id="location" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
fill-rule="evenodd"
|
||||
d="M4 4a4 4 0 1 1 4.5 3.969V13.5a.5.5 0 0 1-1 0V7.97A4 4 0 0 1 4 3.999zm2.493 8.574a.5.5 0 0 1-.411.575c-.712.118-1.28.295-1.655.493a1.319 1.319 0 0 0-.37.265.301.301 0 0 0-.057.09V14l.002.008a.147.147 0 0 0 .016.033.617.617 0 0 0 .145.15c.165.13.435.27.813.395.751.25 1.82.414 3.024.414s2.273-.163 3.024-.414c.378-.126.648-.265.813-.395a.619.619 0 0 0 .146-.15.148.148 0 0 0 .015-.033L12 14v-.004a.301.301 0 0 0-.057-.09 1.318 1.318 0 0 0-.37-.264c-.376-.198-.943-.375-1.655-.493a.5.5 0 1 1 .164-.986c.77.127 1.452.328 1.957.594C12.5 13 13 13.4 13 14c0 .426-.26.752-.544.977-.29.228-.68.413-1.116.558-.878.293-2.059.465-3.34.465-1.281 0-2.462-.172-3.34-.465-.436-.145-.826-.33-1.116-.558C3.26 14.752 3 14.426 3 14c0-.599.5-1 .961-1.243.505-.266 1.187-.467 1.957-.594a.5.5 0 0 1 .575.411z"
|
||||
/>
|
||||
</symbol>
|
||||
<symbol id="quote" viewBox="0 0 16 16">
|
||||
<path
|
||||
fill="currentColor"
|
||||
d="M16 8c0 3.866-3.582 7-8 7a9.06 9.06 0 0 1-2.347-.306c-.584.296-1.925.864-4.181 1.234-.2.032-.352-.176-.273-.362.354-.836.674-1.95.77-2.966C.744 11.37 0 9.76 0 8c0-3.866 3.582-7 8-7s8 3.134 8 7zM7.194 6.766a1.688 1.688 0 0 0-.227-.272 1.467 1.467 0 0 0-.469-.324l-.008-.004A1.785 1.785 0 0 0 5.734 6C4.776 6 4 6.746 4 7.667c0 .92.776 1.666 1.734 1.666.343 0 .662-.095.931-.26-.137.389-.39.804-.81 1.22a.405.405 0 0 0 .011.59c.173.16.447.155.614-.01 1.334-1.329 1.37-2.758.941-3.706a2.461 2.461 0 0 0-.227-.4zM11 9.073c-.136.389-.39.804-.81 1.22a.405.405 0 0 0 .012.59c.172.16.446.155.613-.01 1.334-1.329 1.37-2.758.942-3.706a2.466 2.466 0 0 0-.228-.4 1.686 1.686 0 0 0-.227-.273 1.466 1.466 0 0 0-.469-.324l-.008-.004A1.785 1.785 0 0 0 10.07 6c-.957 0-1.734.746-1.734 1.667 0 .92.777 1.666 1.734 1.666.343 0 .662-.095.931-.26z"
|
||||
/>
|
||||
</symbol>
|
||||
</svg>
|
||||
{{ end }}
|
||||
|
|
|
@ -4,9 +4,69 @@
|
|||
{{ .Title }}
|
||||
{{ end }}
|
||||
|
||||
|
||||
<div class="bg-gray-500">
|
||||
{{ range .Bookmarks }}
|
||||
{{ . }}
|
||||
{{ define "content" }}
|
||||
{{ template "weatherIcons" . }}
|
||||
{{ if .Weather.Name }}
|
||||
<div class="flex items-center mb-6 md:mb-10 select-none">
|
||||
<svg class="w-20 h-20 md:w-14 md:h-14 mr-5">
|
||||
{{ range .Weather.Weather }}
|
||||
<use xlink:href="#{{ .Icon }}"></use>
|
||||
{{ end }}
|
||||
</svg>
|
||||
<div class="flex flex-col md:flex-row">
|
||||
<div class="text-4xl font-bold mr-8">{{ .Weather.Main.Temp }} {{ .Weather.Units }}</div>
|
||||
<div class="flex flex-col md:flex-row mt-1 text-sm text-slate-700 dark:text-slate-300">
|
||||
<div class="flex items-center md:mr-5">
|
||||
<svg width="14" height="14" class="mr-2">
|
||||
<use xlink:href="#quote"></use>
|
||||
</svg>
|
||||
{{ range .Weather.Weather }}
|
||||
{{ .Description }}
|
||||
{{ end }}
|
||||
</div>
|
||||
<div class="flex items-center md:mr-5">
|
||||
<svg width="14" height="14" class="mr-2">
|
||||
<use xlink:href="#humidity"></use>
|
||||
</svg>
|
||||
{{ .Weather.Main.Humidity }}%
|
||||
</div>
|
||||
<div class="hidden lg:flex items-center">
|
||||
<div class="flex items-center md:mr-5">
|
||||
<svg width="15" height="15" class="mr-2">
|
||||
<use xlink:href="#location"></use>
|
||||
</svg>
|
||||
{{ .Weather.Name }}
|
||||
</div>
|
||||
<div class="flex items-center md:mr-5">
|
||||
<svg width="18" height="18" class="mr-2 mt-1">
|
||||
<use xlink:href="#sunrise"></use>
|
||||
</svg>
|
||||
{{ .Weather.Sys.StrSunrise }}
|
||||
</div>
|
||||
<div class="flex items-center md:mr-5">
|
||||
<svg width="18" height="18" class="mr-2 mt-1">
|
||||
<use xlink:href="#sunset"></use>
|
||||
</svg>
|
||||
{{ .Weather.Sys.StrSunset }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
|
||||
<div class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6 gap-5">
|
||||
{{ range .Bookmarks }}
|
||||
<a
|
||||
href="{{ .Url }}"
|
||||
class="link flex items-center rounded-md hover:underline underline-offset-2 decoration-gray-500 text-sm text-slate-700 dark:text-slate-300 hover:text-slate-900 dark:hover:text-slate-50 ease-in duration-200"
|
||||
>
|
||||
<div class="img rounded-md w-8 h-8 bg-cover bg-center opacity-90" style="background-image: url({{ .Icon }})"></div>
|
||||
<div class="uppercase truncate ml-2">
|
||||
{{ .Name }}
|
||||
</div>
|
||||
</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
|
42
weather/types.go
Normal file
42
weather/types.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package weather
|
||||
|
||||
type Config struct {
|
||||
Location Location
|
||||
OpenWeather OpenWeather `mapstructure:"OPEN_WEATHER"`
|
||||
}
|
||||
|
||||
type Location struct {
|
||||
Latitude float32
|
||||
Longitude float32
|
||||
}
|
||||
|
||||
type OpenWeather struct {
|
||||
Key string
|
||||
Units string
|
||||
Lang string
|
||||
}
|
||||
|
||||
type OpenWeatherApiResponse struct {
|
||||
Weather []OpenWeatherApiWeather `json:"weather" `
|
||||
Main OpenWeatherApiMain `json:"main" `
|
||||
Sys OpenWeatherApiSys `json:"sys" `
|
||||
Name string `json:"name" `
|
||||
Units string `json:"units" `
|
||||
}
|
||||
|
||||
type OpenWeatherApiWeather struct {
|
||||
Description string `json:"description" `
|
||||
Icon string `json:"icon" `
|
||||
}
|
||||
|
||||
type OpenWeatherApiMain struct {
|
||||
Temp float32 `json:"temp" `
|
||||
Humidity float32 `json:"humidity" `
|
||||
}
|
||||
|
||||
type OpenWeatherApiSys struct {
|
||||
Sunrise int64 `json:"sunrise"`
|
||||
Sunset int64 `json:"sunset"`
|
||||
StrSunrise string
|
||||
StrSunset string
|
||||
}
|
62
weather/weather.go
Normal file
62
weather/weather.go
Normal file
|
@ -0,0 +1,62 @@
|
|||
package weather
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"io"
|
||||
"launchpad/config"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
var Conf = Config{}
|
||||
var CurrentOpenWeather = OpenWeatherApiResponse{}
|
||||
|
||||
func NewWeather() {
|
||||
config.ParseViperConfig(&Conf, config.AddViperConfig("weather"))
|
||||
if Conf.OpenWeather.Key != "" {
|
||||
setWeatherUnits()
|
||||
go updateWeather(time.Second * 150)
|
||||
}
|
||||
}
|
||||
|
||||
func setWeatherUnits() {
|
||||
if Conf.OpenWeather.Units == "imperial" {
|
||||
CurrentOpenWeather.Units = "°F"
|
||||
} else {
|
||||
CurrentOpenWeather.Units = "°C"
|
||||
}
|
||||
}
|
||||
|
||||
func calcTimestamps() {
|
||||
myTime := time.Unix(CurrentOpenWeather.Sys.Sunrise, 0)
|
||||
CurrentOpenWeather.Sys.StrSunrise = myTime.Format("15:04")
|
||||
myTime = time.Unix(CurrentOpenWeather.Sys.Sunset, 0)
|
||||
CurrentOpenWeather.Sys.StrSunset = myTime.Format("15:04")
|
||||
}
|
||||
|
||||
func updateWeather(interval time.Duration) {
|
||||
for {
|
||||
resp, err := http.Get(fmt.Sprintf("https://api.openweathermap.org/data/2.5/weather?lat=%f&lon=%f&appid=%s&units=%s&lang=%s",
|
||||
Conf.Location.Latitude,
|
||||
Conf.Location.Longitude,
|
||||
Conf.OpenWeather.Key,
|
||||
Conf.OpenWeather.Units,
|
||||
Conf.OpenWeather.Lang))
|
||||
if err != nil {
|
||||
logrus.Error("weather cannot be updated")
|
||||
} else {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
err = json.Unmarshal(body, &CurrentOpenWeather)
|
||||
if err != nil {
|
||||
logrus.Error("weather cannot be processed")
|
||||
} else {
|
||||
logrus.WithFields(logrus.Fields{"temp": fmt.Sprintf("%0.2f%s", CurrentOpenWeather.Main.Temp, CurrentOpenWeather.Units), "location": CurrentOpenWeather.Name}).Trace("weather updated")
|
||||
}
|
||||
calcTimestamps()
|
||||
resp.Body.Close()
|
||||
}
|
||||
time.Sleep(interval)
|
||||
}
|
||||
}
|
11
weather/weather.json
Normal file
11
weather/weather.json
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"location": {
|
||||
"latitude": 48.780331609463815,
|
||||
"longitude": 9.177968320179422
|
||||
},
|
||||
"open_weather": {
|
||||
"key": "",
|
||||
"units": "metric",
|
||||
"lang": "en"
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue