2015-08-12 08:53:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Alex Yatskov <alex@foosoft.net>
|
|
|
|
* Author: Alex Yatskov <alex@foosoft.net>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/PuerkitoBio/goquery"
|
|
|
|
)
|
|
|
|
|
2015-08-16 10:02:59 +00:00
|
|
|
type tabelog struct {
|
2015-08-12 08:53:53 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 10:12:16 +00:00
|
|
|
func (tabelog) index(doc *goquery.Document) (string, []string) {
|
2015-08-16 10:02:59 +00:00
|
|
|
var reviewUrls []string
|
|
|
|
doc.Find("div.list-rst__header > p > a").Each(func(index int, sel *goquery.Selection) {
|
|
|
|
if href, ok := sel.Attr("href"); ok {
|
|
|
|
reviewUrls = append(reviewUrls, href)
|
2015-08-12 11:29:45 +00:00
|
|
|
}
|
2015-08-16 10:02:59 +00:00
|
|
|
})
|
2015-08-12 11:29:45 +00:00
|
|
|
|
2015-08-16 10:02:59 +00:00
|
|
|
var nextIndexUrl string
|
|
|
|
if href, ok := doc.Find("a.c-pagination__target--next").Attr("href"); ok {
|
|
|
|
nextIndexUrl = href
|
2015-08-13 07:29:39 +00:00
|
|
|
}
|
2015-08-14 10:57:44 +00:00
|
|
|
|
2015-08-16 10:02:59 +00:00
|
|
|
return nextIndexUrl, reviewUrls
|
2015-08-14 07:40:37 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 10:12:16 +00:00
|
|
|
func (tabelog) profile(doc *goquery.Document) *review {
|
2015-08-16 10:02:59 +00:00
|
|
|
var r review
|
2015-08-12 11:29:45 +00:00
|
|
|
|
2015-08-16 10:02:59 +00:00
|
|
|
r.name = doc.Find("a.rd-header__rst-name-main").Text()
|
|
|
|
if addresses := doc.Find("p.rd-detail-info__rst-address"); addresses.Length() == 2 {
|
|
|
|
r.address = strings.TrimSpace(addresses.First().Text())
|
|
|
|
} else {
|
|
|
|
return nil
|
2015-08-12 11:29:45 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 10:02:59 +00:00
|
|
|
var err error
|
2015-08-16 10:30:45 +00:00
|
|
|
|
|
|
|
r.features = make(map[string]float64)
|
2015-08-16 10:02:59 +00:00
|
|
|
if r.features["dishes"], err = strconv.ParseFloat(doc.Find("#js-rating-detail > dd:nth-child(2)").Text(), 8); err != nil {
|
|
|
|
return nil
|
2015-08-12 08:53:53 +00:00
|
|
|
}
|
2015-08-16 10:02:59 +00:00
|
|
|
if r.features["service"], err = strconv.ParseFloat(doc.Find("#js-rating-detail > dd:nth-child(4)").Text(), 8); err != nil {
|
|
|
|
return nil
|
2015-08-12 08:53:53 +00:00
|
|
|
}
|
2015-08-16 10:02:59 +00:00
|
|
|
if r.features["atmosphere"], err = strconv.ParseFloat(doc.Find("#js-rating-detail > dd:nth-child(6)").Text(), 8); err != nil {
|
|
|
|
return nil
|
2015-08-12 08:53:53 +00:00
|
|
|
}
|
2015-08-16 10:02:59 +00:00
|
|
|
if r.features["cost"], err = strconv.ParseFloat(doc.Find("#js-rating-detail > dd:nth-child(8)").Text(), 8); err != nil {
|
|
|
|
return nil
|
2015-08-12 08:53:53 +00:00
|
|
|
}
|
2015-08-16 10:02:59 +00:00
|
|
|
if r.features["drinks"], err = strconv.ParseFloat(doc.Find("#js-rating-detail > dd:nth-child(10)").Text(), 8); err != nil {
|
|
|
|
return nil
|
2015-08-12 08:53:53 +00:00
|
|
|
}
|
|
|
|
|
2015-08-16 10:02:59 +00:00
|
|
|
return &r
|
2015-08-12 08:53:53 +00:00
|
|
|
}
|