From ec2e0363a4e3d528d22f223025bfc464813a6dad Mon Sep 17 00:00:00 2001 From: Yohei Yasukawa Date: Sat, 26 Mar 2022 00:19:05 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Add=20=E6=9C=AA=E8=B8=8F=E3=82=B8=E3=83=A5?= =?UTF-8?q?=E3=83=8B=E3=82=A2=E5=BF=9C=E5=8B=9F=E9=80=9F=E5=A0=B1=20featur?= =?UTF-8?q?e=20to=20post=20Mattermost?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 1 + Gemfile.lock | 6 ++++++ gmail2idobata.rb | 28 +++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) 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..eaebce5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -14,11 +14,16 @@ GEM method_source (0.9.2) mime (0.3.0) mime-types (1.25.1) + 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) + racc (1.6.0) treetop (1.4.15) polyglot polyglot (>= 0.3.1) @@ -28,6 +33,7 @@ PLATFORMS 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}") From bf788945d86b073ad7c064a85bcfdaeae1460140 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 25 Mar 2022 15:20:18 +0000 Subject: [PATCH 2/2] Bump mail from 2.5.4 to 2.7.1 Bumps [mail](https://github.com/mikel/mail) from 2.5.4 to 2.7.1. - [Release notes](https://github.com/mikel/mail/releases) - [Changelog](https://github.com/mikel/mail/blob/2.7.1/CHANGELOG.rdoc) - [Commits](https://github.com/mikel/mail/compare/2.5.4...2.7.1) Signed-off-by: dependabot[bot] --- Gemfile.lock | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index eaebce5..3969239 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,25 +8,20 @@ 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) racc (1.6.0) - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) PLATFORMS ruby