Class: Aldi

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

Constant Summary

Constants inherited from GenericSite

GenericSite::MAX_ERRORS, GenericSite::SENDLIST

Instance Attribute Summary

Attributes inherited from GenericSite

#max_errors, #name, #password, #user

Instance Method Summary collapse

Methods inherited from GenericSite

#already_sent_site?, #heute_schon_gesendet, #photos_fuer_heute_uebrig?, #photosize_valid?

Constructor Details

#initialize(name) ⇒ Aldi

Returns a new instance of Aldi.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/multistockphoto/site_aldi.rb', line 3

def initialize(name)
  p "creating an ALDI object"
  super
  if ENV['MSP_CONFIG']
    @config = YAML.load_file(ENV['MSP_CONFIG'])
    p "meine config: #{ENV['MSP_CONFIG']}"
  else
    p "standard config"
    @config = YAML.load_file("config.yaml")
  end
  @user = @config[:aldi][:user]
  @password = @config[:aldi][:password]
  # kann vom Client ueberschrieben werden
end

Instance Method Details

#html_out(body, html_file) ⇒ Object



79
80
81
# File 'lib/multistockphoto/site_aldi.rb', line 79

def html_out(body,html_file)
  File.open(html_file,"w") {|f| f.print body}
end

#transfer(photo) ⇒ Object



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
72
73
74
75
76
77
# File 'lib/multistockphoto/site_aldi.rb', line 18

def transfer(photo)
  # 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
  puts "zoonar:#{photo.filename}"
  g = `grep "zoonar\t#{photo.filename}" sendeliste.dat`
  if g.size > 0
    #puts "INFO: already sent to zoonar"
    return :duplicate
  end

  agent = WWW::Mechanize.new
  agent.user_agent_alias = 'Linux Mozilla'
  page = agent.get 'https://shop.aldi-fotoservice-druck.de/shop/viewLoginForm.do'
  
  if page.body.include?('Login/Neuanmeldung')
    p 'bin auf Login-Seite'
  end
  form = page.forms.first #TODO: besser nach Name
  form.username  = @config[:aldi][:user]
  form.password  = @config[:aldi][:password] 
  p form.username
  p form.password
  page = agent.submit form
  if page.body.include?('Ihre Benutzerdaten')
    p 'bin auf Benutzerdaten-Seite'
  else
    html_out(page.body,'out.html')
  end
  page = agent.click page.links.text('zum Direkt-Upload')
#    if page.body.include?('Ihr Warenkorb ist leer.')
#      p 'bin beim leeren Warenkorb'
#    end
# #   page = agent.get('https://shop.aldi-fotoservice-druck.de/shop/viewUploadForm.do')
#    page = agent.click page.links.text(/viewUploadForm/)
  if page.body.include?('Bilddateien und Zip-Archive einzeln hochladen')
    p 'bin auf Upload-Seite'
  end
  form = page.forms.first #TODO: besser nach Name
  pp form
  #form.file_1 = photo.filename
  pp form.file_uploads.name('file_1').first
  form.file_uploads.name('file_1').first.file_name = photo.filename
  pp form.file_uploads.name('file_1').first
  #pp form
  ##TODO: derzeit sind in diesem Formular bis zu 5 Photos gleichzeitig moeglich
  page = agent.submit form
  if page.body.include?('Ihr Auftrag')
    p "bin auf Auftrag-Anzeigeseite"
    html_out(page.body,'out.html')
  end
end