Skip to content

Instantly share code, notes, and snippets.

@jeffbass
Created July 31, 2020 21:37
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 jeffbass/d8d89b71e9140c7bc2a2f0c150532ba5 to your computer and use it in GitHub Desktop.
Save jeffbass/d8d89b71e9140c7bc2a2f0c150532ba5 to your computer and use it in GitHub Desktop.
Example of a tiny Python data analysis program to count images by date
# Use subprocess.run() to list the number of imagehub_data images for each date
#
# Copyright (c) 2018 by Jeff Bass.
# License: MIT, see LICENSE for more details.
import os
import subprocess
def n_images(dir):
command = 'ls -l ' + dir + ' | wc -l'
return subprocess.run(command, stdout=subprocess.PIPE, shell=True, universal_newlines=True).stdout
# enter the starting date below; will print daily image totals from that date to today
start_year = '2020'
start_month = '07'
start_day = '28'
output = subprocess.run(['ls'], stdout=subprocess.PIPE, universal_newlines=True)
dirs = output.stdout.splitlines()
for dir in dirs:
year = dir[0:4]
if year == start_year:
month = dir[5:7]
if month == start_month:
day = dir[8:]
if day >= start_day:
print(dir, n_images(dir))
elif month > start_month:
print(dir, n_images(dir))
""" Here's a simlar experiment using os.walk(); Linux utility 'ls' above worked faster
for root, dirs, files in os.walk('.'):
i = 1
for dir in dirs:
month = dir[5:7]
day = dir[8:]
print(dir, month, day)
i += 1
if i > 10:
break
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment