-
Notifications
You must be signed in to change notification settings - Fork 3
/
parsing_functions.js
90 lines (80 loc) · 2.23 KB
/
parsing_functions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function parseSchedule(data, done) {
var rootRef = new Firebase("https://sizzling-heat-3782.firebaseio.com/");
var classesRef = rootRef.child("Classes");
var header = $(data).find('.staticheaders');
var name = header.html();
name = $.trim(name).substring(10,header.html().length-48)
var userRef = rootRef.child("Users");
var users;
var userFound = false;
var userID = 1;
var returnVal;
userRef.once("value", function(snapshot){
users = snapshot.val();
if (users) {
$.each(users, function(key, userObject)
{
if(userObject.userName == name)
{
userFound = true;
userID = key;
}
});
}
if(userFound == false)
{
userID = userRef.push().name();
userRef.child(userID).set({userName: name});
}
//gets bolded class name, e.x.: Microcomputers I - CE 320 - 01
$(data).find('.captiontext').each(function()
{
var parsedClassName = $(this).html();
var classes;
var classFound = false;
var classExists = false;
if(!(parsedClassName == "Scheduled Meeting Times"))
{
classesRef.once("value", function(snapshot){
classes = snapshot.val();
if (classes) {
$.each(classes, function(key, classObject){
if(parsedClassName == classObject.ClassName)
{
userRef.child(userID + "/Classes").once("value", function(snapshot){
classes2 = snapshot.val();
if (classes2) {
$.each(classes2, function(key2, userClassObject)
{
if(userClassObject.ClassName == parsedClassName)
{
classExists = true;
}
});
}
if(!classExists)
{
userRef.child(userID + "/Classes").push({ClassName : parsedClassName, classKey : key});
}
});
classFound = true;
}
});
}
if(classFound == false)
{
var classId = classesRef.push().name();
classesRef.child(classId).set({ClassName : parsedClassName});
userRef.child(userID + "/Classes").push({ClassName : parsedClassName, classKey : classId});
}
done && done();
});
}
});
var tempRef = userRef.child(userID);
tempRef.once("value", function(snapshot){
returnVal = snapshot.val();
});
});
return returnVal;
}