Skip to content

Commit

Permalink
Added highline/import. (Vic's suggestion)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashbb committed Apr 6, 2009
1 parent 8075fe0 commit 732eea7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
18 changes: 11 additions & 7 deletions Countries/all_courses.rb
Expand Up @@ -3,11 +3,15 @@

require 'hpricot'
require 'mechanize'
require 'highline/import'

courses = %W(FORPC101-10C FORPC101-9C POIRPTDDC101-1I POIRPWMC101-2I
POIRPWSC101-3I FORPC101-3 FORPC101-4 FORPC101-5C FORPC101-6C
FORPC101-7C FORPC101-8C POIRPC101-1I POIRPWDC101-1I POIRPWMC101-1I
POIRPWSC101-1I POIRPWSC101-2I POJRPC101-1) << 'Teachers Lounge'
courses = %W(FOFXR101-1I FOGGHC101-3L FORPC101-10C
FORPC101-11C FORPC101-12C FOUTWRC101-1I POIRPWMC101-3I
POIRPWSC101-3I POIRPWSC101-4I POIRPWSC101-4I POIRSC101-1I
FOGGHC101-1L FOGGHC101-2L FORPC101-3 FORPC101-4
FORPC101-5C FORPC101-6C FORPC101-7C FORPC101-8C
FORPC101-9C POIRPWMC101-1I POIRPWMC101-2I
POIRPWSC101-1I POIRPWSC101-2I) << 'Teachers Lounge'

lists, countries, htmls = [], [], []

Expand All @@ -17,11 +21,11 @@
login_page = agent.get("http://rubylearning.org/class/login/index.php")

login_form = login_page.forms.first
login_form['username'] = "your username"
login_form['password'] = "your password"
login_form['username'] = ask('Username: '){|q|q.echo = true}
login_form['password'] = ask('Password: '){|q|q.echo = '*'}
agent.submit(login_form)

main_page = agent.get('http://rubylearning.org/class/course/index.php')
main_page = agent.get('http://rubylearning.org/class/')

courses.each do |course|
course_link = main_page.link_with(:text => course)
Expand Down
5 changes: 3 additions & 2 deletions Countries/ruby_launcher.rb
Expand Up @@ -3,14 +3,15 @@
# Mechanize compliant version: 0.9.0

require 'mechanize'
require 'highline/import'

agent = WWW::Mechanize.new

login_page = agent.get("http://rubylearning.org/class/login/index.php")

login_form = login_page.forms.first
login_form['username'] = "your username"
login_form['password'] = "your password"
login_form['username'] = ask('Username: '){|q|q.echo = true}
login_form['password'] = ask('Password: '){|q|q.echo = '*'}
main_page = agent.submit(login_form)

#course_link = main_page.links.text(ARGV[0].upcase)
Expand Down
20 changes: 12 additions & 8 deletions Countries/ruby_launcher2.rb
Expand Up @@ -2,23 +2,27 @@
# Mechanize compliant version: 0.9.0

require 'mechanize'
require 'highline/import'

courses = %W(FORPC101-10C FORPC101-9C POIRPTDDC101-1I POIRPWMC101-2I
POIRPWSC101-3I FORPC101-3 FORPC101-4 FORPC101-5C FORPC101-6C
FORPC101-7C FORPC101-8C POIRPC101-1I POIRPWDC101-1I POIRPWMC101-1I
POIRPWSC101-1I POIRPWSC101-2I POJRPC101-1) << 'Teachers Lounge'
courses = %W(FOFXR101-1I FOGGHC101-3L FORPC101-10C
FORPC101-11C FORPC101-12C FOUTWRC101-1I POIRPWMC101-3I
POIRPWSC101-3I POIRPWSC101-4I POIRPWSC101-4I POIRSC101-1I
FOGGHC101-1L FOGGHC101-2L FORPC101-3 FORPC101-4
FORPC101-5C FORPC101-6C FORPC101-7C FORPC101-8C
FORPC101-9C POIRPWMC101-1I POIRPWMC101-2I
POIRPWSC101-1I POIRPWSC101-2I) << 'Teachers Lounge'

agent = WWW::Mechanize.new
#agent.set_proxy('proxy server name', 'port', 'userid', 'password')

login_page = agent.get("http://rubylearning.org/class/login/index.php")

login_form = login_page.forms.first
login_form['username'] = "your username"
login_form['password'] = "your password"
login_form['username'] = ask('Username: '){|q|q.echo = true}
login_form['password'] = ask('Password: '){|q|q.echo = '*'}
agent.submit(login_form)

main_page = agent.get('http://rubylearning.org/class/course/index.php')
main_page = agent.get('http://rubylearning.org/class/')

courses.each do |course|
course_link = main_page.link_with(:text => course)
Expand All @@ -35,4 +39,4 @@
open(course + '.html', 'w'){|f| f.puts show_all_page.body}
end

%x(ruby shoes_all_courses.rb)
%x(ruby shoes_all_courses.rb)
11 changes: 7 additions & 4 deletions Countries/shoes_all_courses.rb
Expand Up @@ -4,10 +4,13 @@

require 'hpricot'

courses = %W(FORPC101-10C FORPC101-9C POIRPTDDC101-1I POIRPWMC101-2I
POIRPWSC101-3I FORPC101-3 FORPC101-4 FORPC101-5C FORPC101-6C
FORPC101-7C FORPC101-8C POIRPC101-1I POIRPWDC101-1I POIRPWMC101-1I
POIRPWSC101-1I POIRPWSC101-2I POJRPC101-1) << 'Teachers Lounge'
courses = %W(FOFXR101-1I FOGGHC101-3L FORPC101-10C
FORPC101-11C FORPC101-12C FOUTWRC101-1I POIRPWMC101-3I
POIRPWSC101-3I POIRPWSC101-4I POIRPWSC101-4I POIRSC101-1I
FOGGHC101-1L FOGGHC101-2L FORPC101-3 FORPC101-4
FORPC101-5C FORPC101-6C FORPC101-7C FORPC101-8C
FORPC101-9C POIRPWMC101-1I POIRPWMC101-2I
POIRPWSC101-1I POIRPWSC101-2I) << 'Teachers Lounge'

list, countries = [], []

Expand Down
9 changes: 3 additions & 6 deletions README.txt
Expand Up @@ -12,22 +12,19 @@ Requirement:
gem install mechanize

Usage:
- replace your username and password
+ line 12 and 13 of ruby_launcher.rb
+ line 17 and 18 of ruby_launcher2.rb
+ line 20 and 21 of all_courses.rb

- select the courses
+ ruby_launcher.rb : give it as an argument
+ ruby_launcher2.rb : edit line 6, 7, 8, 9
+ all_courses.rb : edit line 7, 8, 9, 10
+ ruby_launcher2.rb : edit line 7-13
+ all_courses.rb : edit line 8-14

- run the Ruby program
+ C:\> ruby ruby_launcher.rb <course name>
+ C:\> ruby ruby_launcher2.rb
+ C:\> ruby all_courses.rb

Change log:
06th Apr: Added `highline/import`. (Vic's suggestion)
25th Feb: Fixed a few typos
12th Feb: Merged RLGGHC's pull-request.
28th Jan: Added two new tools, ruby_launcher2.rb and all_courses.rb, which output a total of all courses.
Expand Down

0 comments on commit 732eea7

Please sign in to comment.