def main(): configutation = Configuration().load() path = configutation.get('upload_folder') if path: for file_name in get_file_names(path): file_changed = False result = None f = os.path.basename(file_name) file_object = get_file_object_or_create(f) current_file_info = get_file_info(file_name) current_file_timestamp = current_file_info[0].replace('-', '').replace(':', '').replace(' ', '') # file exist if file_object.timestamp: if file_object.timestamp < current_file_timestamp: file_changed = True # 2. TODO: Do POST, set result result = 200 # 2. Update model file_object.updated_at = datetime.utcnow() file_object.timestamp = current_file_timestamp else: # 1. TODO: Do POST, set result result = 200 file_object.updated_at = datetime.utcnow() file_object.timestamp = current_file_timestamp file_changed = True db.session.add(file_object) db.session.commit() if file_changed: event_type_file_changed = EventType.query.get(4) event_file_changed = Event(name='%s changed ' % f, event_type=event_type_file_changed, file=file_object, date=None, file_attrs=str(current_file_info), result_code=None) db.session.add(event_file_changed) db.session.commit() if result: event_type_uploading = EventType.query.get(3) event_file_uploading = Event(name='%s uploading ' % f, event_type=event_type_uploading, file=file_object, date=None, file_attrs=str(current_file_info), result_code=result) db.session.add(event_file_uploading) db.session.commit()
def run(self): configuration = Configuration() configuration.load() path = configuration.upload_folder tick = configuration.tick #file_name = os.path.abspath(os.path.join(os.path.dirname(__file__), 'fuckup.log')) while True: if path: for file_name in get_file_names(path): file_changed = False result = None f = os.path.basename(file_name) file_object = get_file_object_or_create(f) current_file_info = get_file_info(file_name) current_file_timestamp = current_file_info[0].replace('-', '').replace(':', '').replace(' ', '') #file exist if file_object.timestamp: if int(file_object.timestamp) < int(current_file_timestamp): file_changed = True upload_file(file_name, file_object, current_file_timestamp) else: file_changed = True upload_file(file_name, file_object, current_file_timestamp) time.sleep(float(tick))
import modules.utils as u #Method 1 u.get_file_names("./modules/") #Method 2 u.get_all_file_names("./modules/") #Method 3 myList = [ "myFile.csv", "output.txt", "utils.py", "week2ex1c.py", "Week_2.ipynb" ] u.print_line_one(myList) #Method 4 list_emails = [ "myFile.csv", "*****@*****.**", "utils.py", "*****@*****.**", "Week_2.ipynb" ] u.print_emails(list_emails) #Method 5 md_list = ["./modules/read.md", "./modules/readme.md"] u.write_headlines(md_list)
def test_get_file_names(folderpath): utils.get_file_names(folderpath)
# print('List:', args.list) # print('Len', vars(args)) # only first arg. usage: python_handin_template/Week_2.py python_handin_template/datamsg.txt if not (args.output_file and args.list): print_file_content_2(args.input_file) # only input and output. usage: python python_handin_template/Week_2.py python_handin_template/datamsg.txt -f python_handin_template/datawrite.txt -l word1 word2 word3 else: lst = print_file_content_2(args.input_file) # not sure why the commented lines were necessary in Thomas' sample file. Seems to work without. # if args.list: # lst.extend(args.list) # print('LISTEN:',lst) write_list_to_file(args.output_file, args.list) # Exercise 2 from modules import utils print("Exercise 2") print("Get file names (writing to file output.txt)") utils.get_file_names('./') print("Get all file names (writing to file output2.txt") utils.get_all_file_names('./') print("Print first line of file:") utils.print_line_one('python_handin_template/file_data/datamsg2.txt', 'python_handin_template/file_data/datamsg.txt') print("Print all rows containing email (@ validation):") utils.print_emails('python_handin_template/file_data/datamsg2.txt', 'python_handin_template/file_data/datamsg.txt') print("Print all rows containing headline of MD files (# validation):") utils.write_headlines('python_handin_template/README.md', 'python_handin_template/file_data/README.md')
import modules.utils as util if __name__ == '__main__': util.get_file_names("/home/jovyan/python_handin_template") util.get_all_file_names("/home/jovyan/python_handin_template") file_list = ["output1.txt", "output.txt", "python_handin_template/textfiles/pythonfile.csv"] util.print_line_one(file_list) email_list = ["readtest.txt", "output1.txt", "python_handin_template/textfiles/emails.txt"] util.print_emails(email_list) util.write_headlines("python_handin_template/textfiles/headlines.md")
from modules.utils import get_all_file_names, get_file_names, print_line_one, print_emails, write_headlines get_file_names("C:\\Users\\claes\\PycharmProjects\\Giraffe", "file1.txt") get_all_file_names( "C:\\Datamatiker\\4.semester\\Python\\master\\docker_notebooks\\server", "file1.txt") print_line_one(['C:\\Users\\claes\\PycharmProjects\\Giraffe\\file2.txt', 'C:\\Users\\claes\\PycharmProjects\\Giraffe\\file2.txt', 'C:\\Users\\claes\\PycharmProjects\\Giraffe\\file2.csv']) print_emails(['*****@*****.**', 'aflev2B.py', 'arg_parse.py', '*****@*****.**', '*****@*****.**'])