Friday, November 23, 2012

Randomize Digital Picture Frame Photos

I just put some photos on a digital picture frame (Smartparts SPX8E) to be displayed at a funeral.  I was disappointed to find that the photos could not be randomized.  In some cases the viewer would see many of the same photos in a row.  I went through all of the settings and could not find a way to fix this.

My first thought was to write a short Python script to rename all of the files with a random name.  This seemed easy enough, but someone must've come across this issue already...

Of course, someone has created a little tool to do this.  Check out this Windows batch file from Jason Faulkner on howtogeek.com.

The script is easy to use.
  • Insert the USB stick with the photos on it.  (I copied all of the photos to a backup folder just in case.)
  • Navigate to the USB stick in a DOS window on your Windows machine.  Here is a directory listing of the F: drive, which is the USB stick:

  • Notice many of the files have consecutive names?  This is what I want to change. 
  • Copy the batch file to this location (in this case F:\).
  • Run the batch file.  Just type "randomnames" and hit enter.  This is what you should see:


  • Type OK.  Don't sweat it.  When the script has finished, do another directory listing (type 'dir'):


Great, the photos all have random names now.  I inserted the stick into the picture frame...

This didn't change the order at all!  Was it the file date that needed to be changed?

With the USB stick back in my laptop, I updated the date on all of the files.  The POSIX utility 'touch' could be used to do this.  I used a program called ZTree to update the date on all of the files to today's date.

I tried again with updated dates.  No difference.  The files were still being displayed in the original order!  Now, the only thing I could think of is that the files are being read at a very low level, meaning they are simply being read from the stick in the physical order they are stored there.  The remedy for this is simply to move all of the files to your hard drive (either by using the move command or by copying them all and then deleting them), and then copy them back to the USB stick.

You should be able to use Windows Explorer to do this.  Again, I used ZTree.  Sort by name before copying back to the USB stick, and they should be copied in a 'random' order, because the names are already randomized.

Finally, it worked!  The photos are now displayed in a random order.  A simplified version of the steps:
  1. Start with a blank USB stick.
  2. Copy all of the photos you want to display into a temp directory on your hard drive.
  3. Copy the batch file "RenameFiles.bat" into the temp folder you just created.
  4. Execute the batch file to rename all of the files randomly.
  5. Use Windows Explorer and sort all of the files by name.
  6. Copy all of the files onto the blank USB stick.
  7. Finished.
Thanks to Jason Faulkner for writing and publishing the script to randomize filenames.

Thursday, September 20, 2012

Download all Links from a Webpage with Python

Man, I love Python and BeautifulSoup!

I wanted to download a bunch of files from a webpage.  Fortunately we have Python.  Watch how ridiculously easy this is:

C:\>python
Python 2.6 (r26:66721, Oct  2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win 32
Type "help", "copyright", "credits" or "license" for more information.
>>> from BeautifulSoup import *

>>> import urllib
>>> import urllib2
>>> baseurl = "http://whatever.com/files/here/"
>>> soup = BeautifulSoup(urllib2.urlopen(baseurl))
>>> links=soup.findAll("a")
>>> for link in links[5:]:
...    print link.text
...    urllib.urlretrieve(baseurl+link.text, link.text)



--- Now watch the fun, your downloads have begun. ---

So now a little explanation.  BeautifulSoup is an HTML parser, and a damn good one at that.  It can handle really badly formed HTML with grace, and makes it really easy to do screen-scraping.  Really cool stuff.  

Basically my variable 'soup' will hold the entire contents of the webpage.  Now that object has a lot of capabilities, you will want to check out the BeautifulSoup docs to learn all of what it can do.  How about this:

soup.findAll("a")  #Boom.  This will return a Python list of all "a" tags


Now all I do is loop through them all.  I skip the first few because after inspection, these weren't files and I don't care about them.  Now I just call the urllib.urlretrieve(url, filename).  link.text is the actual text of the link.


In retrospect I probably should've done (urlretrieve(baseurl+link.href, link.text)), but you can figure that out for yourself.  This is meant to be inspiration and to apply this you might have to make some changes to these nine lines.  

Nine lines!!




Wednesday, September 19, 2012

ATV Riding in Indian River, MI, and GPS Tools

I've tried most of the GPS mapping solutions out there for Android, using my $45 Samsung phone (Craigslist find) as the test bed.  I was really hoping I could get an open source solution that would meet my needs.  The closest I found was called Aripuca.  It is almost exactly what I want, and I started playing around with the code, there is a lot of promise to this app.

The most advertising I saw was for Backcountry Navigator.  This app has good ratings on the Google Play store, but costs $10.  I figure this is not a bad price to pay if it is decent.  I tried the trial version and eventually bought the pro version.  I was quickly finding a lot of bugs with this app, such as my tracks drawing in the middle of a lake or a lot of flicker on the screen when the maps would redraw.

In between I'm not sure how many others I tried, but my favorite by far is a gem called OruxMaps.  If you're used to a Garmin eTrex, you will feel pretty close to home using this app.  It is EXTREMELY customizable and 'just works'.  Never had a FC, and almost always had expected behavior.  The only strange thing I found was at some point I had it navigating to a point, and I could not figure out how to 'cancel' the navigation, so it was always drawing a straight line from my position to the point it was trying to navigate me to.  Other than this annoyance it performed flawlessly.

So, here is our route in the Indian River area.  I used OruxMaps to record the route.  I shared it with myself by uploading it to my Google Drive account as a GPX file.  Once in drive I downloaded it to my laptop, where I tried to re upload it to Google Maps with very poor success.  I played with this for several hours, trying to modify the GPX file and get Maps to load the whole thing, but it would only display about half of the entire track.

I finally came across GPSVisualizer.com, a cool site that will let you upload your gpx file and visualize it in a number of different ways.  One of the ways you can save the file is to a site called EveryTrail.com, which is kind of like a blog site for your trips.  Here is the link it generated for our trip in Indian River:


EveryTrail - Find hiking trails in California and beyond


Later I'll post about my Ram mount on the four wheeler and maybe some screenshots of OruxMaps in action.