hemnetparser

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2020 License: MIT Imports: 11 Imported by: 0

README

CircleCI GoDoc Go Report Card

Hemnet Parser

Library and a simple commandline to parse information from Hemnet URL to JSON, XML or update it to Google sheet.

Library

Install
go get -u github.com/ledongthuc/hemnetparser
Usage
Parse data to JSON/XML:
func main() {
	output, err := hemnetparser.Parse("https://www.hemnet.se/bostad/lagenhet-2rum-bromma-beckomberga-stockholms-kommun-agatvagen-26-16065891")
	if err != nil {
		panic(err)
	}

	fmt.Println(output.ToJSON())
	fmt.Println(output.ToXML())
}
Parse and update to google sheet:
type Configuration struct {
}
	googlesheet.Process(googlesheet.Configuration{
	GoogleCredentialPath: "credentials.json" ,
	SpreadsheetID      : "1S0Xzpl_a3SFGnkFWCw7M1t_NXa2VZV42Lxh70G9PTlo" ,

})

You can check full configuration at: https://github.com/ledongthuc/hemnetparser/blob/master/googlesheet/sheet.go#L32

Commandline

Install
go get -u github.com/ledongthuc/hemnetparser/cmd/hemnet-parser
Usage
Parse data to JSON
hemnet-parser --format=json https://www.hemnet.se/bostad/lagenhet-2rum-bromma-beckomberga-stockholms-kommun-agatvagen-26-16065891
Parse data to XML
hemnet-parser --format=xml https://www.hemnet.se/bostad/lagenhet-2rum-bromma-beckomberga-stockholms-kommun-agatvagen-26-16065891
Parse data and update to Google sheet
hemnet-parser --format=googlesheet --credential=credentials.json --sheet-id=1S0Xzpl_a3SFGnkFWCw7M1t_NXa2VZV42Lxh70G9PTlo --skipheader=1``

credential: Turn on Google Sheet APIs and download credentials.json from https://developers.google.com/sheets/api/quickstart/go

sheet-id: https://developers.google.com/sheets/api/guides/concepts

Before run: Before

After run: After

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFloat64

func GetFloat64(val *float64) float64

GetFloat64 get value of pointer or empty value

func GetString

func GetString(val *string) string

GetString get value of pointer or empty value

func PtrFloat64

func PtrFloat64(val float64) *float64

PtrFloat64 get pointer of value float64

func PtrString

func PtrString(val string) *string

PtrString get pointer of value string

func StringValueOrNil

func StringValueOrNil(val string) *string

StringValueOrNil convert empty if it's nil

Types

type AreaDetail

type AreaDetail struct {
	PostalCity   *string `json:"postal_city,omitempty"`
	Municipality *string `json:"municipality,omitempty"`
	County       *string `json:"county,omitempty"`
	Country      *string `json:"country,omitempty"`
}

AreaDetail define area information such as city, county or country

type Output

type Output struct {
	URL                     string     `json:"url,omitempty"`
	StreetName              *string    `json:"street_name,omitempty"`
	Area                    *string    `json:"area,omitempty"`
	AreaDetail              AreaDetail `json:"area_detail"`
	ConstructionYear        *string    `json:"construction_year,omitempty"`
	NumberOfRooms           *float64   `json:"number_of_rooms,omitempty"`
	LivingArea              *float64   `json:"living_area,omitempty"`
	Borattavgift            *float64   `json:"borattavgift,omitempty"`
	Driftkostnad            *float64   `json:"driftkostnad,omitempty"`
	Price                   *float64   `json:"price,omitempty"`
	PricePerM2              *float64   `json:"price_per_m_2,omitempty"`
	SellingPrice            *float64   `json:"selling_price,omitempty"`
	DevelopmentPrice        *float64   `json:"development_price,omitempty"`
	DevelopmentPricePercent *float64   `json:"development_price_percent,omitempty"`
	HousingForm             *string    `json:"housing_form,omitempty"`
	Tenure                  *string    `json:"tenure,omitempty"`
	Status                  Status     `json:"status,omitempty"`
}

Output is parsed output from library

func Parse

func Parse(url string) (Output, error)

Parse parses information from URL to output object

func (*Output) CalculateDevelopment

func (o *Output) CalculateDevelopment()

func (Output) ToJSON

func (o Output) ToJSON() ([]byte, error)

ToJSON convert output object to JSON

func (Output) ToXML

func (o Output) ToXML() ([]byte, error)

ToXML convert output object to JSON

type Status

type Status string
const (
	StatusDeactived  Status = "Deactivated"
	StatusSold       Status = "Sold"
	StatusProcessing Status = "Processing"
)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL