forked from codingprivacy/Feedback-Portal-System
-
Notifications
You must be signed in to change notification settings - Fork 1
/
customfunc.py
42 lines (34 loc) · 1.01 KB
/
customfunc.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
import os
import json
from mysql_dbconnect import *
import gc
forms_dir_path = "/var/www/FPSU/FPSU/alg252kjaglasj/forms/"
def jsonifyforms(form_name, new_quest_list):
try:
file_name = form_name + ".json"
file_path = os.path.join(forms_dir_path, file_name)
data = {}
for i in range(10):
data['q' + str(i+1)] = new_quest_list[i]
json_data = json.dumps(data)
f = os.open(file_path, os.O_RDWR | os.O_CREAT)
os.write(f, json_data)
os.close(f)
return True
except Exception as e:
return False
def list_out_forms():
return os.listdir(os.path.join(forms_dir_path, ""))
def count_forms():
return len(list_out_forms())
def get_class_list(semester):
c, conn = connect_to("pumis")
c.execute("SELECT class FROM semester_info WHERE semester IN (%s)", str(semester))
x = c.fetchall()
c.close()
conn.close()
gc.collect()
class_list = list()
for i in x:
class_list.append(i[0])
return class_list