class Upload(object): """ TODO interface or abstract class for upload services """ def __init__(self, config, service_type): self.__config = config if service_type == SERVICE_DRIVE: self.service = Drive(config) elif service_type == SERVICE_DROPBOX: raise NotImplementedError('not implemented yet!') def run(self, paths): """ """ for path in paths: self.service.upload(path) log_dict(self.service.info)
class Upload(object): """ TODO interface or abstract class for upload services """ def __init__(self, config, service_type): self.__config = config self.info = { 'details': [] } if service_type == SERVICE_DRIVE: self.service = Drive(config) elif service_type == SERVICE_DROPBOX: raise NotImplementedError('not implemented yet!') def run(self, paths): """ """ for path in paths: self.service.upload(path) self.info['details'].append(self.service.info) log_dict(self.service.info)
def get_ID(self, mid, date, statement): dr = Drive() mn = Main() print(mid, date, statement) currentdate = date.replace(day=1) headers = ["MID", "date", "fileID", "folderID"] sect = {} try: my_query = "SELECT * from statementData.notifyStatement where MID like '{}' and `date` = '{}' limit 1".format( "','".join(mid), str(currentdate.date())) print(my_query) fileID = [item for item in callConnection(self.confir, my_query)] print("This is my search for file id: {}".format(fileID)) if not fileID: my_query = "SELECT * from notifyStatement where MID = '{}' limit 1".format( "','".join(mid)) midID = [ item for item in callConnection(self.confir, my_query) ] print(midID) if midID: midID = midID[0] print("all get the folder than " + str(midID)) fileID = dr.upload(statement, str(date.date()), midID[3]) print("This is my file" + fileID) if fileID: ins = "INSERT into notifyStatement({}) Values('{}')".format( "`mid`,`date`,`fileID`,`folderID`", "','".join( [mid[0], str(currentdate), fileID, folderID])) print(ins) if callConnection(self.confir, ins): sect["success"] = { "MID": mid, "date": str(currentdate), "fileID": fileID, "folderID": midID[3] } else: respo = "The current month does not exist yet for {}".format( mid[0]) print(respo) sect["error"] = respo else: print("creating the folder from :" + str(mid[0]), folderID) midID = dr.createFolder(str(mid[0]), folderID) print("This is my mid :" + midID) name = "{}.pdf".format(str(date.date())) fileID = dr.upload(statement, name, midID) print("This is my file :" + fileID) if fileID: ins = "INSERT into notifyStatement({}) Values('{}')".format( "`mid`,`date`,`fileID`,`folderID`", "','".join( [mid[0], str(currentdate), fileID, midID])) print(ins) if callConnection(self.confir, ins): sect["success"] = { "MID": mid, "date": str(currentdate), "fileID": fileID, "folderID": midID } else: respo = "The current month does not exist yet for {}".format( mid[0]) print(respo) sect["error"] = respo else: fileID = [str(i) for i in list(fileID[0])] sect["success"] = dict(zip(headers, fileID)) except: print(sys.exc_info()) sect["error"] = sys.exc_info() raise return sect
def get_ID(self, mid, date, statement): dr = Drive() mn = Main() print(mid, date, statement) currentdate = date.replace(day=1) headers = ["MID", "date", "fileID", "folderID"] sect = {} lnmid = "','".join(mid) curdate = currentdate.date() try: my_query = "SELECT * from statementData.notifyStatement where MID like '{lnmid}' and `date` = '{curdate}' limit 1" print(my_query) fileID = [item for item in self.confir.execute(my_query)] print(f"This is my search for file id: {fileID}") if not fileID: my_query = f"SELECT * from notifyStatement where MID = '{lnmid}' limit 1" midID = [item for item in self.confir.execute(my_query)] print(midID) if midID: midID = midID[0] print(f"all get the folder than {midID}") fileID = dr.upload(statement, str(date.date()), midID[3]) print("This is my file" + fileID) if fileID: ins = "INSERT into notifyStatement(`mid`,`date`,`fileID`,`folderID`) Values('{val}')".format(val="','".join([mid[0], str(currentdate), fileID, folderID])) print(ins) try: self.confir.execute(ins) except IntegrityError: pass sect["success"] = {"MID": mid, "date": str(currentdate), "fileID": fileID, "folderID": midID[3]} else: respo = "The current month does not exist yet for {0}".format(mid[0]) print(respo) sect["error"] = respo else: print("creating the folder from : {mid}, {id}".format(mid = mid[0], id=folderID)) midID= dr.createFolder(str(mid[0]), folderID) print(f"This is my mid :{midID}") name = f"{date.date()}.pdf" fileID = dr.upload(statement, name, midID) print(f"This is my file : {fileID}") if fileID: ins = "INSERT into notifyStatement(`mid`,`date`,`fileID`,`folderID`) Values('{val}')".format("','".join([mid[0], str(currentdate), fileID, midID])) print(ins) try: self.confir.execute(ins) except IntegrityError: pass sect["success"] = {"MID": mid, "date": str(currentdate), "fileID": fileID, "folderID": midID} else: respo = "The current month does not exist yet for {mid}".format(mid=mid[0]) print(respo) sect["error"] = respo else: fileID = [str(i) for i in list(fileID[0])] sect["success"] = dict(zip(headers, fileID)) except: print(sys.exc_info()) sect["error"] = sys.exc_info() raise return sect