Class: Zoonar

Inherits:
GenericSite show all
Defined in:
lib/multistockphoto/site_zoonar.rb

Constant Summary collapse

SITENAME =
'zoonar'
@@errors =
0

Constants inherited from GenericSite

GenericSite::MAX_ERRORS, GenericSite::SENDLIST

Instance Attribute Summary collapse

Attributes inherited from GenericSite

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from GenericSite

#already_sent_site?, #heute_schon_gesendet, #photos_fuer_heute_uebrig?

Constructor Details

#initialize(name) ⇒ Zoonar

Returns a new instance of Zoonar.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/multistockphoto/site_zoonar.rb', line 13

def initialize(name)
  super
  if ENV['MSP_CONFIG']
    @config = YAML.load_file(ENV['MSP_CONFIG'])
  else
    @config = YAML.load_file("config.yaml")
  end
  @user = @config[:zoonar][:user]
  @password = @config[:zoonar][:password]
  @total_per_day = @config[:zoonar][:total_per_day]
end

Instance Attribute Details

#max_errorsObject

Returns the value of attribute max_errors.



11
12
13
# File 'lib/multistockphoto/site_zoonar.rb', line 11

def max_errors
  @max_errors
end

#passwordObject

Returns the value of attribute password.



11
12
13
# File 'lib/multistockphoto/site_zoonar.rb', line 11

def password
  @password
end

#total_per_dayObject (readonly)

Returns the value of attribute total_per_day.



10
11
12
# File 'lib/multistockphoto/site_zoonar.rb', line 10

def total_per_day
  @total_per_day
end

#userObject

Returns the value of attribute user.



11
12
13
# File 'lib/multistockphoto/site_zoonar.rb', line 11

def user
  @user
end

Class Method Details

.can_handle_orientation?Boolean

can site handle orientation?

Returns:

  • (Boolean)


133
134
135
# File 'lib/multistockphoto/site_zoonar.rb', line 133

def self.can_handle_orientation?
  false
end

Instance Method Details

#already_sent?(photo) ⇒ Boolean

wurde dieses Photo schon gesendet?

Returns:

  • (Boolean)


128
129
130
# File 'lib/multistockphoto/site_zoonar.rb', line 128

def already_sent?(photo)
  already_sent_site?(photo,SITENAME)
end

#sent_todayObject

Anzahl heute schon gesendeter Photos



122
123
124
125
# File 'lib/multistockphoto/site_zoonar.rb', line 122

def sent_today
  site = SITENAME
  return sent_today_site(site)
end

#transfer(photo, dont_send = false, dont_log = false) ⇒ Object

TODO: Bild gedreht senden, falls Hochformat



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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/multistockphoto/site_zoonar.rb', line 26

def transfer(photo,dont_send=false,dont_log=false)
  # falls nicht in config Datei eingetragen dann nicht senden
  if @user == nil or @password == nil
    return
  end
  
  unless photo.class == Photo
    raise 'not a Photo object'
  end
  unless File.exist?(photo.filename)
    raise "file #{photo.filename} does not exist"
  end
  print "#{SITENAME}:#{photo.filename} ... "
  $stdout.flush
  g = grep(SENDLIST, /#{SITENAME}\t#{photo.filename}/)
  if g.size > 0
    puts 'already sent'
    return :duplicate
  end
      if photo.portrait? and ! Zoonar.can_handle_orientation?
    photo.drehen
  end

  if site_can_handle_keywords?
    photo.set_keywords
  end

  unless dont_send
    agent = WWW::Mechanize.new
    agent.user_agent_alias = 'Linux Mozilla'
   begin
     page = agent.get 'http://www.zoonar.de'
   rescue WWW::Mechanize::ResponseCodeError
       raise UploadException
   end
    form = page.forms[1] #TODO: besser nach Name
    form['loginForm[Username]']  = @config[:zoonar][:user]
    form['loginForm[Password]']  = @config[:zoonar][:password] 

    page = agent.submit form
    raise "login error" if ! page.body.include?("Hallo, #{@config[:zoonar][:user]}!")
    page = agent.click page.links.text('Bilder hochladen')
    raise "nicht auf Upload-Seite" if ! page.body.include?('bertragen Sie Ihre Bilder einzeln mit Hilfe Ihres Internet-Browsers,')
    form = page.form('fUploadResource')
    if photo.portrait?
      form.file_uploads.first.file_name = photo.rotated_filename
    else
      form.file_uploads.first.file_name = photo.filename
    end
    # puts "form abgeschickt ..."
    page = agent.submit form
    if page.body.include?("Es ist ein Fehler aufgetreten")
      if page.body.include?("Das Bild ist zu klein.")
        raise "Bild zu klein. Muss mind. 6 MP sein"
      else
        @@errors += 1
        if @@errors > max_errors
          raise "too many errors"
        end
        raise UploadException, "Fehler beim Upload"
      end
    end
    @@errors = 0
    "Es ist ein Fehler aufgetreten!

Bei der Übertragung des Bildes ist ein Fehler aufgetreten.

Das Bild ist zu klein. Bitte übertragen Sie nur Bilder mit mehr als 6,0 MegaPixel.

Bitte versuchen Sie es erneut.
    "
  
    sonstiger_fehler = "<b>Es ist ein Fehler aufgetreten!</b><br/>\n   
<br/>\n    Bei der &Uuml;bertragung des Bildes ist ein Fehler aufgetreten.<br/>\
n    <br/>\n    Die Datei konnte nicht &uuml;bertragen werden.<br/>  "
    if page.body.include?("Vielen Dank!")
      puts "OK"
    end
    ok="Vielen Dank!

Das Bild wurde vollständig übertragen und wird nun von der Zoonar Bildredaktion geprüft.
Wenn das Bild angenommen wird, erscheint es umgehend im Zoonar Portal und ist über die Such-Funktion zu finden.
Falls wir das Bild ablehnen sollten, werden Sie eine Benachrichtigung per E-Mail erhalten.
    "
  else
    puts "OK"
  end # dont_send
  unless dont_log    
    File.open(SENDLIST,'a') {|f|
      f.puts "#{SITENAME}\t#{photo.filename}\t#{Time.now}"
    }
  end
  true
end