-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmConverter.py
53 lines (46 loc) · 1.83 KB
/
mConverter.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
import csv
import sys
import mConnect
def convert(input):
result = "None"
# using a set to find the sections (unique elements only)
findSection = set([])
# Connect to the database.
conn = mConnect.connection()
c = conn.cursor()
c.execute("START TRANSACTION")
c.execute("SELECT * FROM `class` " )
for section in c.fetchall():
if (input.find('.') != -1):
input = input.replace(" ", "")
input = input.replace(".0", ".")
#section = '11081','201610','CS','374','1','Software Engineering',3)
if (input.upper() == section[2]+section[3]+'.'+section[4]):
result = section[0]
# subject code + a course 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])
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])
result = section[0]
# course title
else:
if (input.lower() == section[5].lower()):
findSection.add(section[2]+section[3]+'.'+section[4])
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)