<< | Index | >>
Experiment
def update_item(product)
pointer = product.pointer + [:item]
@app.update(pointer.creator, {}, :migel)
end
Run
ch.oddb> search_migel_products('151002001','de')[0].pointer
-> :!migel_group,15!subgroup,10!product,02%.00%.1.
ch.oddb> ODDB::MiGeLPlugin.new(self).update_item(search_migel_products('151002001','de')[0])
-> undefined method `diff' for #<ODDB::Persistence::InvalidPathError:0x7f16647d9138>
Note
Experiment
def update_test1
group_pointer = Persistence::Pointer.new([:migel_group, '111'])
@app.update(group_pointer.creator, {}, :migel)
end
def update_test2
group_pointer = Persistence::Pointer.new([:masa, '222'])
@app.update(group_pointer.creator, {}, :migel)
end
Result
ch.oddb> migel_group('111').class
-> ODDB::Migel::Group
ch.oddb> ODDB::MiGeLPlugin.new(self).update_test2
-> undefined method `diff' for #<ODDB::Persistence::InvalidPathError:0x7fc60ec96bf8>
ch.oddb> migel_group('222').class
-> NilClass
Consideration
Experiment
include SimpleLanguage
attr_accessor :pharmacode
attr_reader :product
def initialize(product)
@product = product
end
end
end
attr_reader :code, :accessories, :products, :product_text, :items
def initialize(code)
...
@items = {}
end
def create_item(pharmacode)
@items ||= {}
item = ODDB::Migel::Item.new(self)
@items.store(pharmacode, item)
item
end
def item(pharmacode)
@items[pharmacode]
end
def update_test
product = @app.search_migel_products('151002011', 'de')[0]
pointer = product.pointer + [:item, '999']
update_values = {
:pharmacode => '1234'
}
@app.update(pointer.creator, update_values, :migel)
end
Result
ch.oddb> search_migel_products('151002011', 'de')[0].item('999').class
-> NilClass
ch.oddb> ODDB::MiGeLPlugin.new(self).update_test
->
ch.oddb> search_migel_products('151002011', 'de')[0].item('999').class
-> ODDB::Migel::Item
ch.oddb> search_migel_products('151002011', 'de')[0].item('999').pharmacode
-> 1234
Note
Next
Experiment
#!/usr/bin/env ruby
# ODDB::Migel::Item -- oddb.org -- 12.08.2011 -- mhatakeyama@ywesee.com
require 'util/language'
require 'model/text'
module ODDB
module Migel
class Item
include SimpleLanguage
attr_accessor :pharmacode, :article_name, :companyname, :ppha, :ppub, :factor
attr_reader :product
def initialize(product)
@product = product
end
end
end
end
def update_items_by_migel
#product = @app.migel_products[0]
product = @app.search_migel_products('151002011', 'de')[0]
migel_code = product.migel_code.split('.').to_s
plugin = ODDB::SwissindexNonpharmaPlugin.new(@app)
if table = plugin.search_migel_table(migel_code)
table.each do |record|
if pharmacode = record.shift
update_item(product, pharmacode, *record)
end
end
end
end
def update_item(product, pharmacode, *args)
#product = @app.search_migel_products('151002011', 'de')[0]
pointer = product.pointer + [:item, pharmacode]
article_name, companyname, ppha, ppub, factor = *args
update_values = {
:pharmacode => pharmacode,
:article_name => article_name,
:companyname => companyname,
:ppha => ppha,
:ppub => ppub,
:factor => factor,
}
@app.update(pointer.creator, update_values, :migel)
end
Run
ch.oddb> ODDB::MiGeLPlugin.new(self).update_items_by_migel
Result
ch.oddb> search_migel_products('151002011', 'de')[0].item('4340649').pharmacode
-> 4340649
ch.oddb> search_migel_products('151002011', 'de')[0].item('4340649').companyname
-> Manfred
ch.oddb> search_migel_products('151002011', 'de')[0].item('4340649').ppha
-> 100.95
ch.oddb> search_migel_products('151002011', 'de')[0].item('4340649').ppub
-> 134.25
ch.oddb> search_migel_products('151002011', 'de')[0].item('4340649').factor
-> 30
ch.oddb> search_migel_products('151002011', 'de')[0].items.keys.length
-> 323
Note (Important)
Question
suspend
Experiment
:th_ean_code => 'EAN-Code',
attr_reader :ean_code, :pharmacode, :article_name, :companyname, :ppha, :ppub, :factor
def initialize(record, container)
@ean_code, @pharmacode, @article_name, @companyname, @ppha, @ppub, @factor = *record
class SearchedList < HtmlGrid::List
CSS_CLASS = 'composite'
SUBHEADER = ODDB::View::Migel::SubHeader
def init
@components = {
[0,0] => :pharmacode,
[1,0] => :ean_code,
[2,0] => :article_name,
[3,0] => :companyname,
[4,0] => :ppha,
[5,0] => :ppub,
[6,0] => :factor,
}
@css_map = {
[0,0] => 'list',
[1,0] => 'list',
[2,0] => 'list bold',
[3,0] => 'list italic',
[4,0] => 'list',
[5,0] => 'list',
[6,0] => 'list',
}
super
end
Result

Note
canceled
Next
Experiemnt
:th_ean_code => 'EAN-Code',
:th_article_name => 'Artikelname',
:th_companyname => 'Companyname',
:th_ppha => 'PPHA',
:th_ppub => 'PPUB',
:th_factor => 'Faktor',
:th_status => 'Status',
class SearchedList < HtmlGrid::List
CSS_CLASS = 'composite'
SUBHEADER = ODDB::View::Migel::SubHeader
def init
@components = {
[0,0] => :pharmacode,
[1,0] => :ean_code,
[2,0] => :article_name,
[3,0] => :size,
[4,0] => :status,
[5,0] => :companyname,
[6,0] => :ppha,
[7,0] => :ppub,
[8,0] => :factor,
}
@css_map = {
[0,0] => 'list',
[1,0] => 'list',
[2,0] => 'list bold',
[3,0] => 'list italic',
[4,0] => 'list',
[5,0] => 'list',
[6,0] => 'list',
[7,0] => 'list',
[8,0] => 'list',
}
super
end
class SearchedTable
class Record
attr_reader :ean_code, :pharmacode, :article_name, :companyname, :ppha, :ppub, :factor, :size, :status
def initialize(record, container)
@ean_code = record[:ean_code]
@pharmacode = record[:pharmacode]
@article_name = record[:article_name]
@companyname = record[:companyname]
@ppha = record[:ppha]
@ppub = record[:ppub]
@factor = record[:factor]
@size = record[:size]
@status = record[:status]
@container = container
end
def search_migel_table(code, query_key = 'Pharmacode')
# 'MiGelCode' is also available for query_key
agent = Mechanize.new
try_time = 3
begin
agent.get(@base_url + query_key + '=' + code)
count = 100
table = []
line = []
migel = {}
agent.page.search('td').each_with_index do |td, i|
text = td.inner_text.chomp.strip
if text.is_a?(String) && text.length == 7 && text.match(/\d{7}/)
swissindex = {}
if pharmacode = line[0] and pharmacode.match(/\d{7}/) and item = search_item(pharmacode)
swissindex[:ean_code] = item[:gtin]
swissindex[:article_name] = item[:dscr]
swissindex[:size] = item[:addscr]
swissindex[:status] = item[:status]
if company = item[:comp]
swissindex[:companyname] = company[:name]
end
end
pharmacode, article_name, companyname, ppha, ppub, factor = *line
migel = {
:pharmacode => pharmacode,
:article_name => article_name,
:companyname => companyname,
:ppha => ppha,
:ppub => ppub,
:factor => factor,
}
migel.update swissindex
# line.unshift ean_code
# table << line
table << migel
line = []
swisindex = {}
count = 0
end
if count < 7
text = text.split(/\n/)[1] || text.split(/\n/)[0]
text = text.gsub(/\302\240/, '').strip if text
line << text
count += 1
end
end
# for the last line
swissindex = {}
if pharmacode = line[0] and pharmacode.match(/\d{7}/) and item = search_item(pharmacode)
swissindex[:ean_code] = item[:gtin]
swissindex[:article_name] = item[:dscr]
swissindex[:size] = item[:addscr]
swissindex[:status] = item[:status]
if company = item[:comp]
swissindex[:companyname] = company[:name]
end
end
pharmacode, article_name, companyname, ppha, ppub, factor = *line
migel = {
:pharmacode => pharmacode,
:article_name => article_name,
:companyname => companyname,
:ppha => ppha,
:ppub => ppub,
:factor => factor,
}
migel.update swissindex
table << migel
=begin
ean_code = nil
if pharmacode = line[0] and pharmacode.match(/\d{7}/)
ean_code = search_item(pharmacode)[:gtin]
end
line.unshift ean_code
table << line
=end
table.shift
table
rescue StandardError, Timeout::Error => err
if try_time > 0
puts err
puts err.backtrace
puts
puts "retry"
sleep 10
agent = Mechanize.new
try_time -= 1
retry
else
return []
end
end
end
Result

Note
Next
Experiment
#!/usr/bin/env ruby
# ODDB::Migel::Item -- oddb.org -- 12.08.2011 -- mhatakeyama@ywesee.com
require 'util/language'
require 'model/text'
module ODDB
module Migel
class Item
include SimpleLanguage
attr_accessor :ean_code, :pharmacode, :article_name, :companyname, :ppha, :ppub, :factor, :size, :status
attr_reader :product
def initialize(product)
@product = product
end
end
end
end
~
def update_items_by_migel
#product = @app.migel_products[0]
product = @app.search_migel_products('342101021', 'de')[0]
migel_code = product.migel_code.split('.').to_s
plugin = ODDB::SwissindexNonpharmaPlugin.new(@app)
if table = plugin.search_migel_table(migel_code)
table.each do |record|
if record[:pharmacode]
update_item(product, record)
end
# if pharmacode = record.shift
# update_item(product, pharmacode, *record)
# end
end
end
end
#def update_item(product, pharmacode, *args)
def update_item(product, record)
#product = @app.search_migel_products('151002011', 'de')[0]
pointer = product.pointer + [:item, record[:pharmacode]]
# article_name, companyname, ppha, ppub, factor = *args
update_values = {
:pharmacode => record[:pharmacode],
:ean_code => record[:ean_code],
:article_name => record[:article_name],
:companyname => record[:companyname],
:ppha => record[:ppha],
:ppub => record[:ppub],
:factor => record[:factor],
:size => record[:size],
:status => record[:status],
}
@app.update(pointer.creator, update_values, :migel)
end
Result
ch.oddb> ODDB::MiGeLPlugin.new(self).update_items_by_migel
-> Array
ch.oddb> search_migel_products('342101021', 'de')[0].items.length
-> 7
ch.oddb> search_migel_products('342101021', 'de')[0].items('1740101')
-> (eval):1:in `items': wrong number of arguments (1 for 0)
ch.oddb> search_migel_products('342101021', 'de')[0].item('1740101')
->
ch.oddb> search_migel_products('342101021', 'de')[0].item('1740101').class
-> ODDB::Migel::Item
ch.oddb> search_migel_products('342101021', 'de')[0].item('1740101').status
-> A
ch.oddb> search_migel_products('342101021', 'de')[0].item('1740101').size
-> 10 Stk
ch.oddb> search_migel_products('342101021', 'de')[0].item('1740101').article_name
-> RHENA IDEAL Elastische Binde écru 5mx6cm
Next