polyhoraire 1.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/setup.rb ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #encoding : UTF-8
4
+
5
+ module Setup
6
+ def self.google
7
+ puts " ------------------------------ "
8
+ puts " Google-API connection settings "
9
+ puts " => https://code.google.com/apis/console"
10
+ puts " ------------------------------ "
11
+ puts " 1. Client ID : "
12
+ clientID = STDIN.gets.chomp
13
+ puts " 2. Client secret : "
14
+ clientSecret = STDIN.gets.chomp
15
+ scope = "https://www.googleapis.com/auth/calendar"
16
+
17
+ command = "google-api oauth-2-login --scope=" + scope + " --client-id=" + clientID + " --client-secret=" + clientSecret
18
+
19
+
20
+ system(command)
21
+ FileUtils.mv(Dir.home + '/.google-api.yaml', Poly::userConfDir + '/google-api.yaml')
22
+ puts "Creation du fichier de configuration dans :"
23
+ puts " => " + Poly::userConfDir + "/google-api.yaml"
24
+ end
25
+ end
@@ -0,0 +1,115 @@
1
+ <?xml version="1.0"?>
2
+ <poly>
3
+ <informations>
4
+ <cour sigle="INF3005">
5
+ <nom>COMMUNICATION ECRITE ET ORALE</nom>
6
+ <prof>Dominique Chass&#xE9;</prof>
7
+ <groupeTheorie>01</groupeTheorie>
8
+ <groupeLaboratoire/>
9
+ <nombreCredits>01</nombreCredits>
10
+ </cour>
11
+ <cour sigle="INF3610">
12
+ <nom>SYSTEMES EMBARQUES</nom>
13
+ <prof>Guy Bois</prof>
14
+ <groupeTheorie>01</groupeTheorie>
15
+ <groupeLaboratoire>01</groupeLaboratoire>
16
+ <nombreCredits>03</nombreCredits>
17
+ </cour>
18
+ <cour sigle="INF3990">
19
+ <nom>PROJET DE CONC. LOG. EMBARQUE</nom>
20
+ <prof>J&#xE9;r&#xF4;me Collin</prof>
21
+ <groupeTheorie>01</groupeTheorie>
22
+ <groupeLaboratoire>01</groupeLaboratoire>
23
+ <nombreCredits>04</nombreCredits>
24
+ </cour>
25
+ <cour sigle="INF4705">
26
+ <nom>ANALYSE ET CONCEPTION D'ALGOR.</nom>
27
+ <prof>&#xC0; d&#xE9;terminer &#xC0; d&#xE9;terminer</prof>
28
+ <groupeTheorie>01</groupeTheorie>
29
+ <groupeLaboratoire>02</groupeLaboratoire>
30
+ <nombreCredits>03</nombreCredits>
31
+ </cour>
32
+ <cour sigle="SSH5201">
33
+ <nom>ECONOMIQUE DE L'INGENIEUR</nom>
34
+ <prof>Sophie Bernard</prof>
35
+ <groupeTheorie>04</groupeTheorie>
36
+ <groupeLaboratoire>04</groupeLaboratoire>
37
+ <nombreCredits>03</nombreCredits>
38
+ </cour>
39
+ <cour sigle="SSH5501">
40
+ <nom>ETHIQUE APPL. A L'INGENIERIE</nom>
41
+ <prof>Laurent Jodoin</prof>
42
+ <groupeTheorie>06</groupeTheorie>
43
+ <groupeLaboratoire/>
44
+ <nombreCredits>02</nombreCredits>
45
+ </cour>
46
+ </informations>
47
+ <horaire>
48
+ <evenement type="lab">
49
+ <moment semaine="B2" jour="1" debut="12:45" fin="15:45"/>
50
+ <sigle>SSH5201</sigle>
51
+ <groupe>04</groupe>
52
+ <local>L-6616</local>
53
+ </evenement>
54
+ <evenement type="cours">
55
+ <moment semaine="" jour="2" debut="8:30" fin="10:30"/>
56
+ <sigle>INF3990</sigle>
57
+ <groupe>01</groupe>
58
+ <local>M-1020</local>
59
+ </evenement>
60
+ <evenement type="lab">
61
+ <moment semaine="" jour="2" debut="10:30" fin="12:30"/>
62
+ <sigle>INF3990</sigle>
63
+ <groupe>01</groupe>
64
+ <local>L-3712</local>
65
+ </evenement>
66
+ <evenement type="cours">
67
+ <moment semaine="" jour="2" debut="14:45" fin="17:45"/>
68
+ <sigle>INF3610</sigle>
69
+ <groupe>01</groupe>
70
+ <local>L-3816</local>
71
+ </evenement>
72
+ <evenement type="cours">
73
+ <moment semaine="" jour="3" debut="9:30" fin="12:30"/>
74
+ <sigle>SSH5501</sigle>
75
+ <groupe>06</groupe>
76
+ <local>M-2107</local>
77
+ </evenement>
78
+ <evenement type="lab">
79
+ <moment semaine="B2" jour="3" debut="12:45" fin="15:45"/>
80
+ <sigle>INF4705</sigle>
81
+ <groupe>02</groupe>
82
+ <local>L-4712</local>
83
+ </evenement>
84
+ <evenement type="cours">
85
+ <moment semaine="" jour="4" debut="9:30" fin="12:30"/>
86
+ <sigle>INF4705</sigle>
87
+ <groupe>01</groupe>
88
+ <local>B-505</local>
89
+ </evenement>
90
+ <evenement type="lab">
91
+ <moment semaine="B1" jour="4" debut="13:45" fin="16:45"/>
92
+ <sigle>INF3610</sigle>
93
+ <groupe>01</groupe>
94
+ <local>L-3714</local>
95
+ </evenement>
96
+ <evenement type="cours">
97
+ <moment semaine="" jour="4" debut="13:45" fin="16:45"/>
98
+ <sigle>SSH5201</sigle>
99
+ <groupe>04</groupe>
100
+ <local>L-1720</local>
101
+ </evenement>
102
+ <evenement type="lab">
103
+ <moment semaine="" jour="5" debut="13:45" fin="17:45"/>
104
+ <sigle>INF3990</sigle>
105
+ <groupe>01</groupe>
106
+ <local>L-3712</local>
107
+ </evenement>
108
+ <evenement type="cours">
109
+ <moment semaine="" jour="5" debut="17:45" fin="18:45"/>
110
+ <sigle>INF3005</sigle>
111
+ <groupe>01</groupe>
112
+ <local>WEBCOURS</local>
113
+ </evenement>
114
+ </horaire>
115
+ </poly>
@@ -0,0 +1,21 @@
1
+ require 'polyhoraire/auth'
2
+ require 'test/unit'
3
+ require 'yaml'
4
+
5
+ class TestAuth < Test::Unit::TestCase
6
+ def setup
7
+ @config = YAML.load_file("conf/test_poly.yaml")
8
+ end
9
+
10
+ def test_connect
11
+ assert_nothing_raised do
12
+ auth = Poly::Auth.new
13
+
14
+ user = @config['credentials']['user']
15
+ password = @config['credentials']['password']
16
+ bday = @config['credentials']['bday']
17
+
18
+ auth.connect(user,password,bday)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ require 'polyhoraire/course'
4
+ require 'test/unit'
5
+ require 'nokogiri'
6
+
7
+ class TestCourse < Test::Unit::TestCase
8
+
9
+ def test_from_nokogiri
10
+ assert_nothing_raised do
11
+ xml = Nokogiri::XML(File.read("test/asset/schedule.xml"))
12
+
13
+ course = Poly::Course.from_nokogiri(xml)[0]
14
+
15
+ assert_equal('INF3005' ,course.acronym)
16
+ assert_equal('COMMUNICATION ECRITE ET ORALE',course.name)
17
+ assert_equal("Dominique Chassé" ,course.professor)
18
+ assert_equal('01' ,course.group)
19
+ assert_equal('' ,course.labGroup)
20
+ assert_equal('01' ,course.creditNbr)
21
+
22
+ assert_equal(1,course.periods.size)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ require 'polyhoraire/period'
2
+ require 'test/unit'
3
+ require 'nokogiri'
4
+
5
+ class TestPeriod < Test::Unit::TestCase
6
+ def test_from_nokogiri
7
+ assert_nothing_raised do
8
+ xml = Nokogiri::XML(File.read("test/asset/schedule.xml"))
9
+
10
+ p = Poly::Period.from_nokogiri(xml,"INF3990")[0]
11
+
12
+
13
+ assert_equal('8:30' ,p.from)
14
+ assert_equal('10:30',p.to)
15
+ assert_equal(2 ,p.weekDay)
16
+ assert_equal('01' ,p.group)
17
+ assert_equal('M-1020',p.location)
18
+ assert_equal(false ,p.isLab)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ require 'polyhoraire/auth'
2
+ require 'polyhoraire/schedule'
3
+
4
+ require 'test/unit'
5
+ require 'nokogiri'
6
+ require 'yaml'
7
+
8
+ class TestSchedule < Test::Unit::TestCase
9
+ def setup
10
+ @config = YAML.load_file("conf/test_poly.yaml")
11
+ end
12
+
13
+ def test_get
14
+ assert_nothing_raised do
15
+ doc = Nokogiri::XML(File.read("test/asset/schedule.xml"))
16
+
17
+ auth = Poly::Auth.new
18
+
19
+ user = @config['credentials']['user']
20
+ password = @config['credentials']['password']
21
+ bday = @config['credentials']['bday']
22
+
23
+ auth.connect(user,password,bday)
24
+
25
+ schedule = Poly::Schedule.new(auth,20121)
26
+ afile = File.open('pol.xml','w')
27
+ afile.write(schedule.to_xml)
28
+ afile.close
29
+ assert_equal(doc.to_s ,schedule.to_xml)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,75 @@
1
+ require 'polyhoraire/trimester'
2
+ require 'polyhoraire/period'
3
+
4
+ require 'test/unit'
5
+ require 'yaml'
6
+
7
+ class TestTrimester < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @trimester = Poly::Trimester.fromYAML(20121)
11
+ end
12
+ def test_week
13
+ assert_nothing_raised do
14
+
15
+ #puts trimester.datesFor(4,2)
16
+ fridayB1 = [
17
+ Date.new(2012,01,13),
18
+ Date.new(2012,01,27),
19
+ Date.new(2012,02,10),
20
+ Date.new(2012,02,24),
21
+ Date.new(2012,03,16),
22
+ Date.new(2012,03,30),
23
+ Date.new(2012,04,17)
24
+ ]
25
+ assert_equal(fridayB1,@trimester.week[1][5])
26
+
27
+ end
28
+ end
29
+
30
+ def test_getDates
31
+ xml = Nokogiri::XML(File.read("test/asset/schedule.xml"))
32
+
33
+ period = Poly::Period.new('8:30','9:30',0,4,'01','Endroit',true)
34
+ dates = [
35
+ Date.new(2012,01,12),
36
+ Date.new(2012,01,19),
37
+ Date.new(2012,01,26),
38
+ Date.new(2012,02,2),
39
+ Date.new(2012,02,9),
40
+ Date.new(2012,02,16),
41
+ Date.new(2012,02,23),
42
+ Date.new(2012,03,1),
43
+ Date.new(2012,03,15),
44
+ Date.new(2012,03,22),
45
+ Date.new(2012,03,29),
46
+ Date.new(2012,04,5),
47
+ Date.new(2012,04,12)
48
+ ]
49
+ assert_equal(dates,@trimester.getDates(period))
50
+
51
+ period = Poly::Period.new('8:30','9:30',2,4,'01','Endroit',true)
52
+ dates = [
53
+ Date.new(2012,01,19),
54
+ Date.new(2012,02,2),
55
+ Date.new(2012,02,16),
56
+ Date.new(2012,03,1),
57
+ Date.new(2012,03,22),
58
+ Date.new(2012,04,5)
59
+ ]
60
+ assert_equal(dates,@trimester.getDates(period))
61
+
62
+
63
+ period = Poly::Period.new('8:30','9:30',1,4,'01','Endroit',true)
64
+ dates = [
65
+ Date.new(2012,01,12),
66
+ Date.new(2012,01,26),
67
+ Date.new(2012,02,9),
68
+ Date.new(2012,02,23),
69
+ Date.new(2012,03,15),
70
+ Date.new(2012,03,29),
71
+ Date.new(2012,04,12)
72
+ ]
73
+ assert_equal(dates,@trimester.getDates(period))
74
+ end
75
+ end
@@ -0,0 +1,29 @@
1
+ require 'google_exporter'
2
+ require 'polyhoraire/schedule'
3
+ require 'polyhoraire/auth'
4
+ require 'test/unit'
5
+ require 'nokogiri'
6
+
7
+ class TestGoogleExporter < Test::Unit::TestCase
8
+ def setup
9
+ @exporter = GoogleExporter.new
10
+
11
+ auth = Poly::Auth.new
12
+
13
+ @config = YAML.load_file("conf/test_poly.yaml")
14
+ user = @config['credentials']['user']
15
+ password = @config['credentials']['password']
16
+ bday = @config['credentials']['bday']
17
+
18
+ auth.connect(user,password,bday)
19
+
20
+ @schedule = Poly::Schedule.new(auth,20121)
21
+ end
22
+
23
+ def test_send
24
+ @exporter.send(@schedule,'ekd38fnk731clljnj56svvvdgk@group.calendar.google.com')
25
+ puts "Verify manually that every events have been created and press any key"
26
+ STDIN.gets.chomp
27
+ @exporter.deleteSentEvents()
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby
2
+
3
+ # To have tests working, fill in the config.yaml file
4
+
5
+ require 'polyhoraire/tc_period'
6
+
7
+
data/test/ts_online.rb ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'polyhoraire/tc_auth'
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: polyhoraire
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Charles Briere
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-10 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Retrieve schedule from Polytechnique de Montreal and exports it to different
15
+ formats(only google calendar is suported at this time)
16
+ email: charles.briere@polymtl.ca
17
+ executables:
18
+ - polyhoraire
19
+ extensions: []
20
+ extra_rdoc_files:
21
+ - Readme.rdoc
22
+ files:
23
+ - bin/polyhoraire
24
+ - lib/html.xsl
25
+ - lib/polyhoraire.rb
26
+ - lib/polyhoraire/period.rb
27
+ - lib/polyhoraire/auth.rb
28
+ - lib/polyhoraire/course.rb
29
+ - lib/polyhoraire/schedule.rb
30
+ - lib/polyhoraire/poly2XML.xsl
31
+ - lib/polyhoraire/trimester.rb
32
+ - lib/google.atom.xsl
33
+ - lib/google_exporter.rb
34
+ - lib/setup.rb
35
+ - lib/google.xml.xsl
36
+ - test/ts_online.rb
37
+ - test/polyhoraire/test_schedule.rb
38
+ - test/polyhoraire/test_trimester.rb
39
+ - test/polyhoraire/test_auth.rb
40
+ - test/polyhoraire/test_course.rb
41
+ - test/polyhoraire/test_period.rb
42
+ - test/ts_offline.rb
43
+ - test/asset/schedule.xml
44
+ - test/test_google_exporter.rb
45
+ - Readme.rdoc
46
+ homepage: https://github.com/flatzo/polyhoraire
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.13
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Retrieve schedule from Polymtl and exports it
70
+ test_files: []