Skip to content

Instantly share code, notes, and snippets.

@mdeguzis
Created April 19, 2018 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdeguzis/241cfa26fbb89ff1ac68b8ba45cc35c0 to your computer and use it in GitHub Desktop.
Save mdeguzis/241cfa26fbb89ff1ac68b8ba45cc35c0 to your computer and use it in GitHub Desktop.
json_text = r.json()
# get total length of dictionary keys for tracking
for key, value in json_text.iteritems():
item_index = 0
if key == 'FileStatuses':
total_items = len(json_text['FileStatuses']['FileStatus'][:])
for listitems in json_text['FileStatuses']['FileStatus'][:]:
perm_set = []
item_count = len(json_text['FileStatuses']['FileStatus'][:])
octal_perms = json_text['FileStatuses']['FileStatus'][item_index]['permission']
replcount = json_text['FileStatuses']['FileStatus'][item_index]['replication']
fileuser = json_text['FileStatuses']['FileStatus'][item_index]['owner']
filegroup = json_text['FileStatuses']['FileStatus'][item_index]['group']
filename = json_text['FileStatuses']['FileStatus'][item_index]['pathSuffix']
filetype = json_text['FileStatuses']['FileStatus'][item_index]['type']
filelength = json_text['FileStatuses']['FileStatus'][item_index]['length']
# modtime is epoch (UNIX time) with the last 3 digits as milliseconds
modtime_epoch = json_text['FileStatuses']['FileStatus'][item_index]['modificationTime']
modtime = time.strftime('%Y-%m-%d %H:%M', time.gmtime(modtime_epoch/1000.0))
# update counter
item_index += 1
logging.debug("Analyzing " + str(item_index) + ' out of ' + str(total_items))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment