Created
July 31, 2020 21:37
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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