Skip to content
This repository was archived by the owner on Mar 25, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ ruby '2.6.3'

gem 'gmail'
gem 'pry'
gem 'nokogiri'
17 changes: 9 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 27 additions & 1 deletion gmail2idobata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 += "<li>件名: #{mail.subject}</li>"
#text += "<li>日付: #{mail.date}</li>"
Expand All @@ -43,6 +44,7 @@ def attached_file_exist?(filename)
text += "<b>件名なし</b><br>"
else
text += "<b>#{mail.subject.toutf8}</b><br>"
is_mitoujr_app = true if text.include?('未踏ジュニア2022 応募フォーム')
end

begin
Expand All @@ -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}")
Expand Down