Class: PwUp::PwUp

Inherits:
Object
  • Object
show all
Defined in:
lib/pwup.rb

Constant Summary collapse

COMMANDS =

FILE_TYPES = %w[.rar .zip]

{
  ".rar" => "unrar x -ep \"%<file>s\" %<target_dir>s",
  ".zip" => "unzip -j \"%<file>s\" -d %<target_dir>s",
}
IMAGE_TYPES =
%w[*.jpg *.png *.gif]

Instance Method Summary collapse

Constructor Details

#initialize(email, password) ⇒ PwUp

Returns a new instance of PwUp.



16
17
18
19
20
21
# File 'lib/pwup.rb', line 16

def initialize(email, password)
  @email = email
  @password = password
  @picasa = Picasa::Picasa.new
  p @picasa.(email, password)
end

Instance Method Details

#process!(files, album_name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/pwup.rb', line 23

def process!(files, album_name)
  # create a tmp folder
  target_dir = Dir.mktmpdir('pwup', '/tmp')
  # these are the compressed ones or directories
  unless files.respond_to? :each
    files = [files]
  end
  files.each do |file|
    unless process? file
      puts "Skipping, can't process file #{file}"
      next
    end
    # unpack file there
    puts "Unpacking #{file}"
    unpack file, target_dir
  end
  # filter only the images
  p1 = Pathname.new target_dir
  images = Dir.glob(IMAGE_TYPES.map {|i| p1 + "**" + i} ,File::FNM_CASEFOLD)
  puts "Found #{images.length} images"
  # exit if no images where found
  return if images.length == 0
  puts "Uploading to #{album_name}"
  # create album
  album = @picasa.create_album(
    title: album_name,
    summary: album_name,
    location: "",
    keywords: "",
    )
  puts "album name = #{album.name}"
  images.each_with_index do |image, index|
    file_name = image
    image_data = open(file_name, "rb").read
    @picasa.post_photo(
      image_data,
      album: album.name,
      summary: file_name,
      title: file_name
      )
    puts "photo #{file_name} uploaded to #{album.name} - #{index+1} of #{images.length}"
  end
  return album
end