def login(): ''' Login end point ''' if request.method == "POST": # load JSON data from request data = json.loads(request.data) # search for user's player record, returning a single line '0' switch player_record = file_operations.search_from_file( 'data/players.txt', data['userName'], 0) if (player_record): username_score = player_record.split(',') # update players file with username, total score, 1 switch denotes # user is logged in file_operations.update_file('data/players.txt', username_score[0], username_score[1] + ',1') else: # write new user to file username, 0 total score and 1 switch # denotes user is logged in file_operations.write_to_file('data/players.txt', data['userName'] + ',0' + ',1') username_score = [data['userName'], 0] response = app.response_class(response=json.dumps({ 'user_name': username_score[0], 'total_score': username_score[1] }), status=200, mimetype='application/json') response.headers['Access-Control-Allow-Origin'] = '*' return response
def song_total_score(): ''' Save total song score end point ''' if request.method == "POST": # load JSON data from request data = json.loads(request.data) file_operations.write_to_file('data/song_scores.txt', data['writeData']) response = app.response_class(status=200, mimetype='application/json') return response
def main(): args = cli_parser.parse_arguments() if args.list: bookmarks_object_wrappers_list = list( file_operations.load_bookmarks_files(args.files)) with open(args.output, "w") as output: for bookmarks_object_wrapper in bookmarks_object_wrappers_list: output.write(bookmarks_object_wrapper.get("name") + "\n") bookmark_utils.print_pretty_url_tree( bookmarks_object_wrapper.get("json").get("children"), output) output.write("\n") if args.merge or args.merge_to_subdir: if len(args.files) > 1: bookmarks_object_wrappers_list = list( file_operations.load_bookmarks_files(args.files)) main_bookmarks_object = bookmarks_object_wrappers_list[0].get( "json") if args.merge: for other_bookmarks_object_wrapper in bookmarks_object_wrappers_list[ 1:]: bookmark_utils.merge_into( main_bookmarks_object, other_bookmarks_object_wrapper.get("json")) file_operations.write_to_file( args.output, json.dumps(main_bookmarks_object, indent=4)) elif args.merge_to_subdir: for other_bookmarks_object_wrapper in bookmarks_object_wrappers_list[ 1:]: bookmark_utils.merge_to_subdir( main_bookmarks_object, other_bookmarks_object_wrapper.get("json"), other_bookmarks_object_wrapper.get("name")) file_operations.write_to_file( args.output, json.dumps(main_bookmarks_object, indent=4)) else: print("Not enough files for merge")
def main(): args = cli_parser.parse_arguments() bookmarks_object = load_bookmarks_file(args.file) deduplicate_and_merge_all(bookmarks_object) write_to_file(args.output, json.dumps(bookmarks_object, indent=4))
PASCAL_OPERATORS = [ '+', '-', '*', '/', '%', # Arithmetic Operators '=', '<>', '>', '<', '>=', '<=', '><', # Relational Operators '&', '|', '!', '~', '<<', '>>', # Bit Operators ':=', ';', 'and', 'and then', 'or', 'or else', 'not' # Boolean Operators ] def single_operator_in_line(text, operators=PASCAL_OPERATORS): output = text for operator in operators: if operator in text: output = sub(r'{}'.format(escape(operator)), '\g<0>\n', output) return output if __name__ == '__main__': from file_operations import create_output_folder, read_file, write_to_file file_path = argv[1] file_name = os.path.basename(file_path) output_folder_path = '{}/output'.format(os.path.dirname(os.path.realpath(__file__))) create_output_folder(output_folder_path) text = single_operator_in_line(read_file(file_path)) write_to_file(output_folder_path, file_name, text)