Last active
March 9, 2017 16:04
-
-
Save pkulak/a20196f68f7c88f1d7e0 to your computer and use it in GitHub Desktop.
A simple script to get the files off your Olympus camera.
This file contains 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
#!/usr/bin/env ruby | |
require 'open-uri' | |
require 'time' | |
require 'json' | |
class Runner | |
def initialize | |
@base = "http://192.168.0.10/DCIM/100OLYMP" | |
# Replace this with wherever you'd like your photos to live. | |
@home = File.join(Dir.home, "/Google Drive/Photo Sync/Negatives/#{DateTime.now.year}/#{DateTime.now.strftime("%m")}") | |
@config = File.join(Dir.home, "/.imported_photos") | |
unless Dir.exist?(@home) | |
Dir.mkdir(@home) | |
end | |
if File.exist?(@config) | |
@seen = JSON.parse(IO.read(@config)) | |
else | |
@seen = [] | |
end | |
end | |
def run | |
page = open(@base).read | |
last_ext = "" | |
page.split("\n").each do |line| | |
next unless line.start_with?("wlansd[") | |
file = line[11...-3].split(",")[1] | |
if @seen.include?(file) | |
puts "skipping file #{file}" | |
next | |
end | |
`curl #{@base}/#{file} > "#{@home}/#{file}"` | |
@seen << file | |
end | |
File.open(@config, 'w') {|file| file.write(@seen.to_json)} | |
end | |
end | |
Runner.new.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment