Created
August 1, 2020 16:16
-
-
Save dmitry/480915917612644e1f377b870e39269d to your computer and use it in GitHub Desktop.
Revisions
-
dmitry created this gist
Aug 1, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ 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'