Class: Photocase
- Inherits:
-
GenericSite
- Object
- GenericSite
- Photocase
- Defined in:
- lib/multistockphoto/site_photocase.rb
Constant Summary collapse
- SITENAME =
'photocase'
- @@errors =
0
Constants inherited from GenericSite
GenericSite::MAX_ERRORS, GenericSite::SENDLIST
Instance Attribute Summary collapse
-
#max_errors ⇒ Object
Returns the value of attribute max_errors.
-
#password ⇒ Object
Returns the value of attribute password.
-
#total_per_day ⇒ Object
readonly
Returns the value of attribute total_per_day.
-
#user ⇒ Object
Returns the value of attribute user.
Attributes inherited from GenericSite
Class Method Summary collapse
-
.accept?(ext) ⇒ Boolean
Site akzeptiert diese Extension.
-
.can_handle_orientation? ⇒ Boolean
can site handle orientation?.
Instance Method Summary collapse
- #accept?(ext) ⇒ Boolean
-
#already_sent?(photo) ⇒ Boolean
wurde dieses Photo schon gesendet?.
-
#initialize(name) ⇒ Photocase
constructor
A new instance of Photocase.
-
#sent_today ⇒ Object
Anzahl heute schon gesendeter Photos.
- #transfer(photo, dont_send = false, dont_log = false) ⇒ Object
Methods inherited from GenericSite
#already_sent_site?, #heute_schon_gesendet, #photos_fuer_heute_uebrig?
Constructor Details
#initialize(name) ⇒ Photocase
Returns a new instance of Photocase.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/multistockphoto/site_photocase.rb', line 11 def initialize(name) super # if ENV['MSP_CONFIG'] # @config = YAML.load_file(ENV['MSP_CONFIG']) # else # @config = YAML.load_file("config.yaml") # end @config = load_config begin @user = @config[:photocase][:user] @password = @config[:photocase][:password] @total_per_day = @config[:photocase][:total_per_day] rescue puts 'cannot read configuration entries of '+SITENAME end end |
Instance Attribute Details
#max_errors ⇒ Object
Returns the value of attribute max_errors.
9 10 11 |
# File 'lib/multistockphoto/site_photocase.rb', line 9 def max_errors @max_errors end |
#password ⇒ Object
Returns the value of attribute password.
9 10 11 |
# File 'lib/multistockphoto/site_photocase.rb', line 9 def password @password end |
#total_per_day ⇒ Object (readonly)
Returns the value of attribute total_per_day.
8 9 10 |
# File 'lib/multistockphoto/site_photocase.rb', line 8 def total_per_day @total_per_day end |
#user ⇒ Object
Returns the value of attribute user.
9 10 11 |
# File 'lib/multistockphoto/site_photocase.rb', line 9 def user @user end |
Class Method Details
.accept?(ext) ⇒ Boolean
Site akzeptiert diese Extension
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/multistockphoto/site_photocase.rb', line 149 def self.accept?(ext) ext = ext.downcase if ext[0,1] == '.' ext = ext[1..-1] end case ext when 'jpg','jpeg' #TODO: pruefen return true else return false end end |
.can_handle_orientation? ⇒ Boolean
can site handle orientation?
144 145 146 |
# File 'lib/multistockphoto/site_photocase.rb', line 144 def self.can_handle_orientation? false end |
Instance Method Details
#accept?(ext) ⇒ Boolean
162 163 164 |
# File 'lib/multistockphoto/site_photocase.rb', line 162 def accept?(ext) Photocase.accept?(ext) end |
#already_sent?(photo) ⇒ Boolean
wurde dieses Photo schon gesendet?
130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/multistockphoto/site_photocase.rb', line 130 def already_sent?(photo) already_sent_site?(photo,SITENAME) # # unless photo.class == Photo # raise 'not a Photo object' # end # unless File.exist?(photo.filename) # raise "file #{photo.filename} does not exist" # end # g = grep(SENDLIST, /photocase\t#{photo.filename}/) # return g.size > 0 end |
#sent_today ⇒ Object
Anzahl heute schon gesendeter Photos
124 125 126 127 |
# File 'lib/multistockphoto/site_photocase.rb', line 124 def sent_today site = SITENAME return sent_today_site(site) end |
#transfer(photo, dont_send = false, dont_log = false) ⇒ Object
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 120 121 |
# File 'lib/multistockphoto/site_photocase.rb', line 28 def transfer(photo,dont_send=false,dont_log=false) sav_photo_filename = photo.filename.dup # 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 if already_sent_site?(photo,SITENAME) puts 'already sent' return :duplicate end if photo.portrait? and ! Photocase.can_handle_orientation? photo.drehen end if site_can_handle_keywords? photo.set_keywords end if ! dont_send begin agent = WWW::Mechanize.new agent.user_agent_alias = 'Linux Mozilla' page = agent.get 'http://www.photocase.de/en/login.asp' if !page.body.include?('Log in') raise 'not at the login page' end form = page.forms.first #TODO: besser nach Name # form['loginForm[Username]'] = @config[:zoonar][:user] # form['loginForm[Password]'] = @config[:zoonar][:password] form['UserName'] = @config[:photocase][:user] form['UserPassword'] = @config[:photocase][:password] #UserName #UserPassword page = agent.submit form raise "login error" if ! page.body.include?("Login successful") page = agent.click page.links.text('Upload') raise "no Upload a photo" if ! page.body.include?('Upload a photo') form = page.form('Form') if photo.portrait? form.file_uploads.first.file_name = photo.rotated_filename # b = File.basename(photo.filename) # newfilename = photo.filename.sub(b,'')+'rot_'+b # # form.file_uploads.first.file_name = 'r' + photo.filename # form.file_uploads.first.file_name = newfilename else form.file_uploads.first.file_name = photo.filename end #TODO: # 2 Checkboxen #UploadDisclaimerAccepted #HasCopyright form.checkboxes.name('UploadDisclaimerAccepted').check form.checkboxes.name('HasCopyright').check page = agent.submit form if !page.body.include?('Your photo was uploaded successfully.') raise "not successfully uploaded" end if page.body.include?('Your photo was uploaded successfully.') @@errors = 0 puts "OK" else #Fehler aufgetreten @@errors += 1 if @@errors > 3 raise "too many errors" end end rescue Net::HTTPInternalServerError, WWW::Mechanize::ResponseCodeError # Net::HTTPInternalServerError (WWW::Mechanize::ResponseCodeError) raise UploadException end # rescue else puts "OK" end #'Your photo was uploaded successfully.' if sav_photo_filename != photo.filename raise "photo.filenames has been changed!" end unless dont_log File.open(SENDLIST,'a') {|f| f.puts "#{SITENAME}\t#{photo.filename}\t#{Time.now}" } end true end |