Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed scholar-grades.rb as its no longer functional.

Was some quite old code
  • Loading branch information...
commit 2f16621cdc65d6407cea054edaee0ec3fd8f41d5 1 parent aaa3064
Miles Sandlar authored

Showing 2 changed files with 0 additions and 196 deletions. Show diff stats Hide diff stats

  1. +0 4 README.md
  2. +0 192 scholar-grades.rb
4 README.md
Source Rendered
@@ -6,10 +6,6 @@ Course Add (course-add.rb)
6 6 --------------------------------
7 7 A script which stalks the Virginia Tech classes time table and when a class becomes available it automatically registers you for that class. Can be used to check multiple crns at once. Use at your own discretion.
8 8
9   -Scholar Grades (scholar-grades.rb)
10   -----------------------------------
11   -A prompt-menu type CLI for getting your grades from Scholar.
12   -
13 9 Blacksburg Transit (blacksburg-transit.rb)
14 10 ------------------------------------------
15 11 Gets the next bus stop for the Blacksburg transit given a list of pre-determined stops.
192 scholar-grades.rb
... ... @@ -1,192 +0,0 @@
1   -#!/usr/bin/ruby
2   -require 'rubygems'
3   -require 'mechanize'
4   -require 'nokogiri'
5   -require 'json'
6   -require 'highline/import'
7   -require 'stringio'
8   -
9   -
10   -#Create the agent
11   -@agent = Mechanize.new
12   -@agent.redirect_ok = true
13   -@agent.user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.11 Safari/535.19"
14   -
15   -
16   -#Uber simway to colorize outputin
17   -class String
18   - def color(c)
19   - colors = {
20   - :black => 30,
21   - :red => 31,
22   - :green => 32,
23   - :yellow => 33,
24   - :blue => 34,
25   - :magenta => 35,
26   - :cyan => 36,
27   - :white => 37
28   - }
29   - return "\e[#{colors[c] || c}m#{self}\e[0m"
30   - end
31   -end
32   -
33   -
34   -def main
35   -
36   - #Prompt and Store User/Pass
37   - username = ask("Username".color(:green) + ": ") { |q| q.echo = true }
38   - password = ask("Password".color(:green) + ": " ) { |q| q.echo = "*" }
39   -
40   - #Login
41   - cookieJar = login(username,password)
42   - courses = getCourses(cookieJar)
43   -
44   - #Show Available Courses
45   - print "\n"
46   - courses.each_with_index do |course, index|
47   - puts "#{index.to_s.color(:red)} #{course["name"].color(:blue)}"
48   - end
49   -
50   - #Prompt to Pick a Course
51   - print "\nCourse Name or #: ".color(:green)
52   - courseSelector = gets.chomp!
53   -
54   - #Fetch the gRadebook
55   - course, gradebook = getGrades(courses, cookieJar, courseSelector)
56   -
57   - #Course Name
58   - puts "\n#{course.color(:magenta)}\n"
59   -
60   - #Loop through Grades in Gradbook
61   - gradebook.each do |category, grades|
62   -
63   - puts "#{category}".color(:red).color(4)
64   -
65   - grades.each_with_index do |grade, index|
66   - print "#{grade[:assignment].color(:blue)}\t"
67   - print "[#{grade[:pointsScored].color(:green).color(4)}/"
68   - print "#{grade[:pointsAvailable].color(:blue)}]\t"
69   - print "#{grade[:weight].color(:yellow)}\n"
70   - end
71   - print "\n"
72   - end
73   -
74   -end
75   -
76   -def loadCookies(cookieJar)
77   - @agent.cookie_jar.load_cookiestxt(cookieJar)
78   -end
79   -
80   -#Unload's cookies to a variable returned
81   -def unloadCookies
82   - #Store the Coories
83   - cookieJar = StringIO.new
84   - @agent.cookie_jar.dump_cookiestxt(cookieJar)
85   - @agent.cookie_jar.clear!
86   -
87   - return cookieJar.string
88   -end
89   -
90   -
91   -#Logins, Gets the Courses, Returns Courses Obj with Name/URL/Tools for each
92   -def login(username, password)
93   -
94   - #Login to the system!
95   - page = @agent.get("https://scholar.vt.edu/portal/login")
96   - login = page.forms.first
97   -
98   - login.set_fields({
99   - :username => username,
100   - :password => password
101   - })
102   - login.submit().body
103   -
104   - return unloadCookies
105   -end
106   -
107   -#Get courses given a cookiejar
108   -def getCourses(cookieJar)
109   - loadCookies(cookieJar)
110   -
111   - #Get Scholar Site
112   - scholar = Nokogiri::HTML(@agent.get("https://scholar.vt.edu/portal/site").body)
113   - courses = []
114   -
115   - #Store Courses URLs
116   - scholar.css('#siteLinkList a').collect do |course|
117   - courses.push({
118   - "name" => course.text,
119   - "url" => course.get_attribute("href"),
120   - "tools" => {}
121   - }) unless course.text == "My Workspace"
122   - end
123   -
124   - #Store Tool URLS
125   - courses.each do |course|
126   - Nokogiri::HTML(
127   - @agent.get(course["url"]).body
128   - ).css("#toolMenu a").each do |tool|
129   - course["tools"][tool.text] = tool.get_attribute("href")
130   - end
131   - end
132   -
133   - unloadCookies
134   - return courses
135   -end
136   -
137   -#Get grades for a specific class given a cookie jar
138   -def getGrades(courses, cookieJar, classSelector)
139   -
140   - loadCookies(cookieJar)
141   -
142   - #Figure out what Class were getting grades for
143   - course = false
144   -
145   - #Course Number was passed
146   - if classSelector.match(/^[0-9]+$/) then
147   - course = courses[classSelector.to_i]
148   - else
149   - course = courses.select do |c|
150   - c["name"].match(classSelector)
151   - end
152   - end
153   -
154   -
155   - #Setup Return Grades Hash
156   - returnGrades = {}
157   -
158   - #Get URL base of gradebook based on iframe and format to REST JSON Path
159   - gradebookFrame = Nokogiri::HTML(@agent.get(course["tools"]["Gradebook"]).body)
160   - gradebook = gradebookFrame.css('iframe')[0].get_attribute("src")
161   - gradebook.gsub!(/\?.+$/, "/gradebook/rest/application/")
162   -
163   - #Get Grades JSON and parse, get User Grades Json as well
164   - gradesJson = JSON.parse(@agent.get(gradebook).body)
165   - userGrades = gradesJson["A_GB_MODELS"][0]["M_USER"]
166   -
167   - #Loop through each category and enter each grade into returnGrades
168   - gradesJson["A_GB_MODELS"][0]["M_GB_ITM"]["A_CHILDREN"].each do |category|
169   - #If Cateogry is single object
170   - if (!category["A_CHILDREN"]) then category["A_CHILDREN"] = [category] end
171   -
172   - #Category name create and create entry in return grades
173   - categoryName = category["A_CHILDREN"][0]["S_PARENT"]
174   - returnGrades[categoryName] = []
175   -
176   - #The actual assignment
177   - category["A_CHILDREN"].each do |entry|
178   - returnGrades[categoryName].push({
179   - :assignment => entry["S_NM"].to_s,
180   - :pointsScored => (userGrades[entry["S_ID"]] || "N/A").to_s,
181   - :pointsAvailable => entry["D_PNTS"].to_s,
182   - :weight => entry["D_WGHT"].to_s
183   - })
184   - end
185   - end
186   -
187   - unloadCookies
188   - return course["name"], returnGrades
189   -end
190   -
191   -#Run
192   -main

0 comments on commit 2f16621

Please sign in to comment.
Something went wrong with that request. Please try again.