movies_client 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,17 +1,17 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in movies_client.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in movies_client.gemspec
4
+ gemspec
data/LICENSE.txt CHANGED
@@ -1,22 +1,22 @@
1
- Copyright (c) 2014 jeanbaptistevilain
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2014 jeanbaptistevilain
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,29 +1,29 @@
1
- # MoviesClient
2
-
3
- TODO: Write a gem description
4
-
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'movies_client'
10
-
11
- And then execute:
12
-
13
- $ bundle
14
-
15
- Or install it yourself as:
16
-
17
- $ gem install movies_client
18
-
19
- ## Usage
20
-
21
- TODO: Write usage instructions here
22
-
23
- ## Contributing
24
-
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
1
+ # MoviesClient
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'movies_client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install movies_client
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,274 @@
1
+ #encoding: UTF-8
2
+
3
+ require "roo"
4
+ require "spreadsheet"
5
+
6
+ class ScheduleParser
7
+
8
+ def self.parse_ods(path)
9
+ #open ods file with UTF_8 encoding option
10
+ s = Roo::OpenOffice.new(path, ods_options: {encoding: Encoding::UTF_8})
11
+
12
+ @result = {}
13
+ @daily_schedule = {}
14
+ day = {}
15
+ film = {}
16
+ lastrow = s.last_row
17
+ lastcolumn = s.last_column
18
+ y = 2
19
+
20
+ @result[:mois] = s.cell(1,3)
21
+ @result[:cinema1] = s.cell(1,2)
22
+ @result[:cinema2] = s.cell(1,5)
23
+
24
+ while y != lastrow do
25
+ x = 1
26
+
27
+ while x != lastcolumn+1 do
28
+
29
+ value = s.cell(y,x)
30
+
31
+ if s.cell(y, 3).nil?
32
+ key = s.cell(y-1, 3).gsub(/[^\d]/, '').to_s
33
+ flagline = true # second line of a date
34
+ else
35
+ key = s.cell(y, 3).gsub(/[^\d]/, '').to_s
36
+ flagline = false #first line of a date
37
+ end
38
+
39
+ case x
40
+ when 1
41
+ if flagline
42
+ day[:horaire2] = value
43
+ else
44
+ day[:horaire1] = value
45
+ end
46
+ when 2
47
+ if flagline
48
+ day[:film3] = value
49
+ unless film.has_key?(value)
50
+ unless value.nil?
51
+ if value.include? ':'
52
+ value.sub!(':', ' ')
53
+ end
54
+ if value.include? "'"
55
+ value.sub!("'", ' ')
56
+ end
57
+ if value.include? ","
58
+ value.sub!(",", '')
59
+ end
60
+ value_escaped = CGI::escape(value)
61
+ film.store(value,[value_escaped])
62
+ end
63
+ end
64
+ else
65
+ day[:film1] = value
66
+ unless film.has_key?(value)
67
+ unless value.nil?
68
+ if value.include? ':'
69
+ value.sub!(':', ' ')
70
+ end
71
+ if value.include? "'"
72
+ value.sub!("'", ' ')
73
+ end
74
+ if value.include? ","
75
+ value.sub!(",", '')
76
+ end
77
+ value_escaped = CGI::escape(value)
78
+ film.store(value,[value_escaped])
79
+ end
80
+ end
81
+ end
82
+ when 3
83
+ unless flagline
84
+ day[:date] = value
85
+ end
86
+ when 5
87
+ if flagline
88
+ day[:film4] = value
89
+ unless film.has_key?(value)
90
+ unless value.nil?
91
+ if value.include? ':'
92
+ value.sub!(':', ' ')
93
+ end
94
+ if value.include? "'"
95
+ value.sub!("'", ' ')
96
+ end
97
+ if value.include? ","
98
+ value.sub!(",", '')
99
+ end
100
+ value_escaped = CGI::escape(value)
101
+ film.store(value,[value_escaped])
102
+ end
103
+ end
104
+ else
105
+ day[:film2] = value
106
+ unless film.has_key?(value)
107
+ unless value.nil?
108
+ if value.include? ':'
109
+ value.sub!(':', ' ')
110
+ end
111
+ if value.include? "'"
112
+ value.sub!("'", ' ')
113
+ end
114
+ if value.include? ","
115
+ value.sub!(",", '')
116
+ end
117
+ value_escaped = CGI::escape(value)
118
+ film.store(value,[value_escaped])
119
+ end
120
+ end
121
+ end
122
+ else
123
+ # case ignored
124
+ end
125
+ x += 1
126
+ end
127
+ @daily_schedule[key] = day
128
+ if flagline
129
+ day = {}
130
+ end
131
+ y +=1
132
+ end
133
+ @result[:daily_schedule] = @daily_schedule
134
+ @result[:result] = film
135
+ @result
136
+ end
137
+
138
+ def self.parse_ods_with_day(path, date)
139
+ s = Roo::OpenOffice.new(path, ods_options: {encoding: Encoding::UTF_8})
140
+
141
+ @result = {}
142
+ @daily_schedule = {}
143
+ day = {}
144
+ film = {}
145
+ lastrow = s.last_row
146
+ lastcolumn = s.last_column
147
+ y = 2 # Start on line 2 to avoid header
148
+
149
+ @result[:mois] = s.cell(1,3)
150
+ @result[:cinema1] = s.cell(1,2)
151
+ @result[:cinema2] = s.cell(1,5)
152
+
153
+ while y != lastrow do
154
+ x = 1
155
+
156
+ while x != lastcolumn+1 do
157
+
158
+ value = s.cell(y,x)
159
+
160
+ if s.cell(y, 3).nil?
161
+ key = s.cell(y-1, 3).gsub(/[^\d]/, '').to_s
162
+ flagline = true # second line of a date
163
+ else
164
+ key = s.cell(y, 3).gsub(/[^\d]/, '').to_s
165
+ flagline = false #first line of a date
166
+ end
167
+
168
+ case key
169
+ when date
170
+ case x
171
+ when 1
172
+ if flagline
173
+ day[:horaire2] = value
174
+ else
175
+ day[:horaire1] = value
176
+ end
177
+ when 2
178
+ if flagline == false
179
+ day[:film1] = value
180
+ unless film.has_key?(value)
181
+ unless value.nil?
182
+ if value.include? ':'
183
+ value.sub!(':', ' ')
184
+ end
185
+ if value.include? "'"
186
+ value.sub!("'", ' ')
187
+ end
188
+ if value.include? ","
189
+ value.sub!(",", '')
190
+ end
191
+ value_escaped = CGI::escape(value)
192
+ film.store(value,[value_escaped])
193
+ end
194
+ end
195
+ elsif flagline == true
196
+ day[:film3] = value
197
+ unless film.has_key?(value)
198
+ unless value.nil?
199
+ if value.include? ':'
200
+ value.sub!(':', ' ')
201
+ end
202
+ if value.include? "'"
203
+ value.sub!("'", ' ')
204
+ end
205
+ if value.include? ","
206
+ value.sub!(",", '')
207
+ end
208
+ value_escaped = CGI::escape(value)
209
+ film.store(value,[value_escaped])
210
+ end
211
+ end
212
+ end
213
+ when 3
214
+ unless flagline == true
215
+ day[:date] = value
216
+ end
217
+ when 5
218
+ if flagline == false
219
+ day[:film2] = value
220
+ unless film.has_key?(value)
221
+ unless value.nil?
222
+ if value.include? ':'
223
+ value.sub!(':', ' ')
224
+ end
225
+ if value.include? "'"
226
+ value.sub!("'", ' ')
227
+ end
228
+ if value.include? ","
229
+ value.sub!(",", '')
230
+ end
231
+ value_escaped = CGI::escape(value)
232
+ film.store(value,[value_escaped])
233
+ end
234
+ end
235
+ elsif flagline == true
236
+ day[:film4] = value
237
+ unless film.has_key?(value)
238
+ unless value.nil?
239
+ if value.include? ':'
240
+ value.sub!(':', ' ')
241
+ end
242
+ if value.include? "'"
243
+ value.sub!("'", ' ')
244
+ end
245
+ if value.include? ","
246
+ value.sub!(",", '')
247
+ end
248
+ value_escaped = CGI::escape(value)
249
+ film.store(value,[value_escaped])
250
+ end
251
+ end
252
+ end
253
+ else
254
+ # cellule non traitée
255
+ end
256
+ else
257
+ # date non traitée
258
+ end
259
+ x += 1
260
+ end
261
+ unless day[:date].nil?
262
+ @daily_schedule.store( key, day)
263
+ end
264
+ if flagline
265
+ day = {}
266
+ end
267
+ y +=1
268
+ end
269
+ @result.store( :daily_schedule, @daily_schedule)
270
+ @result.store( :result, film)
271
+ @result
272
+ end
273
+
274
+ end
@@ -0,0 +1,96 @@
1
+ #encoding: UTF-8
2
+
3
+ require "themoviedb"
4
+
5
+ class TmdbClient
6
+
7
+ def self.get_movie_details(id, api_key)
8
+ Tmdb::Api.key(api_key)
9
+ Tmdb::Api.language("fr")
10
+ movie = Tmdb::Movie.detail(id)
11
+ movie
12
+ end
13
+
14
+ def self.get_id_from_title(title, api_key)
15
+ Tmdb::Api.key(api_key)
16
+ Tmdb::Api.language("fr")
17
+ search = Tmdb::Search.new
18
+ search.resource('movie')
19
+ search.query(title)
20
+ movie = search.fetch
21
+ if movie.nil?
22
+ puts title
23
+ else
24
+ f = movie.length
25
+ i = 0
26
+ while i != f
27
+ unless movie[i][:release_date] == ''
28
+ date = Date.parse movie[i][:release_date]
29
+ if date.year == Date.today.year or date.year == Date.today.prev_year
30
+ movie_id = movie[i][:id]
31
+ else
32
+ movie_id = movie[0][:id]
33
+ end
34
+ end
35
+ i += 1
36
+ end
37
+ movie_id
38
+ end
39
+ end
40
+
41
+ def self.get_trailer(id, api_key)
42
+ Tmdb::Api.key(api_key)
43
+ Tmdb::Api.language("fr")
44
+ trailer = Tmdb::Movie.trailers(id)
45
+ link = ''
46
+ unless trailer["youtube"][0].nil?
47
+ source = trailer["youtube"][0]["source"]
48
+ link = 'https://www.youtube.com/watch?v='+source.to_s
49
+ end
50
+ link
51
+ end
52
+
53
+ def self.get_credits(id, api_key)
54
+ Tmdb::Api.key(api_key)
55
+ Tmdb::Api.language("fr")
56
+ credit = Tmdb::Movie.credits(id)
57
+ credits = {}
58
+ cred = {}
59
+ credit["crew"].each do |r|
60
+ key = r["job"]
61
+ value = r["name"]
62
+ if cred.has_key?(key)
63
+ cred[key] << value
64
+ else
65
+ cred.store(key, [value])
66
+ end
67
+ end
68
+ credits.store(:credit, cred)
69
+ credits
70
+ end
71
+
72
+ def self.get_movie_casts(id, api_key)
73
+ Tmdb::Api.key(api_key)
74
+ Tmdb::Api.language("fr")
75
+ casts = Tmdb::Movie.casts(id)
76
+ casting = {}
77
+ actor = {}
78
+ i = 0
79
+ if casts.nil?
80
+ actor = 'casting non disponible'
81
+ casting = actor
82
+ else
83
+ while i < 3
84
+ unless casts[i].nil?
85
+ actor[:role] = casts[i]["character"]
86
+ actor[:name] = casts[i]["name"]
87
+ end
88
+ casting.store(i, actor)
89
+ actor = {}
90
+ i += 1
91
+ end
92
+ end
93
+ casting
94
+ end
95
+
96
+ end
@@ -1,3 +1,3 @@
1
1
  module MoviesClient
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end