-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetadata.py
More file actions
43 lines (38 loc) · 1.9 KB
/
Metadata.py
File metadata and controls
43 lines (38 loc) · 1.9 KB
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
from Logger import Logger as Log
import settings
import pymysql
class Metadata:
def __init__(self, cid):
"""The constructor"""
self.cid = str(cid)
self.logger = Log().getLogger()
def getChannelMetadataMid(self):
self.logger.info("\nFinding Channel Metadata, UserID: " + str(self.cid) + " in database")
try:
dbConnection = pymysql.connect( host=settings.hostname, user=settings.username, passwd=settings.password, db=settings.database )
cursor = dbConnection.cursor()
checkUser = "SELECT mid FROM channel_metadata where cid=\"" + str(self.cid) + "\";"
cursor.execute(checkUser)
result = cursor.fetchall()
if result :
self.logger.info("Found user... Returning User")
return result[0][0]
else :
self.logger.warn("Could not find metadata: {}".format(str(self.cid)))
return 0
except Warning as warn:
self.logger.error("Waring: " + str(warn) + "\nStop\n")
def initializeChannelMetadata(self):
self.logger.info("\nInitializing User's Channel's Metadata Instance, cid: " + str(self.cid))
try:
dbConnection = pymysql.connect( host=settings.hostname, user=settings.username, passwd=settings.password, db=settings.database )
cursor = dbConnection.cursor()
command = "INSERT INTO `channel_metadata` (`cid`) VALUES (\"" + str(self.cid) + "\");"
cursor.execute(command)
dbConnection.commit() # Required to commit changes to the actual database
dbConnection.close()
self.logger.info("Successful connection termination")
return self.getChannelMetadataMid() # Grabbing the user's Uid
except Warning as warn:
self.logger.error("Warning: " + str(warn) + "\nStop.\n")
return None