{"id":5069,"date":"2015-12-21T13:00:10","date_gmt":"2015-12-21T17:00:10","guid":{"rendered":"https:\/\/www.urbin.net\/blog\/?p=5069"},"modified":"2015-12-21T13:00:10","modified_gmt":"2015-12-21T17:00:10","slug":"sorting-pictures","status":"publish","type":"post","link":"https:\/\/urbin.net\/blog\/photography\/sorting-pictures\/","title":{"rendered":"Sorting pictures"},"content":{"rendered":"<p>I\u2019ve been backing up my iPhone photos to my Windows 10 desktop using Microsoft\u2019s OneDrive. \u00a0The photos are on my local drive as well as the cloud. \u00a0The downside is that all the photos, movies, and screen shots are dumped into a single directory, and there are <em>a lot<\/em> of them.<\/p>\n<p>I prefer to have them sorted by date into directories. \u00a0A directory for each year, with sub-directories for each month. \u00a0I could do this by hand, but that\u2019s a pain, and I have to remember to do it on a regular basis. \u00a0Plus I\u2019ll probably want to do the same for my wife\u2019s iPhone photos. \u00a0So I decided to write a python script to scan the camera roll directory, and copy the files to a directory in my photo archive section. \u00a0The scrip will create directories if needed and skip files that are already in place.<\/p>\n<p>That part was pretty straight forward. I used\u00a0os.chdir() to get to source directory and os.listdir() to get the directory contents. \u00a0Don\u2019t want to create month directories for directories, just files, so I used os.path.isfile() to filter out non-files, and then check the file extension. \u00a0I only want jpg, mov, png, and tiff files. \u00a0I use <a href=\"http:\/\/campl.us\/\">Camera+<\/a>\u00a0most of the time, which produces tiff files instead of jpg files. The png files are screenshots.<\/p>\n<p>I used os.stat() to get the create time, and found files I exported to the camera roll from Camera plus had a create time of when they were exported, not the time the photo was taken. (Once I started having Camera+ dump straight to the camera roll, I didn\u2019t have this problem).<\/p>\n<p>So, I dug a little deeper and found I could get an image created time stamp with a getImageDate() call. \u00a0Downside was this didn\u2019t work for png, tiff, or mov files. \u00a0 So I had to do some extra sorting, and wrote another function to use on\u00a0just the jpg files. I called the open() function from the Image library, and extracted the exif data using the _getexif() function. This works most of the time, so when it fails I had it return a \u2018?\u2019 rather than the time stamp string. \u00a0Seeing that caused a fall back to the getImageDate() function.<\/p>\n<p>This extra call to the Image library made the placement of the files more accurate. \u00a0I had the base time function return the month as a three character string and the year as a 4 characters string. \u00a0This required some basic string manipulation. Those two parameters were added to predetermined destination and passed to a function I had written for another project that checks if directory exits, and creates it if it does not.<\/p>\n<p>Next\u00a0was to have the program check to see if the file already existed in the correct destination directory. \u00a0If it did, don\u2019t bother copying it again. This will make the incremental runs faster and save on unneeded file transfers.<\/p>\n<p>Now I have a functional script that I can set up to automatically run once a week. \u00a0Once the files are archived off OneDrive, I can removed them there and on the iPhone is order to free up space.<\/p>\n<p><a href=\"http:\/\/urbintechnology.com\/2015\/12\/21\/sorting-pictures\/\">Originally posted to Urbin Technology<\/a>. \u00a0I put the source code for the time stamp functions there.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve been backing up my iPhone photos to my Windows 10 desktop using Microsoft\u2019s OneDrive. \u00a0The photos are on my local drive as well as the cloud. \u00a0The downside is that all the photos, movies, and screen shots are dumped into a single directory, and there are a lot of them. I prefer to have [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_themeisle_gutenberg_block_has_review":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[18,55,30],"tags":[605,635,759],"class_list":["post-5069","post","type-post","status-publish","format-standard","hentry","category-photography","category-smartphones-pdas","category-technology","tag-photography","tag-python","tag-technology"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pab4zg-1jL","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/urbin.net\/blog\/wp-json\/wp\/v2\/posts\/5069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/urbin.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/urbin.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/urbin.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/urbin.net\/blog\/wp-json\/wp\/v2\/comments?post=5069"}],"version-history":[{"count":0,"href":"https:\/\/urbin.net\/blog\/wp-json\/wp\/v2\/posts\/5069\/revisions"}],"wp:attachment":[{"href":"https:\/\/urbin.net\/blog\/wp-json\/wp\/v2\/media?parent=5069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/urbin.net\/blog\/wp-json\/wp\/v2\/categories?post=5069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/urbin.net\/blog\/wp-json\/wp\/v2\/tags?post=5069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}