Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
1dc3d77
added bootstrapped cardkingdom function and categories function
srhbutts May 31, 2019
6866557
cleaned up categories, started buylist parsing
srhbutts May 31, 2019
1a607d2
start parse_retail function
srhbutts May 31, 2019
6eaedf8
add next_page for pagination handling
srhbutts May 31, 2019
0b7713d
fixed syntax error
srhbutts May 31, 2019
a7f5b01
added skeleton of category processing
srhbutts May 31, 2019
9782c10
fixed missing end
srhbutts Jun 1, 2019
5daf05b
started retail parsing function, will split to separate services later
srhbutts Jun 1, 2019
1024327
Merge branch 'master' of https://github.com/difference-engineers/fars…
srhbutts Jun 30, 2019
01b5d39
added pricing parsing
srhbutts Jul 5, 2019
db45f2b
added function to return an array of all relevant pages
srhbutts Jul 5, 2019
7678950
next_page function no longer needed
srhbutts Jul 5, 2019
2682f9c
added skeleton of function for update buylist/retail
srhbutts Jul 5, 2019
6ddc2cb
added processing for separate foil pages
srhbutts Jul 7, 2019
63b9677
corrected string pushed to every_page url
srhbutts Jul 7, 2019
22e88c0
Merge branch 'master' of https://github.com/difference-engineers/fars…
srhbutts Jul 8, 2019
e053177
no need for a default/testing url
srhbutts Jul 12, 2019
349c8fc
fixed redundant/unnecessary categories definition
srhbutts Jul 12, 2019
3ac0e2c
fixing whitespace
srhbutts Jul 12, 2019
2b9c668
started separate functionn for buylist vs retail url array
srhbutts Jul 15, 2019
ec02028
need the url to be customized based on our array of categories
srhbutts Jul 15, 2019
7e444af
Merge branch 'master' of github.com:difference-engineers/farsight-fun…
krainboltgreene Jul 15, 2019
3d0a699
These are now handled automatically
krainboltgreene Jul 15, 2019
07bb15a
Updating from latest designs
krainboltgreene Jul 15, 2019
af063c6
Merge branch 'master' of https://github.com/difference-engineers/fars…
srhbutts Jul 17, 2019
46f8396
Merge branch 'master' of https://github.com/difference-engineers/fars…
srhbutts Jul 17, 2019
5a97cb1
Merge branch 'master' of https://github.com/difference-engineers/fars…
srhbutts Jul 17, 2019
7690ba4
Merge branch 'cardkingdom_import' of https://github.com/difference-en…
srhbutts Jul 17, 2019
e9902e2
Let god sort them out
srhbutts Jul 15, 2019
a403c07
No longer needed
krainboltgreene Jul 17, 2019
2551500
no longer needed puts output, will use logger if required
srhbutts Jul 18, 2019
2d25633
don't need temp_url, was just there for testing
srhbutts Jul 18, 2019
9570bb7
rewrote categories function to avoid syntax errors
srhbutts Jul 18, 2019
7693b60
fixed missing end of block
srhbutts Jul 18, 2019
06c436e
cleaning up whitespace
srhbutts Jul 18, 2019
14afa93
fixed whitespace
srhbutts Jul 24, 2019
25c71e0
ensure categories returns the sets array
srhbutts Jul 24, 2019
280264f
fixed syntax error
srhbutts Jul 27, 2019
391d11b
fixed syntax error
srhbutts Jul 27, 2019
d45e1a2
changed categories to return set_ids as that's all we actually need
srhbutts Jul 27, 2019
5dd6e2c
changed categories to return set_ids as that's all we actually need
srhbutts Jul 27, 2019
8d114ff
Merge branch 'cardkingdom_import' of https://github.com/difference-en…
srhbutts Jul 27, 2019
e2e2ea8
category_urls needed to replace a substring slice to make the array
srhbutts Jul 28, 2019
0686ef5
no more need for sample url
srhbutts Jul 28, 2019
09dca04
update_buylist now has a sample url it needed to start
srhbutts Jul 28, 2019
a993290
updated the retail function to use the new category_urls function
srhbutts Jul 28, 2019
1341bb4
make sure we return the array
srhbutts Jul 28, 2019
ac87ed0
have to pass every_page a starter url
srhbutts Jul 28, 2019
6807368
use the specific retail/buylist functions instead of "cards"
srhbutts Jul 28, 2019
3126ee1
no need for set names now
srhbutts Jul 28, 2019
55e4ac2
we only need set ids, not the old sets array
srhbutts Jul 28, 2019
dd1ba41
we'll use map since it's cleaner
srhbutts Jul 28, 2019
0ec8d21
started using logger
srhbutts Jul 28, 2019
af5c8a2
find vendor isn't implemented yet
srhbutts Jul 28, 2019
c11e6ec
not yet ready for DB
srhbutts Jul 28, 2019
e0aafd4
monetize also not yet implemented
srhbutts Jul 28, 2019
1530d69
added basic logging
srhbutts Jul 28, 2019
eef391c
switched another .each to .map to clean things up
srhbutts Jul 28, 2019
5972b2e
Merge branch 'master' into cardkingdom_import
krainboltgreene Aug 12, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion SERVICES
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mtgjson-import-cards
mtgjson-import-sets
mtgjson-import-keywords
mtgjson-import-keywords
cardkingdom-import
4 changes: 4 additions & 0 deletions _base/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ group(:development) do
gem("pry-loudmouth", "~> 0.1.0")
gem("pry-auto_benching.rb", "~> 3.2")
end

gem("nokogiri", "~> 1.10", :group => :"cardkingdom-import")

gem("monetize", "~> 1.9")
13 changes: 12 additions & 1 deletion _base/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ GEM
grpc (1.20.0)
google-protobuf (~> 3.7)
googleapis-common-protos-types (~> 1.0.0)
i18n (1.6.0)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
interception (0.5)
jaro_winkler (1.5.3)
Expand All @@ -125,9 +127,16 @@ GEM
mapping (1.1.1)
memoist (0.16.0)
method_source (0.9.2)
mini_portile2 (2.4.0)
monetize (1.9.2)
money (~> 6.12)
money (6.13.4)
i18n (>= 0.6.4, <= 2)
multi_json (1.13.1)
multipart-post (2.1.1)
nio4r (2.3.1)
nokogiri (1.10.3)
mini_portile2 (~> 2.4.0)
os (1.0.1)
parallel (1.17.0)
parser (2.6.3.0)
Expand Down Expand Up @@ -249,6 +258,8 @@ PLATFORMS
DEPENDENCIES
async-http (~> 0.40.3)
falcon (~> 0.30.0)
monetize (~> 1.9)
nokogiri (~> 1.10)
pg (~> 1.1)
pry (~> 0.12.2)
pry-auto_benching.rb (~> 3.2)
Expand Down Expand Up @@ -276,4 +287,4 @@ RUBY VERSION
ruby 2.6.3p62

BUNDLED WITH
1.17.2
1.17.3
7 changes: 7 additions & 0 deletions cardkingdom-import/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM us.gcr.io/farsight-239605/base:latest

ENV SERVICE "cardkingdom-import"

WORKDIR /home/root/application/

COPY function.rb .
124 changes: 124 additions & 0 deletions cardkingdom-import/function.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
def function(response:, router:, database:)
response.status = :ok
end

def update_buylist
base_url = "https://cardkingdom.com/purchasing/mtg_singles?filter%5Bsort%5D=n"\
"ame&filter%5Bsearch%5D=mtg_advanced&filter%5Bname%5D=&filter%5Bcategory_id%5D"\
"=2864&filter%5Bfoil%5D=1&filter%5Bnonfoil%5D=1&filter%5Bprice_op%5D=&filter%5"\
"Bprice%5D="

LOGGER.info("Starting update of buylist cardkingdom prices..")

category_urls(base_url).each do |category_url|
LOGGER.info(".. Processing #{category_url}.")
every_page(category_url).each do |page|
LOGGER.info(".... Processing page #{page}.")
parse_buylist(page)
end
end
end

def update_retail
base_url = "https://www.cardkingdom.com/mtg/5th-edition?filter%5Bipp%5D=60&fi\
lter%5Bsort%5D=name"

LOGGER.info("Starting update of retail cardkingdom prices.")

category_urls(base_url).each do |category_url|
LOGGER.info(".. Processing #{category_url}.")
every_page(category_url).each do |page|
LOGGER.info(".... Processing page #{page}.")
parse_retail(page)
end
end
end

def set_ids()
url = "https://cardkingdom.com/search/mtg"

raw = Nokogiri::HTML(Net::HTTP.get(URI(url)))

discard = ["All Editions", "Standard", "Modern"]
raw.css("div#editionContainer").css("option").map do |set|
(Integer(set["value"], 10)) unless discard.include?(set.children.text)
end.compact

end

def category_urls(base_url)
set_ids().map do |set_id|
base_url.gsub(/category_id%5D=([0-9]+)/i, "category_id%5D=#{set_id}")
end
end

def parse_buylist(url)
#vendor = find(:vendors, :slug => "cardkingdom")

raw = Nokogiri::HTML(Net::HTTP.get(URI(url)))
raw.css("div.itemContentWrapper").each do |card|
cardname = card.css("span.productDetailTitle").inner_text
raw_set = card.css("div.productDetailSet").css("a").inner_text.strip
cash_dollars = card.css(".usdSellPrice").css("span.sellDollarAmount").inner_text
cash_cents = card.css(".usdSellPrice").css("span.sellCentsAmount").inner_text
parsed_set = raw_set.split(/\((C|U|R|M|P|S)\)/)
set = parsed_set[0]
foil = parsed_set[2]
foil.nil? ? foil = "0" : foil = "1"
cash = cash_dollars + "." + cash_cents
#sell = monetize.parse(cash)

#card = find(table, {})
#insert(:card_sell_prices, card, :sell_cents => sell.cents, :sell_currency => sell.currency, :reported_condition => reported_condition, :vendor => vendor)
end
end


def parse_retail(url)

raw = Nokogiri::HTML(Net::HTTP.get(URI(url)))
raw.css("div.itemContentWrapper").each do |card|
# add handling for unusual cards: prerelease promos, con promos, buy a box, etc
cardname = card.css("span.productDetailTitle").text
raw_set = card.css("div.productDetailSet").text.strip
parsed_set = raw_set.split(/\((C|U|R|M|P|S)\)/)
set = parsed_set[0]

nm_inventory = card.css("ul.addToCartByType").css("li.NM").css("div.amtAndPrice").css("span.styleQty").inner_text
nm_price = card.css("ul.addToCartByType").css("li.NM").css("div.amtAndPrice").css("span.stylePrice").inner_text.strip

ex_inventory = card.css("ul.addToCartByType").css("li.EX").css("div.amtAndPrice").css("span.styleQty").inner_text
ex_price = card.css("ul.addToCartByType").css("li.EX").css("div.amtAndPrice").css("span.stylePrice").inner_text.strip

vg_inventory = card.css("ul.addToCartByType").css("li.VG").css("div.amtAndPrice").css("span.styleQty").inner_text.strip
vg_price = card.css("ul.addToCartByType").css("li.VG").css("div.amtAndPrice").css("span.stylePrice").inner_text.strip

g_inventory = card.css("ul.addToCartByType").css("li.G").css("div.amtAndPrice").css("span.styleQty").inner_text.strip
g_price = card.css("ul.addToCartByType").css("li.G").css("div.amtAndPrice").css("span.stylePrice").inner_text.strip
end
end

def every_page(url)
every_page = []

raw = Nokogiri::HTML(Net::HTTP.get(URI(url)))

count = raw.css("ul.pagination").css("li").count
pages = Integer(raw.css("ul.pagination").css("li")[count - 2].children.text.strip, 10)

(1..pages).each do |page|
every_page.push(url + "&page=#{page}")
end
separate_foil_pages = true unless url.include?("/purchasing/")
foil_url = url.sub(%r(/singles), "/foils") if separate_foil_pages

foil_raw = Nokogiri::HTML(Net::HTTP.get(URI(url)))

foil_count = raw.css("ul.pagination").css("li").count
foil_pages = Integer(raw.css("ul.pagination").css("li")[count - 2].children.text.strip, 10)

(1..foil_pages).each do |page|
every_page.push(url + "&page=#{page}")
end
every_page
end