Skip to content

Instantly share code, notes, and snippets.

@atpons
Created September 18, 2012 15:12
Show Gist options
  • Save atpons/3743678 to your computer and use it in GitHub Desktop.
Save atpons/3743678 to your computer and use it in GitHub Desktop.
TMCIT Exam archives downaloder
# -*- coding: utf-8 -*-
# ++ TMCIT Exam Archives Downloader ++
# ++ I don't like regular expression. ++
# !! At your own risk !!
require "mechanize"
#相対とか絶対とかズッ友になりたくない
agent = Mechanize.new
soutai = "http://www.metro-cit.ac.jp/examination/"
page = agent.get("http://www.metro-cit.ac.jp/examination/honka_haihu.html")
#ちゃんとしたやり方わからない
pdf_title = []
#正規表現しらない
agent.page.links_with(:href => /pdf\Z/).each do |link|
a = "http://www.metro-cit.ac.jp/examination/" + link.uri.to_s
aget = agent.get(a)
puts "[*]URL Fetching of " + a + " ..."
b = link.uri.to_s
puts "[*]URL Fetched."
fetch = a
puts "[*]PDF Downloading of " + b.gsub("pdf/","") + " ..."
bb = b.gsub("pdf/","")
pdf_title.push(bb)
aget.save
puts "[*]PDF Downloaded!"
end
#ダウンロード済PDFファイルの表示
puts "All files downloaded!"
puts "Donwaloded files:"
puts "[*]" + pdf_title
#正規表現知らない
puts "[*]Making directory..."
FileUtils.mkdir_p("2008/shoronbun")
FileUtils.mkdir_p("2009/shoronbun")
FileUtils.mkdir_p("2010/shoronbun")
FileUtils.mkdir_p("2011/shoronbun")
FileUtils.mkdir_p("2012/shoronbun")
FileUtils.mkdir_p("2008/mondai")
FileUtils.mkdir_p("2008/kaito")
FileUtils.mkdir_p("2009/mondai")
FileUtils.mkdir_p("2009/kaito")
FileUtils.mkdir_p("2010/mondai")
FileUtils.mkdir_p("2010/kaito")
FileUtils.mkdir_p("2011/mondai")
FileUtils.mkdir_p("2011/kaito")
FileUtils.mkdir_p("2012/mondai")
FileUtils.mkdir_p("2012/kaito")
#正規表現知らない
puts "[*]Copying files..."
pdf_title.each do |file|
case file
when /2008/
case file
when /shoronbun/
FileUtils.cp(file ,"2008/shoronbun")
when /sugaku/
case file
when /mondai/
FileUtils.cp(file , "2008/mondai")
when /kaito/
FileUtils.cp(file , "2008/kaito")
end
when /eigo/
case file
when /mondai/
FileUtils.cp(file , "2008/mondai")
when /kaito/
FileUtils.cp(file , "2008/kaito")
end
end
when /2009/
case file
when /shoronbun/
FileUtils.cp(file ,"2009/shoronbun")
when /sugaku/
case file
when /mondai/
FileUtils.cp(file , "2009/mondai")
when /kaito/
FileUtils.cp(file , "2009/kaito")
end
when /eigo/
case file
when /mondai/
FileUtils.cp(file , "2009/mondai")
when /kaito/
FileUtils.cp(file , "2009/kaito")
end
end
when /2010/
case file
when /shoronbun/
FileUtils.cp(file ,"2010/shoronbun")
when /sugaku/
case file
when /mondai/
FileUtils.cp(file , "2010/mondai")
when /kaito/
FileUtils.cp(file , "2010/kaito")
end
when /eigo/
case file
when /mondai/
FileUtils.cp(file , "2010/mondai")
when /kaito/
FileUtils.cp(file , "2010/kaito")
end
end
when /2011/
case file
when /shoronbun/
FileUtils.cp(file ,"2011/shoronbun")
when /sugaku/
case file
when /mondai/
FileUtils.cp(file , "2011/mondai")
when /kaito/
FileUtils.cp(file , "2011/kaito")
end
when /eigo/
case file
when /mondai/
FileUtils.cp(file , "2011/mondai")
when /kaito/
FileUtils.cp(file , "2011/kaito")
end
end
when /2012/
case file
when /shoronbun/
FileUtils.cp(file ,"2012/shoronbun")
when /sugaku/
case file
when /mondai/
FileUtils.cp(file , "2012/mondai")
when /kaito/
FileUtils.cp(file , "2012/kaito")
end
when /eigo/
case file
when /mondai/
FileUtils.cp(file , "2012/mondai")
when /kaito/
FileUtils.cp(file , "2012/kaito")
end
end
end
end
#License
#Copyright (c) 2012 atpons
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment