def parseMediaCategory_update(mediaInfo): try: stripper = [x.strip() for x in mediaInfo.split(',', 1)] mediaID = stripper[0] newCategoryName = stripper[1].title() newCategoryID = adapter.get_MediaCategoryID(newCategoryName) except: # if there aren't enough parts return False # returns false return mediaID, newCategoryID
def parseMedia_insert(mediaInfo): try: stripper = [x.strip() for x in mediaInfo.split(',', 4)] theMediaType = adapter.get_MediaTypeID(stripper[0]) theMediaCategory = adapter.get_MediaCategoryID(stripper[1]) theUser = sanitizeID(stripper[2]) isLong = longGame(stripper[3]) theFullName = stripper[4] insertString = "{}, {}, '{}', '{}', {}".format(theMediaType, theMediaCategory, theUser, theFullName, isLong) except: # if there aren't enough parts return False # returns false return insertString, theFullName
def addToDB(someFile): fileOBJ = None try: fileOBJ = open(someFile,"r") except: print("no") sys.exit() i = 0 err = 0 errList = [] for line in fileOBJ.readlines(): try: MediaType, MediaCategory, Owner, LongGame, FullName = line.split(",", 4) theMediaType = adapter.get_MediaTypeID(MediaType) theMediaCategory = adapter.get_MediaCategoryID(MediaCategory) slackID = adapter.getSlackID(Owner).upper() isLong = longGame(LongGame) theFullName = FullName.strip('\n') insertString = "{}, {}, '{}', '{}', {}".format(theMediaType, theMediaCategory, slackID, theFullName, isLong) result = adapter.insert_Media(insertString) if result: print("Error inserting: {}".format(insertString)) print("Inserting: {}".format(insertString)) except: err += 1 errList.append(insertString) print("Insert complete. With errors: {}".format(err)) print(errList) return