mmls-downloader 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/mmls +9 -0
  3. data/lib/mmls-downloader.rb +104 -0
  4. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 939aac452a3954405027bff0b82b01904dd07ce7
4
+ data.tar.gz: aedf27da80260f95616b292e52851df473afef1e
5
+ SHA512:
6
+ metadata.gz: bd073396b6f201f29b86edabb93b6ba853053d79dfe191fa0319c7fc92b54330e315a491e0df04fec5ea1096e479231669369b65b43210195e81802b3f739e86
7
+ data.tar.gz: a08665868a6057600f284cbc46cd6901f99c921e5c2170627844b1bb8397c9cec4044ccd5c00d8d8c8941cefdf5a0cb3d86f2ed2f310f3954a495f39f81c28f5
data/bin/mmls ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'mmls-downloader'
4
+ case ARGV[0].downcase
5
+ when "set_path"
6
+ puts MMLS.set_path(ARGV[1])
7
+ when "update"
8
+ puts MMLS.update
9
+ end
@@ -0,0 +1,104 @@
1
+ require 'net-ssh'
2
+ require 'mechanize'
3
+ require "highline/import"
4
+ require 'daybreak'
5
+ require 'colorize'
6
+
7
+ Shoes.app { button "Push me" }
8
+ class MMLS
9
+
10
+ def initialize
11
+ ObjectSpace.define_finalizer(self, self.class.method(:finalize)) # Works in both 1.9.3 and 1.8
12
+ #ObjectSpace.define_finalizer(self, FINALIZER) # Works in both
13
+ #ObjectSpace.define_finalizer(self, method(:finalize)) # Works in 1.9.3
14
+ end
15
+ def self.set_path(path)
16
+ @db = Daybreak::DB.new "mmls.db"
17
+ case path.downcase
18
+ when "icloud"
19
+ path = "/Users/"+ ENV['USER'] +"/Library/Mobile\ Documents/com~apple~CloudDocs"
20
+ when "documents"
21
+ path = "/Users/" + ENV['USER'] + "/Documents"
22
+ when "downloads"
23
+ path = "/Users/" + ENV['USER'] + "/Downloads"
24
+ end
25
+ @db.set! 'save_path', path
26
+ puts "Downloads will now save in : " + @db['save_path']
27
+ @db.close
28
+ end
29
+
30
+ def self.finalize(object_id)
31
+ p "finalizing %d" % object_id
32
+ @db.close
33
+ end
34
+ def finalize(object_id)
35
+ @db.close
36
+ p "finalizing %d" % object_id
37
+ end
38
+ def self.update()
39
+ @db = Daybreak::DB.new "mmls.db"
40
+ agent = Mechanize.new
41
+ agent.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
42
+ page = agent.get("https://mmls.mmu.edu.my")
43
+ form = page.form
44
+ print " #######################################\n"
45
+ print " | MMLS DOWNLOADER |\n"
46
+ print " | BY |\n"
47
+ print " | HII YONG LIAN |\n"
48
+ print " #######################################\n"
49
+ if @db.keys.include? 'mmls_password'
50
+ print " ---------- Loaded MMLS Password -------- "
51
+ form.stud_id = @db['student_id']# INPUT YOUR STUDENT ID
52
+ form.stud_pswrd = @db['mmls_password']# INPUT YOUR MMLS PASSWORD
53
+ page = agent.submit(form)
54
+ else
55
+ loop do
56
+ student_id = ask "Input Student ID: "
57
+ mmls_password = ask("Input MMLS password (Input will be hidden): ") { |q| q.echo = false }
58
+
59
+ form.stud_id = student_id# INPUT YOUR STUDENT ID
60
+ form.stud_pswrd = mmls_password# INPUT YOUR MMLS PASSWORD
61
+ page = agent.submit(form)
62
+ if page.parser.xpath('//*[@id="alert"]').empty?
63
+ @db.set! 'student_id', student_id
64
+ @db.set! 'mmls_password', mmls_password
65
+ path = ask("Enter download path :")
66
+ set_path(path)
67
+ break
68
+ end
69
+ retry_reply = ask("Student ID or password is invalid... Would you like to retry? (Y/N)")
70
+ loop do
71
+ if(retry_reply == 'Y' or retry_reply == 'y')
72
+ break
73
+ elsif(retry_reply == 'N' or retry_reply == 'n')
74
+ @db.close
75
+ exit
76
+ else
77
+ retry_reply = ask("Unrecognized input... Would you like to retry? (Yy/Nn)")
78
+ end
79
+ end
80
+ end
81
+ end
82
+ @db.close
83
+ agent.pluggable_parser.default = Mechanize::Download
84
+ agent.agent.http.retry_change_requests = true
85
+ puts
86
+ puts "Saving in directory: " + @db['save_path']
87
+ subject_links = page.links_with(:text => /[A-Z][A-Z][A-Z][0-9][0-9][0-9][0-9] . [A-Z][A-Z][A-Z]/)
88
+ subject_links.each do |link|
89
+ page = agent.get(link.uri)
90
+ puts "\n Current Subject: " + link.text
91
+ page.forms_with(:action => 'https://mmls.mmu.edu.my/form-download-content').each do |dl_form|
92
+ directory = link.text.split(" (").first + "/"
93
+ full_directory = @db['save_path'] + "/" + link.text.split(" (").first + "/"
94
+ file_name = dl_form.file_name
95
+ if Dir[full_directory + file_name].empty?
96
+ agent.submit(dl_form).save(full_directory + file_name)
97
+ puts "create ".green + directory + file_name
98
+ # else
99
+ # puts "identical ".blue + file_name
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mmls-downloader
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hii Yong Lian
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2010-04-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple gem to download notes
14
+ email: yonglian146@gmail.com
15
+ executables:
16
+ - mmls
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/mmls
21
+ - lib/mmls-downloader.rb
22
+ homepage: http://rubygems.org/gems/mmls
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.4.6
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: MMLS Downloader
46
+ test_files: []