trippyplan 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dea3723f24a9fb9aa41e9c428e89493249f748da
4
+ data.tar.gz: e70c99f46d10442f89fee010c0b1f329d51985c8
5
+ SHA512:
6
+ metadata.gz: 36ed6d98908a8dee9b59b2ae6db4383939ba58af76922d18e2aeddfe5c45c25c21400b135abbecdc5d6fa97a5105935b93d925ddb57b35d7dd080165386b1106
7
+ data.tar.gz: 3c4dea0bde1b9cda5ca0ab8e420dba509e5cf2389ef29908c5657407604f264f7516b1f07df60ef744e97a59477b5c9498e49f78858c32bf6270440c46531165
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,14 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.2
5
+ before_install: gem install bundler -v 1.11.2
6
+ script: rake
7
+ deploy:
8
+ provider: rubygems
9
+ api_key:
10
+ secure: "JYWwX2XZ1sYlgzUTTI0L9SQ020PaAY4gb4MO1JTZsk0gkKUVfWxkRVXqeuRrJvGdw80r4nVgGhBaAotdDump334ezJkMhLgQof+VhQydzfRDGSCp9MhgGjpe64ZgPx27vEjjKhd50AQCVv4IS9HlYjmVMxA8/pRB0fMiP7H00HP+LWAjTFfvT1oI+Me4DI1CYFgNsre29srIf6ISQIcKn6eMR0xCLLh2eO8lCFkvc+kEtU/IL5B2NiTg841IEA1P9AEyqecQ9IHIMA8cVJo9KqCvjA99t6wNlsnuIcxjtZdZVf3bZjEUMliMjRXvJ2h26X2HePttjrMhWiZ9GR3IWf6o3VSYT8aR+41AQRlAWg1CBdpmQDXEwfI4pdux+cBZ0MvK1EvHXbD18jsLcRYewm0O0t57HXKRmVejIv0QKuAm42Omf4ymOKUqBP8/XQKfP+u3wtRUzLFJPLFDXD4NBJRZieRAsyUmeJWvHlGJwsfl3mY3UHcIJM9lNhIKBEA96B1KHjSLtxzdfdXOTHSZghmO2im6ANFWtoYzKS1SkqSdZftnGLNRF7EjpN24qanWwXTzgHU7iegHgCwMLySXd6W5d9pqzguzBe0TS6FgvzZ3dRUPdMaFnJG/j0uHVufV+rrhKXctrPc7D3sTQk2A9emMIdypMTSGw0Y4cVtnWo0="
11
+ gem: trippyplan
12
+ on:
13
+ tags: true
14
+ repo: pcboy/trippyplan
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at david.hagege@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in trippyplan.gemspec
4
+ gemspec
@@ -0,0 +1,115 @@
1
+ [![Build Status](https://travis-ci.org/pcboy/trippyplan.svg?branch=master)](https://travis-ci.org/pcboy/trippyplan)
2
+
3
+ # Trippyplan
4
+
5
+ Trippy plan helps you to plan your next trip by grouping attractions close to each other.
6
+
7
+ ## Installation
8
+
9
+ $ gem install trippyplan
10
+
11
+ ## Usage
12
+
13
+ ### TSV file support
14
+ Give a file `trips.tsv` following that format:
15
+ ```
16
+ Memorial des Martyrs de la Deportation <tab> Square de l'Ile de France, 75004 Paris France
17
+ Parc de Bercy <tab> Quay de Bercy, 75012 Paris France
18
+ Aquarium Tropical de la Porte Doree <tab> 293 avenue Daumesnil, 75012 Paris France
19
+ Musee d'Art et d'Histoire du Judaisme <tab> 71 rue du Temple Hôtel de Saint-Aignan, 75003 Paris France
20
+ Bercy Village <tab> Cour Saint-Emilion 28 rue François Truffaut, 75012 Paris France
21
+ ```
22
+
23
+ You can use trippyplan like this:
24
+ ```
25
+ $> trippyplan --tsv trips.tsv -d 3
26
+ Day 1:
27
+ Aquarium Tropical de la Porte Doree
28
+ Day 2:
29
+ Parc de Bercy
30
+ Bercy Village Cour Saint-Emilion
31
+ Day 3:
32
+ Memorial des Martyrs de la Deportation
33
+ Musee d'Art et d'Histoire du Judaisme
34
+ ```
35
+
36
+ ### Trip advisor saved trips support
37
+ trippyplan can directly fetch a list of places you saved for your trip already.
38
+ What you need to gives me is your cookie though.
39
+ To get that cookie:
40
+ - simply activate the developer tools in your browser (i.e right click, inspect) and go to the network tab and the XHR filter.
41
+ - go to your trip advisor saved trip url (should look something like https://www.tripadvisor.com/Saves/57292478)
42
+ - On the list of calls on the right find the one with just a number (in my case 57292478) and click on it
43
+ - You should now have on the right the request headers.
44
+ - What you need is the `X-Requested-By` value and the `Cookie` value. Create a file `cookie.yaml` and paste these values following that format:
45
+ ```
46
+ js_security_token: 'TNI1635!AO6YTYtm5C46HxKNQ8HdixmF7xMnk+SrVIEjyROUSajGaSHSrH0h/bjbR1qCEEifYhuOTktGYB29yWuy3Qsr8Gd/1MN4NN4MQTRSmFYsb4APQEsu6A2gNtX7nytOB8RSoBgBSz5FqoUNxjXU90eTq9i+zAqeX/EsgmJdPNn1gy/U'
47
+ cookie: 'TAUnique=%1%enc%3A%2FhBZMXFzVlmxR%2FK32EAYhU2jwwE8%2FgjJoTfLQq1%2BeLPqbL7B36alrg%3D%3D; ServerPool=A; TASSK=enc%3AAOkqsILPd%2F6vwdO2FBmMAlIPTLzn8ool0U1GN2xIChUD6Qko6gL5J%2Bdj%2FLCcYdVKPpY3r8EXNKVh8ltkWEwGBgsOBzcSPpcfe[...]'
48
+ ```
49
+
50
+ That's all. Now you can simply run trippyplan with the trip advisor option.
51
+ See example here with my 12 days trip to Paris:
52
+ ```
53
+ $> trippyplan -t https://www.tripadvisor.com/Saves/57292478 -r cookie.yaml -d 12
54
+ Day 1:
55
+ Aquarium Tropical de la Porte Doree
56
+ Day 2:
57
+ Le Jardin de Versailles
58
+ The Hall of Mirrors
59
+ Chateau de Versailles
60
+ L'Orangerie
61
+ Day 3:
62
+ Arc de Triomphe
63
+ Eiffel Tower
64
+ Day 4:
65
+ Latin Quarter
66
+ Saint Germain des Pres Quarter
67
+ Sainte-Chapelle
68
+ Musee du Louvre
69
+ Luxembourg Gardens
70
+ Day 5:
71
+ Montparnasse
72
+ Le Bon Marche Rive Gauche
73
+ The Catacombs
74
+ Day 6:
75
+ Centre Pompidou
76
+ Memorial de la Shoah (Shoah Memorial)
77
+ Musee d'Art et d'Histoire du Judaisme
78
+ Notre Dame Cathedral
79
+ Ile de la Cite
80
+ Memorial des Martyrs de la Deportation
81
+ Le Marais
82
+ Ile Saint-Louis
83
+ Les Halles
84
+ Rue Montorgueil
85
+ Day 7:
86
+ Bercy Village
87
+ Parc de Bercy
88
+ Day 8:
89
+ Le Quartier de la Butte Aux Cailles a Paris
90
+ Day 9:
91
+ Basilica du Sacre-Coeur de Montmartre
92
+ Montmartre
93
+ Day 10:
94
+ Jardin des Tuileries
95
+ Place de la Concorde
96
+ Musee de l'Orangerie
97
+ Musee d'Orsay
98
+ Galeries Lafayette
99
+ Day 11:
100
+ Grand Palais
101
+ Champs-Elysees
102
+ Grands Boulevards
103
+ Rue du Faubourg Saint-Honore
104
+ Day 12:
105
+ Bastille Market
106
+ Place des Vosges
107
+ Place de la Bastille
108
+ Place de la Republique
109
+ Canal Saint-Martin
110
+ ```
111
+
112
+ ## Contributing
113
+
114
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pcboy/trippyplan. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
115
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "trippyplan"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'trippyplan'
4
+ require 'trollop'
5
+ require 'active_support/core_ext/object/try'
6
+ require 'active_support/core_ext/object/blank'
7
+
8
+ opts = Trollop::options do
9
+ opt :tripadvisor_url, "URL to your tripadvisor trip page (e.g https://www.tripadvisor.com/Saves/57292478)", type: :string
10
+ opt :tripadvisor_cookiefile, "Used in conjonction with --tripadvisor-url (see README)", type: :string
11
+ opt :tsv, "A TSV file (format: attraction_name<tab>address . see README)", type: :string
12
+ opt :days, "Will group your attractions in that number of groups, usually that's almost the same as your number of vacation days", default: 7
13
+ stop_on_unknown
14
+ end
15
+
16
+ Trollop.educate unless opts[:tripadvisor_url] || opts[:tsv]
17
+ abort "You need to specify --tripadvisor_cookiefile" if opts[:tripadvisor_url] && opts[:tripadvisor_cookiefile].blank?
18
+
19
+ list_id = /https:\/\/www.tripadvisor.com\/Saves\/(\d+)/.match(opts[:tripadvisor_url]).try(:captures).try(:first).try(:to_i)
20
+
21
+ clusters = if opts[:tripadvisor_url]
22
+ Trippyplan::Trippyplan.new(opts[:days], advisor: { headers: opts[:tripadvisor_cookiefile], list: list_id }).clusterize
23
+ else
24
+ Trippyplan::Trippyplan.new(opts[:days], tsv: opts[:tsv]).clusterize
25
+ end
26
+ clusters.each do |cluster|
27
+ puts "Day #{cluster.id + 1}:\n"
28
+ puts "\t#{cluster.points.map(&:label).join("\n\t")}"
29
+ end
@@ -0,0 +1,54 @@
1
+ require "trippyplan/version"
2
+
3
+ require 'geocoder'
4
+ require 'kmeans-clusterer'
5
+ require 'yaml'
6
+ require 'rest-client'
7
+
8
+ module Trippyplan
9
+ class Trippyplan
10
+ def initialize(days, tsv: nil, advisor: nil)
11
+ @days = days
12
+ if tsv
13
+ @addresses = File.read(tsv).split("\n").map{|x| x.split("\t")}.map{|x| {x[0] => x[1]}}.reduce(:merge)
14
+ @addresses = addresses_to_coords(@addresses)
15
+ end
16
+ if advisor && advisor[:list]
17
+ headers = YAML.load_file(advisor[:headers])
18
+ abort "Your cookie file does not contain the necessary info. See README for example" unless (['cookie', 'js_security_token'] - headers.keys).empty?
19
+ body = RestClient.get("https://www.tripadvisor.com/data/1.0/trips/list/#{advisor[:list]}",
20
+ {
21
+ :Cookie => headers['cookie'],
22
+ 'X-Requested-By' => headers['js_security_token'],
23
+ }
24
+ )
25
+ @addresses = advisor_to_coords(body)
26
+ end
27
+ end
28
+
29
+ def clusterize
30
+ kmeans = KMeansClusterer.run @days, @addresses.values, labels: @addresses.keys, runs: 10
31
+ kmeans.clusters
32
+ end
33
+
34
+ private
35
+
36
+ def advisor_to_coords(body)
37
+ json = JSON.parse(body)
38
+ json['nodes'].map do |n|
39
+ content = n['content']
40
+ { content['name'] => [content['latitude'], content['longitude']].map(&:to_f) }
41
+ end.reduce(:merge)
42
+ end
43
+
44
+ def addresses_to_coords(addresses)
45
+ addresses.map do |label, address|
46
+ if coord = Geocoder.search(address).first
47
+ { label => coord.data['geometry']['location'].values.map(&:to_f) }
48
+ else
49
+ abort "can't find coordinates of #{address}"
50
+ end
51
+ end.reduce(:merge)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module Trippyplan
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'trippyplan/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "trippyplan"
8
+ spec.version = Trippyplan::VERSION
9
+ spec.authors = ["David Hagege"]
10
+ spec.email = ["david.hagege@gmail.com"]
11
+
12
+ spec.summary = %q{trippyplan helps you plan your next trip}
13
+ spec.description = %q{Trippy plan helps you to plan your next trip by grouping attractions close to each other.}
14
+ spec.homepage = "https://github.com/pcboy/trippyplan"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.11"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest", "~> 5.0"
24
+ spec.add_development_dependency "rspec", "~> 3.4"
25
+
26
+ spec.add_dependency "geocoder", "~> 1.4"
27
+ spec.add_dependency "kmeans-clusterer", "~> 0.11"
28
+ spec.add_dependency "rest-client", "~> 2.0"
29
+ spec.add_dependency "activesupport", "~> 4.2"
30
+ spec.add_dependency "trollop", "~> 2.1"
31
+
32
+ spec.license = 'WTFPL'
33
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trippyplan
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - David Hagege
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: geocoder
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.4'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: kmeans-clusterer
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.11'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.11'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rest-client
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.2'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.2'
125
+ - !ruby/object:Gem::Dependency
126
+ name: trollop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.1'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.1'
139
+ description: Trippy plan helps you to plan your next trip by grouping attractions
140
+ close to each other.
141
+ email:
142
+ - david.hagege@gmail.com
143
+ executables:
144
+ - trippyplan
145
+ extensions: []
146
+ extra_rdoc_files: []
147
+ files:
148
+ - ".gitignore"
149
+ - ".travis.yml"
150
+ - CODE_OF_CONDUCT.md
151
+ - Gemfile
152
+ - README.md
153
+ - Rakefile
154
+ - bin/console
155
+ - bin/setup
156
+ - exe/trippyplan
157
+ - lib/trippyplan.rb
158
+ - lib/trippyplan/version.rb
159
+ - trippyplan.gemspec
160
+ homepage: https://github.com/pcboy/trippyplan
161
+ licenses:
162
+ - WTFPL
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.4.8
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: trippyplan helps you plan your next trip
184
+ test_files: []