Add places to Facebook imports

This commit is contained in:
JP Hastings-Spital 2024-05-01 20:56:38 +01:00
parent 53afa8001f
commit f7e723a41a
4 changed files with 83 additions and 2 deletions

View file

@ -22,4 +22,18 @@ vbuyylvkpwofvk6w5ljf52fofq
qewo2r2bmyayxaqwbgocdp7kb4
pmtarzxo6txmncvb7v2e7gycye
le5h6ori75na7w23ald3ly45qa
b2fcvdtovbazjpctyb6eyt7oze
b2fcvdtovbazjpctyb6eyt7oze
2ae7bof3qivs25v6xihoz42zza
aqcftuzb4kteqve6lluvhiewta
3vyrxpfyyuj4olq7ya4kgko7he
zlkpjo4sxqsbocej3nar5cw5kq
trmgu4muayrxcscn7bbcquozom
7sov3rxu3tqdi2t2dyfvyy35ge
bbwc5e4dlpt3q3kvh6yseq7uaa
pq4ukbww6klhvzyrzhsbzqzdf4
poieboac65bjxse3flxrthvgvu
pta3typpd67kehasqmaj7daifa
55g6wdoiejvcyxa5k6du42zkya
42zuekfsg6zkjm5hz67svw3zju
62jzsu3hz2zmb2i5etez4unm3m
niucmeeuibtxl2pk4xpulr36mi

View file

@ -122,6 +122,10 @@ func postize(e PostCheckinPhotoOrVideo, matches []string) (shared.Post, shared.M
post.Path = makePostPath("photo", postDate, postHash)
mm[path.Join(archiveRoot, mediaPath)] = path.Join(post.Path, mediaName)
}
if loc, ok := attach.Data.GetLocation(); ok {
post.FrontMatter.Location = loc
}
}
postFile, err := formatPostText(e.Data.GetString("post"), e.Tags)

View file

@ -1,6 +1,10 @@
package main
import "time"
import (
"time"
"github.com/by-jp/www.byjp.me/tools/shared"
)
type PostCheckinPhotoOrVideo struct {
Title string `json:"title"`
@ -82,3 +86,55 @@ func (ds DataSlice) GetSubstrings(key string, sub string) []string {
return substrs
}
func (ds DataSlice) GetLocation() (shared.Location, bool) {
for _, obj := range ds {
iface, ok := obj["place"]
if !ok {
continue
}
p, ok := iface.(map[string]interface{})
if !ok {
continue
}
nameI, nameOK := p["name"]
if !nameOK {
continue
}
name, ok := nameI.(string)
if !ok {
continue
}
coordsI, coordsOK := p["coordinate"]
if !coordsOK {
continue
}
coordsM, ok := coordsI.(map[string]interface{})
if !ok {
continue
}
lat, ok := coordsM["latitude"]
if !ok {
continue
}
lng, ok := coordsM["longitude"]
if !ok {
continue
}
return shared.Location{
Name: name,
Latitude: lat.(float64),
Longitude: lng.(float64),
}, true
}
return shared.Location{}, false
}

View file

@ -15,6 +15,13 @@ type FrontMatter struct {
RepostOf string `yaml:"repostOf,omitempty"`
References []Reference `yaml:"references,omitempty"`
Type string `yaml:"type,omitempty"`
Location Location `yaml:"location,omitempty"`
}
type Location struct {
Name string `yaml:"name"`
Latitude float64 `yaml:"latitude"`
Longitude float64 `yaml:"longitude"`
}
type Reference struct {