Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
park4night
require 'json'
require 'open-uri'
require 'nokogiri'
GPX = <<-GPX
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<gpx
xmlns="http://www.topografix.com/GPX/1/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"
version="1.1"
creator="dmitry">
%s
</gpx>
GPX
WPT = <<-WPT
<wpt lat="%f" lon="%f">
<time>2020-07-31T15:51:00Z</time>
<name>%s</name>
<cmt>%s</cmt>
<desc>%s</desc>
<sym>%s</sym>
</wpt>
WPT
data = File.open('locations.gps').readlines.map do |line|
if line.size > 1
JSON.parse(line)['lieux']
else
[]
end
end.flatten.map do |item|
p item
page = open("https://www.park4night.com/?page=lieu&id=#{item['id']}&bulle=YES").read
#print page
description = Nokogiri(page).css('#desc_en').text
rating_content = Nokogiri(page).css('body > div > div:nth-child(2) > div:nth-child(2) > div:nth-child(1) > a > div:nth-child(1) > div.rating_fg')[0]
rating = if rating_content
rating_content['style'].match(/width:(.+?)px/).to_a[1]
end
comments_content = Nokogiri(page).css('body > div > div:nth-child(2) > div:nth-child(2) > div:nth-child(1) > a > div:nth-child(2) > span').text
comments_count = if comments_content
comments_content.match(/[0-9]+ comment/).to_a[1]
end
code = item['code']
photo_count = Nokogiri(page).css('body > div > div:nth-child(2) > div:nth-child(1) > a > div.indicateur > div').text
WPT % [item['latitude'], item['longitude'], code, code, "#{code}\r\n#{description}\r\nComments: #{comments_count}\r\nRating: #{rating}\r\nPhotos: #{photo_count}", code]
end
File.open('data.gpx', 'w') { |f| f.write(GPX % [data]) }
p 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment