public
Description: Silly stickers you can make from your flickr images.
Homepage:
Clone URL: git://github.com/infovore/stickrs.git
stickrs / dadaist-photos.rb
100644 71 lines (61 sloc) 2.059 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
67
68
69
70
71
require 'rubygems'
require 'yaml'
require 'net/sftp'
require 'htmlentities'
require 'moo'
require 'lib/core_ext/slugify'
require 'lib/flickr_image_processor'
 
CONFIG = YAML.load_file("config.yml")
 
if ARGV[0]
  email = ARGV[0]
  if ARGV[1]
    limit = ARGV[1].to_i
  else
    limit = 90
  end
 
  dadaist_processor = DadaistStickers.new(email, limit, CONFIG["flickr_api_key"])
  
  processed_images = dadaist_processor.process_each_image
  public_image_urls = []
 
  # write those images to our SFTP server.
  Net::SFTP.start(CONFIG["ftp"]["host"],
                  CONFIG["ftp"]["username"],
                  :password => CONFIG["ftp"]["password"]) do |sftp|
    processed_images.each do |title_and_image|
      filename = "dadaist-#{title_and_image[:title].slugify}.jpg"
      sftp.file.open("#{CONFIG["ftp"]["full_upload_path"]}#{filename}", "w") do |f|
        f.write(title_and_image[:image].to_blob {|i| i.format = "JPG"})
        public_image_urls << "#{CONFIG["ftp"]["public_url_root"]}#{filename}"
      end
    end
  end
  
  if ARGV[2].eql?("purchase")
    puts "Creating an order for these items from MOO.com..."
    order = Moo::Order.new(:api_key => CONFIG["moo_api_key"])
    public_image_urls.each do |url|
      sticker = Moo::Sticker.new(:url => url)
      order.designs << sticker
    end
    
    order.submit
    if order.error?
      puts "There was a problem with your order:"
      puts order.error_string
    else
      puts "Your order was successfully created. Now visit the website for payment:"
      coder = HTMLEntities.new
      puts coder.decode(order.start_url)
    end
  elsif ARGV[2].eql?("preview")
    puts "Previewing your Moo API XML"
    order = Moo::Order.new(:api_key => CONFIG["moo_api_key"])
    public_image_urls.each do |url|
      sticker = Moo::Sticker.new(:url => url)
      order.designs << sticker
    end
    
    puts order.to_xml
  else
    puts "Your files are available on the web:"
    public_image_urls.each {|url| puts url}
  end
 
else
  puts "Usage: dadaist-photos.rb flickr_user_string limit"
end