Skip to content

Instantly share code, notes, and snippets.

@dmitry
Created August 1, 2020 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmitry/480915917612644e1f377b870e39269d to your computer and use it in GitHub Desktop.
Save dmitry/480915917612644e1f377b870e39269d to your computer and use it in GitHub Desktop.
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'
@RafaEstepona
Copy link

Hello, I would like to use your Park4night project, but I see that it uses a locations.gps file that does not come in the download zip. Is it possible to download this file from somewhere?

@dmitry
Copy link
Author

dmitry commented Feb 20, 2024

@RafaEstepona Park4night changed a lot since then. It was written more than 4 years ago, their site updated and the data isn't available anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment