lita-vrt-mess 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e196b73cf8e2e0f13a3a1504b501d43622b6fd63b5c51eb3a3f23578e2acd34
4
- data.tar.gz: 047b9b58cee9ca7af170eedea3133cdb75afac26dc77e9a27e9a32306fe9bbd3
3
+ metadata.gz: c91d5545b5af6b732a206248e291f15794a65ac921fe3cc7e342483ff42a22bd
4
+ data.tar.gz: e1883d02cfeb3713f300247db900a9027582b701db04c01f8610a002a402a2ba
5
5
  SHA512:
6
- metadata.gz: e309ee698bf797f030d42d892accee8b1c9aa649aafd509f9660ea702dfa7e97df114b3c2d5b52410a9dd8338a9b6589c145532d6d0f027bb3a97df76b5de9d1
7
- data.tar.gz: 7637dbbe0f9e97f2e105af7ea0af62fa3fab3a4dcb866da6a1d7041283c73c431514cfe9e7fa85bd3f1da5d7ab8684799ab27f3b177fb914997bccd88bf377bd
6
+ metadata.gz: 9eebe37a3f4bd5e5f443963e8d4d0de7c6d96b51f9e80cdf07b097b6a52a9e3490c7b0c863c51249ed4539e69a1d463f9ad241e223051a6ca69343f702ae2bbc
7
+ data.tar.gz: 75022227f4e67a80f35cfd8fd62f8d01897d9dfc5662f5a653b469f839b8e61010c6c931c83cdcf1729991e3e3b8ed9188df414600aded12398cc677cc2286de
data/changelog.md CHANGED
@@ -12,12 +12,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
12
12
  ### Removed
13
13
  ### Deprecated
14
14
 
15
- ## [0.1.1] - 2019-10-1920
15
+ ## [0.2.0] - 2021-07-1920
16
+ ### Changed
17
+ - Use JSON included in ishetlekkerindemess.be instead of parsing HTML.
18
+
19
+ ### Added
20
+ - Add fallback url in output when menu is not found.
21
+ - Add placeholders for unavailable menu items.
22
+
23
+ ## [0.1.1] - 2019-10-20
16
24
  ### Added
17
25
  - Changelog file (this file)
18
26
  - Handle the case when there is no menu.
19
27
 
20
- ## [0.1.0] - 2019-10-1920
28
+ ## [0.1.0] - 2019-10-20
21
29
  ### Added
22
30
  - First release
23
31
 
@@ -1,6 +1,8 @@
1
1
  require 'httparty'
2
2
  require 'nokogiri'
3
3
 
4
+ require 'json'
5
+
4
6
  module Lita
5
7
  module Handlers
6
8
  # Handle the VRT Mess requests for the Lita.io bot
@@ -18,42 +20,41 @@ module Lita
18
20
  end
19
21
 
20
22
  def weekmenu
21
- header = []
22
23
  result = []
23
- menu = parse_menu 'week'
24
- table = menu.at('table')
25
- table.search('tr').each do |tr|
26
- cells = tr.search('th')
27
- cells.each do |d|
28
- header << d.text
29
- end
30
- end
31
- table.search('tr').each do |tr|
32
- cells = tr.search('td')
33
- cells.each_with_index do |d, i|
34
- result << "#{header[i]} : #{d.text}"
35
- end
24
+ menus = fetch_menu 'week'
25
+ menus.each do |menu|
26
+ result << format_day(menu)
36
27
  result << '--------------------------' unless result.empty?
37
28
  end
38
- result = ['Geen menu gevonden :('] if result.empty?
29
+ result = ['Geen menu gevonden :(', 'Kijk eens op https://rto365.sharepoint.com/sites/MijnEten'] if result.empty?
39
30
  result.join("\n")
40
31
  end
41
32
 
42
33
  def daymenu
34
+ menu = fetch_menu
35
+ result = format_day(menu)
36
+ result = ['Geen menu gevonden :(', 'Kijk eens op https://rto365.sharepoint.com/sites/MijnEten'] if result.empty?
37
+ result.join("\n")
38
+ end
39
+
40
+ def format_day(menu)
43
41
  result = []
44
- menu = parse_menu
45
- items = menu.css('div.item')
46
- items.each do |item|
47
- name = item.css('h3 img')[0]['alt']
48
- result << "#{name} : #{item.text.strip}"
42
+ date = menu.delete(:date)
43
+ return result if menu.empty?
44
+ result << "Menu voor #{date}"
45
+ menu.each do |name, value|
46
+ value.strip!
47
+ value = "geen #{name.downcase} :(" if value.empty?
48
+ result << "#{name}: #{value}"
49
49
  end
50
- result = ['Geen menu gevonden :('] if result.empty?
51
- result.join("\n")
50
+ result
52
51
  end
53
52
 
54
- def parse_menu(page = '')
55
- menu = HTTParty.get("http://ishetlekkerindemess.be/#{page}")
56
- Nokogiri::HTML(menu)
53
+ def fetch_menu(page = '')
54
+ page = HTTParty.get("http://ishetlekkerindemess.be/#{page}")
55
+ json = Nokogiri::HTML(page).css('script#__NEXT_DATA__').text
56
+ menu = JSON.parse(json, symbolize_names: true)
57
+ menu[:props][:pageProps][:initialData]
57
58
  end
58
59
 
59
60
  Lita.register_handler(self)
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-vrt-mess'
3
- spec.version = '0.1.1'
4
- spec.authors = ['Stefan Goethals']
5
- spec.email = ['stefan.goethals@vrt.be']
3
+ spec.version = '0.2.0'
4
+ spec.authors = ['Stefan Goethals', 'Joris Vandermeersch']
5
+ spec.email = ['stefan.goethals@vrt.be', "joris.vandermeersch@vrt.be"]
6
6
  spec.description = 'Lita.io handler for getting the Menu of the VRT mess'
7
7
  spec.summary = 'Lita.io handler for getting the Menu of the VRT mess'
8
8
  spec.homepage = 'http://vrt.be'
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-vrt-mess
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Goethals
8
- autorequire:
8
+ - Joris Vandermeersch
9
+ autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2019-10-20 00:00:00.000000000 Z
12
+ date: 2021-07-14 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: httparty
@@ -125,6 +126,7 @@ dependencies:
125
126
  description: Lita.io handler for getting the Menu of the VRT mess
126
127
  email:
127
128
  - stefan.goethals@vrt.be
129
+ - joris.vandermeersch@vrt.be
128
130
  executables: []
129
131
  extensions: []
130
132
  extra_rdoc_files: []
@@ -146,7 +148,7 @@ licenses:
146
148
  - 'Apache '
147
149
  metadata:
148
150
  lita_plugin_type: handler
149
- post_install_message:
151
+ post_install_message:
150
152
  rdoc_options: []
151
153
  require_paths:
152
154
  - lib
@@ -161,9 +163,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
163
  - !ruby/object:Gem::Version
162
164
  version: '0'
163
165
  requirements: []
164
- rubyforge_project:
165
- rubygems_version: 2.7.6.2
166
- signing_key:
166
+ rubygems_version: 3.2.3
167
+ signing_key:
167
168
  specification_version: 4
168
169
  summary: Lita.io handler for getting the Menu of the VRT mess
169
170
  test_files: