jortiz il y a 5 ans
révision
8c35097a14
3 fichiers modifiés avec 207 ajouts et 0 suppressions
  1. 6
    0
      README.md
  2. 136
    0
      index.html
  3. 65
    0
      ofertatojson.py

+ 6
- 0
README.md Voir le fichier

@@ -0,0 +1,6 @@
1
+ofertatojson.py recibe como parametro el directorio local con las paginas publicadas por el registrador
2
+
3
+El siguiente CRON conf corre el script de ofertatojason.py, genera el json y lo guarda en courses.js
4
+59 2 * *  *     cd /home/jortiz/public_html/oferta/ ; python ofertatojson.py miupi.uprrp.edu/horarios/agosto-2019/ > courses.js
5
+
6
+

+ 136
- 0
index.html Voir le fichier

@@ -0,0 +1,136 @@
1
+<html>
2
+<title>UPR-RP Oferta Académica</title>
3
+<head>
4
+<meta charset="utf-8">
5
+<meta name="viewport" content="width=device-width, initial-scale=1">
6
+<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
7
+<link href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
8
+
9
+  <style>
10
+  .table-hover tbody tr:hover td, .table-hover tbody tr:hover th {
11
+    background-color: #feb5b5;
12
+  table {
13
+    border: none !important;
14
+  }
15
+  table, th, td {
16
+    border: none !important;
17
+}
18
+  }
19
+  </style>
20
+
21
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
22
+<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
23
+<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
24
+</head>
25
+
26
+<body>
27
+<div class="container">
28
+	<div class="row">
29
+		<h1>Oferta Académica</h1>
30
+	</div>
31
+
32
+	<div ng-app="ccc" ng-controller="cccCtrl">
33
+
34
+        <form name="myform">
35
+          <div class="container">
36
+          Powered by: <a href="http://ccom.uprrp.edu"><img style="height: 150px;" src="http://i.imgur.com/xAsIoLE.png"></a>
37
+          </div>
38
+     <!--      <div class="container">
39
+            Powered by: <a href="http://ccom.uprrp.edu"><img height="150px" src="http://i.imgur.com/xAsIoLE.png"></a>
40
+          </div> -->
41
+
42
+	<div class="container-fluid">
43
+		<div class="row">
44
+		 <div class="col-sm-4">
45
+		      <label class="control-label col-sm-2">Keyword:</label>
46
+		 </div>
47
+		  <div class="col-sm-8">
48
+		    <input type="text" data-toggle="tooltip" title="The filter is applied to all the table fields. Example of keyworkds: ccom, 3033, Ortiz" class="form-control" ng-model="keywords" ng-change="updateTable()">
49
+		  </div>
50
+		 </div>
51
+	</div>
52
+
53
+
54
+ <div class="container-fluid">
55
+ 	<div class="row">
56
+    <div class="col-sm-12">
57
+            <p>
58
+            <h3>Lista de Cursos</h3>
59
+            ** Esta tabla se actualiza con los datos que publíca el registrador.  Puede que la información no esté sincronizada con el sistema real.
60
+        	</p>
61
+            <table class="table  table-hover table-striped" >
62
+              <tr ng-repeat="col in fcourses">
63
+
64
+                    <td>
65
+                    	{{col.code}}
66
+                    </td>
67
+                    <td>
68
+                    	<p class="text-center"><b>{{col.name}}</b><br>
69
+                    	Prof. {{col.prof}}</p>
70
+                    </td>
71
+                    <td>
72
+                    	<span><b>Tipo:</b> {{col.type}}</span><br>
73
+                    	<span><b>Cupo:</b> {{col.cupo}}</span><br>
74
+                    	<span><b>Creditos:</b> {{col.creds}}</span><br>
75
+                    </td>
76
+                    <td>
77
+                    	<ul>
78
+                    		<li ng-repeat="sc in col.schedule">{{sc.days}}  {{sc.times}}  {{sc.room}}</li>
79
+                    	</ul>
80
+
81
+                    </td>
82
+
83
+                 </tr>
84
+            </table>
85
+          <br>
86
+     </div>
87
+     </div>
88
+</div>
89
+</body>
90
+
91
+          <script src="courses.js"></script>
92
+
93
+<script>
94
+	$(document).ready(function() {
95
+	  $('[data-toggle="tooltip"]').tooltip();
96
+	});
97
+
98
+	var app = angular.module('ccc', []);
99
+	app.controller('cccCtrl', function($scope, $http) {
100
+		$scope.courses = data;
101
+		$scope.fcourse = [] ;
102
+
103
+		$scope.fcourses = $scope.courses;
104
+
105
+
106
+		// Code for the Keyword search box
107
+
108
+		$scope.updateTable = function() {
109
+			$scope.fcourses = [];
110
+
111
+			searchableKeys = ["code", "name", "prof"] ;
112
+			if($scope.keywords){
113
+				for (col in $scope.courses) {
114
+					found = false;
115
+					for (keyIdx in searchableKeys) { //  $scope.reu[col]) {
116
+						key = searchableKeys[keyIdx];
117
+						//console.log(key) ;
118
+						if ($scope.courses[col][key]!==null && $scope.courses[col][key].toLowerCase().search($scope.keywords.toLowerCase()) >= 0) {
119
+							found = true;
120
+							break;
121
+						}
122
+					}
123
+				if (found)
124
+				    $scope.fcourses.push($scope.courses[col]) ;
125
+				}
126
+			}
127
+			else{
128
+				$scope.fcourses=$scope.courses ;
129
+			}
130
+		}
131
+
132
+	});
133
+</script>
134
+
135
+
136
+</html>

+ 65
- 0
ofertatojson.py Voir le fichier

@@ -0,0 +1,65 @@
1
+from bs4 import BeautifulSoup
2
+import os
3
+import sys
4
+import json
5
+
6
+files = os.listdir(sys.argv[1])
7
+
8
+courses_list = []
9
+
10
+for file in files:
11
+    # Extract the college in the file
12
+    if not file[0:3] == "RBA":
13
+        continue
14
+
15
+    with open(sys.argv[1]+"/"+file) as fp:
16
+        soup = BeautifulSoup(fp)
17
+
18
+    rows = soup.find_all("tr")
19
+
20
+    rows.pop(0)
21
+
22
+    while rows:
23
+        c_name = None
24
+        c_code = None
25
+        c_type = None
26
+        c_days = None
27
+        c_times = None
28
+        c_room = None
29
+        c_schedule = []
30
+        prof = None
31
+        c_cupo = None
32
+        creditos = None
33
+        comment = None
34
+        for i in range(3):
35
+            row = rows.pop(0)
36
+            cols = row.text.split("\n") #, row.getText(), dir(row)
37
+            if i == 0:
38
+                c_code = cols[1].strip()
39
+                c_name = cols[2].strip()
40
+                c_type = cols[3].strip()
41
+                c_days = cols[4].strip()
42
+                c_times = cols[5].strip()
43
+                c_room = cols[6].strip()
44
+                c_schedule.append({"days":c_days, "times": c_times, "room": c_room})
45
+            elif i == 1:
46
+
47
+                prof = cols[1].strip().split("Prof.")[-1]
48
+                c_cupo = cols[2].strip().split(":")[-1].strip()
49
+                c_days = cols[3].strip()
50
+                if c_days:
51
+                    c_times = cols[4].strip()
52
+                    c_room = cols[5].strip()
53
+                    c_schedule.append({"days":c_days, "times": c_times, "room": c_room})
54
+            elif i == 2:
55
+                #print cols
56
+                creditos = int(cols[1].strip().split()[0])
57
+                if cols[1].find("**") >=0:
58
+                    comment = "Cursos no se ofreceran en el proximo semestre"
59
+        
60
+        courses_list.append({"code": c_code, "name": c_name, "type": c_type, "schedule": c_schedule, "cupo": c_cupo, "prof": prof, "creds": creditos, "comm": comment})
61
+        
62
+
63
+print "data=",json.dumps(courses_list)
64
+
65
+