This repository has been archived by the owner on Mar 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
languages.py
79 lines (64 loc) · 2.35 KB
/
languages.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
import psycopg2
from dbwork import getconn
roles = ['American Sign Language', 'Arabic', 'Czech', 'Danish', 'Dutch', 'English', 'Esperanto', 'Filipino', 'French', 'German', 'Greek', 'Hebrew', 'Indonesian', 'Hindi' ,'Italian', 'Japanese','Korean','Latin', 'Mandarin', 'Portuguese', 'Russian','Spanish', 'Swedish', 'Turkish','Vietnamese']
chans = ['american-sign-language', 'arabic', 'czech', 'danish', 'dutch', 'english', 'esperanto', 'filipino', 'french', 'german', 'greek', 'hebrew', 'indonesian', 'hindustani','italian', 'japanese','korean','latin', 'mandarin', 'portuguese', 'russian','spanish', 'swedish', 'turkish','vietnamese']
def languagedb():
conn = getconn()
cur = conn.cursor()
print('languages')
cur.execute('select exists(select * from information_schema.tables where table_name=%s)', ('languages',))
check = (cur.fetchone()[0])
print(check)
if not check:
cur.execute('''CREATE TABLE languages (
NMB INT NOT NULL,
LANG CHAR(30) NOT NULL,
CHAN CHAR(20) NOT NULL
);''')
print("Table created successfully")
cur.execute('ALTER TABLE languages ADD CONSTRAINT test_pkey6 PRIMARY KEY (LANG);')
else:
print('No need')
conn.commit()
cur.close
conn.close()
def addlanguage(language, id):
conn = getconn()
cur = conn.cursor()
cur.execute("SELECT MAX(NMB) FROM languages;")
a = str(cur.fetchone())
if a == '(None,)':
ar = 0
else:
ar = int(a[1:-2]) + 1
cur.execute("INSERT INTO languages VALUES (%s,%s,%s) ON CONFLICT (LANG) DO UPDATE SET CHAN = excluded.CHAN ;", (ar, language, id))
conn.commit()
cur.execute("SELECT NMB,LANG, CHAN from languages")
rows = cur.fetchall()
x = 0
for j in rows:
x += 1
cur.close()
conn.close
def getlanchan(language):
conn = getconn()
cur = conn.cursor()
cur.execute("SELECT CHAN FROM languages WHERE LANG = %s", (language,))
resp = str(cur.fetchone())
chan = resp[2:-3].strip()
if chan != "":
id = int(chan)
else:
id = -1
return id
cur.close()
conn.close()
def roletochan(role):
n = roles.index(role)
a = chans[n]
item = a.ljust(30)
return getlanchan(item)
def checkrole(role):
return role in roles
def checkchan(chan):
return chan in chans