add url to places

This commit is contained in:
Ted Unangst 2019-09-29 16:07:35 -04:00
parent 409d1e9932
commit 0d0a5677a0
9 changed files with 18 additions and 10 deletions

View File

@ -700,6 +700,7 @@ func xonkxonk(user *WhatAbout, item junk.Junk, origin string) *Honk {
p.Name = name p.Name = name
p.Latitude, _ = tag["latitude"].(float64) p.Latitude, _ = tag["latitude"].(float64)
p.Longitude, _ = tag["longitude"].(float64) p.Longitude, _ = tag["longitude"].(float64)
p.Url, _ = tag.GetString("url")
log.Printf("place: %v", p) log.Printf("place: %v", p)
xonk.Place = p xonk.Place = p
} }
@ -931,6 +932,7 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) {
t["name"] = p.Name t["name"] = p.Name
t["latitude"] = p.Latitude t["latitude"] = p.Latitude
t["longitude"] = p.Longitude t["longitude"] = p.Longitude
t["url"] = p.Url
tags = append(tags, t) tags = append(tags, t)
} }
if len(tags) > 0 { if len(tags) > 0 {

View File

@ -251,7 +251,7 @@ func donksforhonks(honks []*Honk) {
} }
rows.Close() rows.Close()
// grab places // grab places
q = fmt.Sprintf("select honkid, name, latitude, longitude from places where honkid in (%s)", strings.Join(ids, ",")) q = fmt.Sprintf("select honkid, name, latitude, longitude, url from places where honkid in (%s)", strings.Join(ids, ","))
rows, err = db.Query(q) rows, err = db.Query(q)
if err != nil { if err != nil {
log.Printf("error querying places: %s", err) log.Printf("error querying places: %s", err)
@ -261,7 +261,7 @@ func donksforhonks(honks []*Honk) {
for rows.Next() { for rows.Next() {
var hid int64 var hid int64
p := new(Place) p := new(Place)
err = rows.Scan(&hid, &p.Name, &p.Latitude, &p.Longitude) err = rows.Scan(&hid, &p.Name, &p.Latitude, &p.Longitude, &p.Url)
if err != nil { if err != nil {
log.Printf("error scanning place: %s", err) log.Printf("error scanning place: %s", err)
continue continue
@ -303,10 +303,10 @@ func saveextras(h *Honk) error {
return err return err
} }
} }
if h.Place != nil { if p := h.Place; p != nil {
_, err := stmtSavePlace.Exec(h.ID, h.Place.Name, h.Place.Latitude, h.Place.Longitude) _, err := stmtSavePlace.Exec(h.ID, p.Name, p.Latitude, p.Longitude, p.Url)
if err != nil { if err != nil {
log.Printf("error saving ont: %s", err) log.Printf("error saving place: %s", err)
return err return err
} }
} }
@ -419,7 +419,7 @@ func prepareStatements(db *sql.DB) {
stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore, format, precis, oonker, flags) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") stmtSaveHonk = preparetodie(db, "insert into honks (userid, what, honker, xid, rid, dt, url, audience, noise, convoy, whofore, format, precis, oonker, flags) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
stmtDeleteHonk = preparetodie(db, "delete from honks where honkid = ?") stmtDeleteHonk = preparetodie(db, "delete from honks where honkid = ?")
stmtUpdateHonk = preparetodie(db, "update honks set precis = ?, noise = ?, format = ?, dt = ? where honkid = ?") stmtUpdateHonk = preparetodie(db, "update honks set precis = ?, noise = ?, format = ?, dt = ? where honkid = ?")
stmtSavePlace = preparetodie(db, "insert into places (honkid, name, latitude, longitude) values (?, ?, ?, ?)") stmtSavePlace = preparetodie(db, "insert into places (honkid, name, latitude, longitude, url) values (?, ?, ?, ?, ?)")
stmtDeletePlace = preparetodie(db, "delete from places where honkid = ?") stmtDeletePlace = preparetodie(db, "delete from places where honkid = ?")
stmtSaveOnt = preparetodie(db, "insert into onts (ontology, honkid) values (?, ?)") stmtSaveOnt = preparetodie(db, "insert into onts (ontology, honkid) values (?, ?)")
stmtDeleteOnts = preparetodie(db, "delete from onts where honkid = ?") stmtDeleteOnts = preparetodie(db, "delete from onts where honkid = ?")

View File

@ -92,6 +92,7 @@ type Place struct {
Name string Name string
Latitude float64 Latitude float64
Longitude float64 Longitude float64
Url string
} }
type Honker struct { type Honker struct {

View File

@ -8,7 +8,7 @@ create table zonkers (zonkerid integer primary key, userid integer, name text, w
create table doovers(dooverid integer primary key, dt text, tries integer, username text, rcpt text, msg blob); create table doovers(dooverid integer primary key, dt text, tries integer, username text, rcpt text, msg blob);
create table onts (ontology text, honkid integer); create table onts (ontology text, honkid integer);
create table forsaken (honkid integer, precis text, noise text); create table forsaken (honkid integer, precis text, noise text);
create table places (honkid integer, name text, latitude real, longitude real); create table places (honkid integer, name text, latitude real, longitude real, url text);
create index idx_honksxid on honks(xid); create index idx_honksxid on honks(xid);
create index idx_honksconvoy on honks(convoy); create index idx_honksconvoy on honks(convoy);

View File

@ -188,8 +188,11 @@ func upgradedb() {
case 19: case 19:
doordie(db, "create table places (honkid integer, name text, latitude real, longitude real)") doordie(db, "create table places (honkid integer, name text, latitude real, longitude real)")
doordie(db, "create index idx_placehonkid on places(honkid)") doordie(db, "create index idx_placehonkid on places(honkid)")
doordie(db, "update config set value = 20 where key = 'dbversion'")
case 20: case 20:
doordie(db, "alter table places add column url text")
doordie(db, "update places set url = ''")
doordie(db, "update config set value = 21 where key = 'dbversion'")
case 21:
default: default:
log.Fatalf("can't upgrade unknown version %d", dbversion) log.Fatalf("can't upgrade unknown version %d", dbversion)
} }

View File

@ -72,7 +72,7 @@ var dbtimeformat = "2006-01-02 15:04:05"
var alreadyopendb *sql.DB var alreadyopendb *sql.DB
var dbname = "honk.db" var dbname = "honk.db"
var stmtConfig *sql.Stmt var stmtConfig *sql.Stmt
var myVersion = 20 var myVersion = 21
func initdb() { func initdb() {
schema, err := ioutil.ReadFile("schema.sql") schema, err := ioutil.ReadFile("schema.sql")

View File

@ -43,7 +43,7 @@ in reply to: <a href="{{ .RID }}" rel=noreferrer>{{ .RID }}</a>
<p>{{ .HTPrecis }} <p>{{ .HTPrecis }}
<p>{{ .HTML }} <p>{{ .HTML }}
{{ with .Place }} {{ with .Place }}
<p>Location: {{ .Name }} <a href="https://www.openstreetmap.org/?mlat={{ .Latitude }}&mlon={{ .Longitude}}">{{ .Latitude }} {{ .Longitude }}</a> <p>Location: {{ with .Url }}<a href="{{ . }}" rel=noreferrer>{{ end }}{{ .Name }}{{ if .Url }}</a>{{ end }} <a href="https://www.openstreetmap.org/?mlat={{ .Latitude }}&mlon={{ .Longitude}}" rel=noreferrer>{{ .Latitude }} {{ .Longitude }}</a>
{{ end }} {{ end }}
{{ range .Donks }} {{ range .Donks }}
{{ if .Local }} {{ if .Local }}

View File

@ -13,6 +13,7 @@ description: <input type="text" name="donkdesc" value="{{ .DonkDesc }}" autocomp
<p><button id=checkinbutton type=button onclick="fillcheckin()">checkin</button> <p><button id=checkinbutton type=button onclick="fillcheckin()">checkin</button>
<div id=placedescriptor style="display: none"> <div id=placedescriptor style="display: none">
<p>name: <input type="text" name="placename" id=placenameinput value=""> <p>name: <input type="text" name="placename" id=placenameinput value="">
<p>url: <input type="text" name="placeurl" id=placeurlinput value="">
<p>latitude: <input type="text" name="placelat" id=placelatinput value=""> <p>latitude: <input type="text" name="placelat" id=placelatinput value="">
<p>longitude: <input type="text" name="placelong" id=placelonginput value=""> <p>longitude: <input type="text" name="placelong" id=placelonginput value="">
</div> </div>

1
web.go
View File

@ -1047,6 +1047,7 @@ func submithonk(w http.ResponseWriter, r *http.Request) {
p.Name = placename p.Name = placename
p.Latitude, _ = strconv.ParseFloat(placelat, 64) p.Latitude, _ = strconv.ParseFloat(placelat, 64)
p.Longitude, _ = strconv.ParseFloat(placelong, 64) p.Longitude, _ = strconv.ParseFloat(placelong, 64)
p.Url = r.FormValue("placeurl")
honk.Place = p honk.Place = p
} }