Sorting pictures

I’ve been backing up my iPhone photos to my Windows 10 desktop using Microsoft’s OneDrive.  The photos are on my local drive as well as the cloud.  The 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 them sorted by date into directories.  A directory for each year, with sub-directories for each month.  I could do this by hand, but that’s a pain, and I have to remember to do it on a regular basis.  Plus I’ll probably want to do the same for my wife’s iPhone photos.  So 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.  The scrip will create directories if needed and skip files that are already in place.

That part was pretty straight forward. I used os.chdir() to get to source directory and os.listdir() to get the directory contents.  Don’t 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.  I only want jpg, mov, png, and tiff files.  I use Camera+ most of the time, which produces tiff files instead of jpg files. The png files are screenshots.

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’t have this problem).

So, I dug a little deeper and found I could get an image created time stamp with a getImageDate() call.  Downside was this didn’t work for png, tiff, or mov files.   So I had to do some extra sorting, and wrote another function to use on just 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 ‘?’ rather than the time stamp string.  Seeing that caused a fall back to the getImageDate() function.

This extra call to the Image library made the placement of the files more accurate.  I had the base time function return the month as a three character string and the year as a 4 characters string.  This 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.

Next was to have the program check to see if the file already existed in the correct destination directory.  If it did, don’t bother copying it again. This will make the incremental runs faster and save on unneeded file transfers.

Now I have a functional script that I can set up to automatically run once a week.  Once the files are archived off OneDrive, I can removed them there and on the iPhone is order to free up space.

Update: Source Code

The tricky part is getting the time stamps.  Here are the three routines that handle that.  Wordpress mucks with the spacing, but you should be able to figure it out.

def getImageDate(sPath,file):
    'Get the image created time stamp'
    img = Image.open(sPath + "\\" + file)
 
    tTime = "?"
    imgData = img._getexif()
 
    if 306 in imgData and imgData[306] < tTime: # 306 = DateTime
        tTime = imgData[306]
     if 36867 in imgData and imgData[36867] < tTime: # 36867 =                             DateTimeOriginal
         tTime = imgData[36867]
     if 36868 in imgData and imgData[36868] < tTime: # 36868 =         DateTimeDigitized
          tTime = imgData[36868]
      return tTime
def getTime2(file,sPath):
    'If the file is not a jpg, get the last modified time, which is close enough'
    os.chdir(sPath)
    (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(file)
    year = time.ctime(mtime)[-4:]
    month = time.ctime(mtime)[4:7]

return month, year

def getTime(sPath,dPath,file):
     'Most files are jpg files, so this is the default path'
      month = "Jan"
     year = "1956" #If we see this year, we know there is a problem
     months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
     ext = file[-3:].lower()
     if ext == 'jpg':
          cTime = getImageDate(sPath,file)
           if cTime != '?':
                   year = cTime[0:4]
                    monthNum = cTime[5:7]
                    month = months[(int(monthNum)) - 1]
            else:
                       month,year = getTime2(file,sPath)
    else:
            month,year = getTime2(file,sPath)
    return month,year

Apple Watch

I broke down a bought an Apple Watch several months ago. I went for the Sport model with the basic Sport band. That kept the cost down to $400. The “Watch” model was another $200 with no change in functionality. The only difference would be in the materials. A steel case and a sapphire crystal.
This was not my first wearable. I had a Fitbit Force, which was recalled. I was happy with the fitness functionality & the iPhone software package. My opinions on the band are well documented.

 So far, I’m more pleased with the Apple Watch. It is much more versatile, and has comparable fitness tracking functions.  

 As a watch, the Apple Watch is actually usable. The software does a good job of displaying when I raise my arm and rotate the watch upward. This is a vast improvement over the Fitbit, where I had to press a button (flashback to the early digital watches). My one nit is that the Apple Watch software is calibrate for wearing it on the outside of the wrist. I wore my watch on the inside of my wrist for decades, and the Apple Watch wasn’t happy with this. This limitation has me back to wearing my watch on the outside of my wrist. 

 There are ten watch faces loaded, each configurable. I’ve been switching around on an irregular basis. My preference is for traditional analog watch faces. This includes the Mickey Mouse option. The watch faces are configurable for color and options like day, date, timer, stop watch, fitness rings, and battery life.

 In all, I’m happy with it. The fitness function is what I use the most (outside of actually using the watch to tell time). I really like the message and phone preview functions. Being able to review/preview messages and calls and deal with most of them quickly is more of a feature that I thought it would be.

 Watch OS 2 is due out next week. I’ll post my impressions after I play around with it a bit.

Building the better Macbook dongle

As I have said before, the single USB C port is the weak point of the new Macbook.  I’m not overly impressed with the $80 dongle solution from Apple either.

The nice folks at Nonda have slicker solution, at the same price, but only for about another 24 hours.   After the Kickstarter campaign is over, it’s going to run about double the price and still, IMHO, worth it.  The Apple dongle gives you a USB C port for power only, a USB 3.0 port, and an HDMI port.  The Hub+ gives you the following:

  • 2 USB-C ports
  • 1 SDXC card reader
  • 1 mini DisplayPort (mDP 1.2 video output, 4k displays at 60Hz refresh rate)
  • 3 USB-A 3.0 \ charging ports
  • Built-in lithium ion battery to charge ANY phone

Display Port keeps the price down (HDMI needs licensing) and mini DisplayPort to HDMI cables are easy to get.  If you sprung for a new MacBook, grab one of these as well.

The new MacBook

I’ve been reading the specs on the recently announced Macbook.

It certainly is a very slick bit of technology.  Apple poured a lot of research into creating this ultra thin notebook.  Keyboard, display, batteries, motherboard, and the port list, all redesigned nearly from scratch.  About the only thing they didn’t redesign was the headphone jack.

 All this new technology didn’t come cheap either.  The low end one runs $1299.  Compare this to a 13″ Macbook Air with a comparable configuration .  The biggest difference is the MacBook’s Retina display, but the Air wins on battery life, processor, and ports (two USB 3, one Thunderbolt 2, power, SD, and a headphone jack).  Oh, and the Air weighs about a pound more.

 Apple does have a solution for their “all in one” USB-C port, in the way of a $80 dongle that provides a trio of ports (HDMI/USB 3/USB-C).  So now you can charge your macBook (via USB-C),  and attach a USB memory device at the same time.

 Personally I love the idea of USB-C, but I also like doing things in parallel.  This also brings Apple’s commitment to the Thunderbolt port into question.  A lot of third party manufacturers have sunk a lot of capital into Thunderbolt based devices, especially for secondary storage.

 My goto laptop is my 13″ MacBook Air, which I’m not planning on replacing anytime soon.  Ya, the batteries are on the downside of the curve, but Apple can replace those for approximately $150.  That is a lot cheaper than purchasing a new laptop I don’t need (I do the heavy computing and storage tasks on my home build Windows system).

 Of course the serious Apple fan nerds are going to buy a Macbook as soon as they are out.  My plan is to wait for the next rev.  I would like to see a next gen MacBook Pro with Macbook technology.  High end CPU, and a Thunderbolt and SD slot go with the USB-C and headphone jack.

 Disclaimer: I’m talking about serious Apple fan nerds, at least bigger ones than me.  I just have an iPhone 6 Plus, an iPad Air, and two MacBooks.

Gear Update

I picked up an iPhone 6 Plus. Yes, the sucker is big, but it does fit in my pockets. Both pants and shirt. The bigger screen is nice. More real estate, better for view high res pictures and videos. The real plus of the larger size is the vastly improved battery life. This is due the all the extra space behind the screen being packed with a bigger battery. I can use Waze on the way to work, use the phone to check email and take notes all day, and then Waze on the way home. After all that, I still have a decent charge when I get home. It really is a big improvement over my iPhone 5.

The camera is also a big improvement. I typically use the Camera+ app for stills. I have it set to save giant TIF files. Gives you more data to work with in Lightroom, Pixelmator, or Picasa. The editing functions in Camera+ are also richer than the iOS defaults.

The perils of USB

USB has been great.  Connect anything to your system, it’s usually auto recognized, so it fits that useful category of “stuff that just works.”

Now Wired has pointed out that from a security standpoint, USB has some serious, fundamental flaws. In other words, you may be completely and utterly screwed.

It’s not just malware may be lurking on USB memory devices, perhaps even installed at the factory.  A couple of clever lads have figured out how to reprogram the flash that controls just about any USB device.   Which is pretty much like giving them the keys to the Kingdom.  Here are some of the scary highlights from the article.

“Because BadUSB resides not in the flash memory storage of USB devices, but in the firmware that controls their basic functions, the attack code can remain hidden long after the contents of the device’s memory would appear to the average user to be deleted.”

I’m waiting for the standalone device that reads and reflashes USB firmware to hit the IT market at an obscene profit margin.

Wait! It gets worse.

The problem isn’t limited to thumb drives. All manner of USB devices from keyboards and mice to smartphones have firmware that can be reprogrammed—in addition to USB memory sticks, Nohl and Lell say they’ve also tested their attack on an Android handset plugged into a PC. And once a BadUSB-infected device is connected to a computer, Nohl and Lell describe a grab bag of evil tricks it can play. It can, for example, replace software being installed with with a corrupted or backdoored version. It can even impersonate a USB keyboard to suddenly start typing commands. “It can do whatever you can do with a keyboard, which is basically everything a computer does,” says Nohl.

The malware can silently hijack internet traffic too, changing a computer’s DNS settings to siphon traffic to any servers it pleases. Or if the code is planted on a phone or another device with an internet connection, it can act as a man-in-the-middle, secretly spying on communications as it relays them from the victim’s machine.

So the new mantra is don’t let your keys or any USB device out of your sight.

 

 

DARPA looking for a shuttle replacement

With the shuttle retired and funding for the Orion killed back in 2009, the US is currently without a way to get people into space or a relatively cheap way to get payloads into orbit.

DARPA has apparently decided not to wait for NASA, and has called for commercial companies to propose candidates for their XS-1 space plane.

DARPA’s key technical goals for the XS-1 include flying 10 times in 10 days, flying to Mach 10+ at least once and launching a representative small payload to orbit. The program also seeks to reduce the cost of access to space for 3,000- to 5,000-pound payloads to less than $5 million per flight.

Having this capability will fill a hole in LEO access left by NASA policy and budget constraints.