-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcConverter.py
82 lines (70 loc) · 2.68 KB
/
cConverter.py
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
# http://radon.readthedocs.org/en/latest/intro.html
# --------------------------------------------------
# Cyclomatic complexity
# --------------------------------------------------
# F 20:0 convert - C (13)
# --------------------------------------------------
# Halstead complexity
# --------------------------------------------------
# h1: 7
# h2: 58
# N1: 30
# N2: 60
# h: 65
# N: 90
# length: 359.41
# volume: 542.01
# difficulty: 3.62
# effort: 1962.46
import csv
import sys
import cConnect
def convert(input):
# if we can not find a match, we return "None" (default)
result = "None"
# using a set to find the sections (unique elements only)
findSection = set([])
# Connect to the database.
conn = cConnect.connection()
c = conn.cursor()
c.execute("START TRANSACTION")
c.execute("SELECT * FROM `class` " )
for section in c.fetchall():
# if section number, this means we need to format it to work with banner's formatting
if (input.find('.') != -1):
input = input.replace(" ", "")
input = input.replace(".0", ".")
# then we can match this up with a subject code and course number
if (input.upper() == section[2]+section[3]+'.'+section[4]):
# if match, we want to return the CRN
result = section[0]
# subject code + course number (no section number)
elif (input[0].isalpha() and input[len(input)-1].isdigit()):
input = input.replace(" ", "")
input = input.upper()
if(input.upper() == section[2]+section[3]):
findSection.add(section[2]+section[3]+'.'+section[4])
# if match, we want to return the CRN
result = section[0]
# subject code only
elif(input[0].isalpha() and len(input) < 5):
input = input.upper()
if (input == section[1]):
findSection.add(section[2]+section[3]+'.'+section[4])
# if match, we want to return the CRN
result = section[0]
# course title
else:
if (input.lower() == section[5].lower()):
findSection.add(section[2]+section[3]+'.'+section[4])
# if match, we want to return the CRN
result = section[0]
# if the course has at least 2 sections, ask the user to tell us which one he/she wants
if (len(findSection) > 1):
temp = input+' has '+str(len(findSection))+' sections, please choose one: '+findSection.pop()
while (len(findSection)) != 0:
temp += ', '+findSection.pop()
result = temp
c.close()
conn.close()
return str(result)