-
Notifications
You must be signed in to change notification settings - Fork 0
Cardkingdom import #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
srhbutts
wants to merge
59
commits into
master
Choose a base branch
from
cardkingdom_import
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 6866557
cleaned up categories, started buylist parsing
srhbutts 1a607d2
start parse_retail function
srhbutts 6eaedf8
add next_page for pagination handling
srhbutts 0b7713d
fixed syntax error
srhbutts a7f5b01
added skeleton of category processing
srhbutts 9782c10
fixed missing end
srhbutts 5daf05b
started retail parsing function, will split to separate services later
srhbutts 1024327
Merge branch 'master' of https://github.com/difference-engineers/fars…
srhbutts 01b5d39
added pricing parsing
srhbutts db45f2b
added function to return an array of all relevant pages
srhbutts 7678950
next_page function no longer needed
srhbutts 2682f9c
added skeleton of function for update buylist/retail
srhbutts 6ddc2cb
added processing for separate foil pages
srhbutts 63b9677
corrected string pushed to every_page url
srhbutts 22e88c0
Merge branch 'master' of https://github.com/difference-engineers/fars…
srhbutts e053177
no need for a default/testing url
srhbutts 349c8fc
fixed redundant/unnecessary categories definition
srhbutts 3ac0e2c
fixing whitespace
srhbutts 2b9c668
started separate functionn for buylist vs retail url array
srhbutts ec02028
need the url to be customized based on our array of categories
srhbutts 7e444af
Merge branch 'master' of github.com:difference-engineers/farsight-fun…
krainboltgreene 3d0a699
These are now handled automatically
krainboltgreene 07bb15a
Updating from latest designs
krainboltgreene af063c6
Merge branch 'master' of https://github.com/difference-engineers/fars…
srhbutts 46f8396
Merge branch 'master' of https://github.com/difference-engineers/fars…
srhbutts 5a97cb1
Merge branch 'master' of https://github.com/difference-engineers/fars…
srhbutts 7690ba4
Merge branch 'cardkingdom_import' of https://github.com/difference-en…
srhbutts e9902e2
Let god sort them out
srhbutts a403c07
No longer needed
krainboltgreene 2551500
no longer needed puts output, will use logger if required
srhbutts 2d25633
don't need temp_url, was just there for testing
srhbutts 9570bb7
rewrote categories function to avoid syntax errors
srhbutts 7693b60
fixed missing end of block
srhbutts 06c436e
cleaning up whitespace
srhbutts 14afa93
fixed whitespace
srhbutts 25c71e0
ensure categories returns the sets array
srhbutts 280264f
fixed syntax error
srhbutts 391d11b
fixed syntax error
srhbutts d45e1a2
changed categories to return set_ids as that's all we actually need
srhbutts 5dd6e2c
changed categories to return set_ids as that's all we actually need
srhbutts 8d114ff
Merge branch 'cardkingdom_import' of https://github.com/difference-en…
srhbutts e2e2ea8
category_urls needed to replace a substring slice to make the array
srhbutts 0686ef5
no more need for sample url
srhbutts 09dca04
update_buylist now has a sample url it needed to start
srhbutts a993290
updated the retail function to use the new category_urls function
srhbutts 1341bb4
make sure we return the array
srhbutts ac87ed0
have to pass every_page a starter url
srhbutts 6807368
use the specific retail/buylist functions instead of "cards"
srhbutts 3126ee1
no need for set names now
srhbutts 55e4ac2
we only need set ids, not the old sets array
srhbutts dd1ba41
we'll use map since it's cleaner
srhbutts 0ec8d21
started using logger
srhbutts af5c8a2
find vendor isn't implemented yet
srhbutts c11e6ec
not yet ready for DB
srhbutts e0aafd4
monetize also not yet implemented
srhbutts 1530d69
added basic logging
srhbutts eef391c
switched another .each to .map to clean things up
srhbutts 5972b2e
Merge branch 'master' into cardkingdom_import
krainboltgreene File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| 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 |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| 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 . |
This file contains hidden or 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
| 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 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.