github.com/pachyderm/pachyderm@v1.13.4/examples/joins/src/outer/main.py (about) 1 #!/usr/local/bin/python3 2 import glob, json, os, shutil, sys 3 4 5 store_paths = glob.glob(os.path.join("/pfs/stores", "*.txt")) 6 return_paths = glob.glob(os.path.join("/pfs/returns", "*.txt")) 7 8 9 zipcode = "UNKNOWN" 10 separator_line = "\nThis return store does not exist \n" 11 if store_paths: 12 print("Opening store_file...: " + store_paths[0]) 13 with open(store_paths[0], 'r') as store_json: 14 store = json.load(store_json) 15 zipcode = store['address']['zipcode'] 16 # Add a text separator to identify in what store the purchase was made 17 separator_line = "\nReturn at store: "+ str(store["storeid"]) +" - "+ store["name"]+" \n" 18 print("zipcode: " + zipcode) 19 20 with open("/pfs/out/"+zipcode+".txt", 'w') as location_file: 21 location_file.write(separator_line) 22 if return_paths: 23 print("Appending : " + return_paths[0] + " to:" + "/pfs/out/"+zipcode+".txt") 24 # Copy the content of the purchase file into the corresponding zipcode file 25 with open(return_paths[0], 'r') as return_file: 26 location_file.write(return_file.read()) 27 28 29 30