Created
January 23, 2013 08:07
-
-
Save jamespenguin/4603005 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
amiami.rb -- | |
class AmiAmi < FigureWatch::Adapter | |
def item_data(item_url) | |
# Initialize item object | |
item = FigureWatch::Item.new | |
item.seller = "AmiAmi" | |
item.item_url = item_url | |
# Get item page | |
page = FigureWatch.get_doc item_url | |
# Get item name | |
item_name = page.at('title').text | |
item_name = item_name.split("AmiAmi [Character & Hobby Shop] | ")[-1] | |
item.name = item_name.strip | |
### | |
# Process right menu | |
### | |
right_menu = page.at('div[@id="right_menu"]') | |
# Figure out if it is sold out | |
img_tag = right_menu.at('img') | |
status = img_tag[:alt] | |
if status == "SOLD OUT" | |
item.in_stock = false | |
else | |
item.in_stock = true | |
end | |
# Get price and discount percentage | |
price_item = right_menu.at('ul/li[2]') | |
price_string = price_item.text | |
if price_string.include? "%OFF" | |
item.price = price_string.split("OFF")[-1] | |
item.discount_percentage = price_string.split("OFF")[0] | |
end | |
# Figure out if item is a preorder item | |
if right_menu.at('ul').text.include? 'Preorder' | |
item.pre_order = true | |
else | |
item.pre_order = false | |
end | |
### | |
# Process spec data | |
### | |
spec_data = right_menu.at('dl[@class="spec_data"]') | |
# purchase quantity limit | |
limit_tag = spec_data.at('dt[text()*="Purchase Limit"]') | |
quantity = limit_tag.next_element.text | |
quantity = quantity.split('Max ')[-1].to_i | |
item.purchase_limit = quantity | |
# item maker | |
maker_tag = spec_data.at('dt[text()*="Maker"]') | |
item.maker = maker_tag.next_element.text.strip | |
# release date | |
date_tag = spec_data.at('dt[text()*="Release Date"]') | |
item.release_date = date_tag.next_element.text.strip | |
# series | |
series_tag = spec_data.at('dt[text()*="Series Title"]') | |
item.series = series_tag.next_element.text.strip | |
# character name | |
character_tag = spec_data.at('dt[text()*="Character Name"]') | |
item.character_name = character_tag.next_element.text.strip | |
# sculptor | |
sculptor_tag = spec_data.at('dt[text()*="Sculptor"]') | |
item.sculptor = sculptor_tag.next_element.text.strip | |
### | |
# Get product image URLs | |
### | |
# main product image | |
main_image_tag = page.at('p[@class="product_img_area"]/img') | |
item.image_urls << main_image_tag[:src] | |
# other product images | |
image_area = page.at('div[@class="product_img_area"][1]') | |
image_area.search('a').each do | link_tag | | |
item.image_urls << link_tag[:href] | |
end | |
### | |
# Get product specifications and details | |
### | |
# Specifications | |
specs_tag = page.at('p[text()*="Specifications"]') | |
item.specifications = specs_tag.next_element.text.strip | |
# Details | |
details_tag = page.at('p[text()*="Details"]') | |
item.details = details_tag.next_element.text.strip | |
return item | |
end | |
end | |
generate.rb -- | |
# Ritsu amiami | |
url = "http://www.amiami.com/top/detail/detail?scode=FIG-MOE-2038" | |
ap FigureWatch::ADAPTERS['AmiAmi'].item_data(url).attributes | |
brandon@bebop2 /srv/api/figure_watch $ ./generate --foo { | |
:seller => "AmiAmi", | |
:item_url => "http://www.amiami.com/top/detail/detail?scode=FIG-MOE-2038", | |
:name => "K-On! - Ritsu Tainaka 1/7 Complete Figure", | |
:price => "5,180 JPY", | |
:discount_percentage => "20%", | |
:in_stock => false, | |
:back_order => false, | |
:pre_order => false, | |
:used_item => false, | |
:purchase_limit => 1, | |
:maker => "Max Factory", | |
:release_date => "late Dec-2010", | |
:series => "K-On!", | |
:character_name => "Ritsu Tainaka", | |
:sculptor => "Nakayaman", | |
:image_urls => [ | |
[0] "http://img.amiami.jp/images/product/main/103//FIG-MOE-2038.jpg", | |
[1] "http://img.amiami.jp/images/product/review/103//FIG-MOE-2038_01.jpg", | |
[2] "http://img.amiami.jp/images/product/review/103//FIG-MOE-2038_02.jpg", | |
[3] "http://img.amiami.jp/images/product/review/103//FIG-MOE-2038_03.jpg", | |
[4] "http://img.amiami.jp/images/product/review/103//FIG-MOE-2038_04.jpg", | |
[5] "http://img.amiami.jp/images/product/review/103//FIG-MOE-2038_05.jpg" | |
], | |
:specifications => "PVC Pre-painted Complete FigureSize: appx. 210mm Tall (1/7 Scale)[Set Contents]-Main figure-Base", | |
:details => "From the popular anime and manga series \"K-ON!\" comes a 1/7th PVC figure of the president of the K-ON music club, as well as the club's drummer - Ritsu Tainaka. She is wearing a jersey over her school uniform, just as she appeared in the show. She is posed with her school bag slung over her shoulder - a pose that really brings Ritsu's rough and lively personality out!You can see her drumsticks sticking out of the bag slung over her shoulders, plus there is even a little mascot character hanging off the bag! Whilst it might not be on the stage, it's still a great scene out of Ritsu's everyday life!" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment