diff --git a/Gemfile b/Gemfile
index 4e256f9..13bd3be 100644
--- a/Gemfile
+++ b/Gemfile
@@ -4,3 +4,4 @@ ruby '2.6.3'
gem 'gmail'
gem 'pry'
+gem 'nokogiri'
diff --git a/Gemfile.lock b/Gemfile.lock
index bf4b9ef..3969239 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -8,26 +8,27 @@ GEM
mime (>= 0.1)
gmail_xoauth (0.4.1)
oauth (>= 0.3.6)
- mail (2.5.4)
- mime-types (~> 1.16)
- treetop (~> 1.4.8)
+ mail (2.7.1)
+ mini_mime (>= 0.1.1)
method_source (0.9.2)
mime (0.3.0)
- mime-types (1.25.1)
+ mini_mime (1.1.2)
+ mini_portile2 (2.8.0)
+ nokogiri (1.13.3)
+ mini_portile2 (~> 2.8.0)
+ racc (~> 1.4)
oauth (0.4.7)
- polyglot (0.3.4)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
- treetop (1.4.15)
- polyglot
- polyglot (>= 0.3.1)
+ racc (1.6.0)
PLATFORMS
ruby
DEPENDENCIES
gmail
+ nokogiri
pry
RUBY VERSION
diff --git a/gmail2idobata.rb b/gmail2idobata.rb
index fa26ba0..1a45e10 100755
--- a/gmail2idobata.rb
+++ b/gmail2idobata.rb
@@ -33,6 +33,7 @@ def attached_file_exist?(filename)
mails = @gmail.inbox.emails(:unread).each do |mail|
text = ""
is_html_format = false
+ is_mitoujr_app = false
#text += "
件名: #{mail.subject}"
#text += "日付: #{mail.date}"
@@ -43,6 +44,7 @@ def attached_file_exist?(filename)
text += "件名なし
"
else
text += "#{mail.subject.toutf8}
"
+ is_mitoujr_app = true if text.include?('未踏ジュニア2022 応募フォーム')
end
begin
@@ -62,7 +64,31 @@ def attached_file_exist?(filename)
post = text.gsub("\n", "").gsub("'", "\"")
puts post
- puts is_html_format
+ puts "Is HTML format? => #{is_html_format}"
+
+ if is_mitoujr_app == true
+ require 'nokogiri'
+ require 'net/http'
+
+ doc = Nokogiri::HTML.parse(text)
+
+ # Get Title & File (URL)
+ title = doc.at("th[text()*='提案のタイトル']").next_element.text.strip
+ file = doc.at("a[href*='mitoujr.wufoo.com/cabinet']")['href']
+
+ uri = URI.parse('https://mattermost.jr.mitou.org/hooks/huxdejyasbgdjgctwtxjf8udje')
+ request = Net::HTTP::Post.new(uri)
+ request.content_type = 'application/json'
+ request.body = JSON.dump({ text: ":new: 提案書: #{title} #{file}" })
+
+ response = Net::HTTP.start(uri.hostname, uri.port, { use_ssl: uri.scheme == "https" }) do |http|
+ http.request(request)
+ end
+
+ # response.code
+ # response.body
+ next
+ end
if is_html_format
system("curl --data-urlencode 'source=#{post}' -d format=html #{IDOBATA_END}")