cockatrice_feeder 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cockatrice_feeder.rb +139 -1
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e43bbd10275d5150dd9d3e45c8d5b01df882c65
4
- data.tar.gz: 18d5eae374e7e1ebe294f46fcdb7fcf3fa0c697f
3
+ metadata.gz: 35f49ec43fbddcb43336894609d1f110ed83b9c4
4
+ data.tar.gz: d43a4dc9a50c9f8e8c0dd0e8df2a1d08721ebe4d
5
5
  SHA512:
6
- metadata.gz: 0d7f63f8025a330e9a62b6179cece671f0d7a91b0539fe9fa971ee3ef4e2bfee4dc4b3be0667800ce999662667825abc958d7fc5bc3165f6adf68f337f29b006
7
- data.tar.gz: d7463259b547c30638eae233ea0174a31d7d79a64b9054ee05a50298248501399a11518f7330fa247d7df07e8c4be9f4812f986cf383af1ec355a73b6224702d
6
+ metadata.gz: 6f185893e9afa3c3cbed1c9217a55d58d7d456d6887c0078dac5b0d37f0c8ab54d5720983ce7e813ff95f2785c2caabf6e4b766f7cd90c6148213fbf230dd34d
7
+ data.tar.gz: 35bf4d00a14d7b2b7806d84ab8230915082da0f298dced2c0bd4acc3b4eef818b763292fa5b05305f9c04e5a055ca6b2a56badb051830f2c9cc5a752f2ad3c7c
@@ -145,6 +145,15 @@ module CockatriceFeeder
145
145
  tiers
146
146
  end
147
147
 
148
+ def self.update_full_data
149
+ File.open(@@meta_dir+"AllPrintings.json", "w") do |file|
150
+ file.binmode
151
+ HTTParty.get("https://mtgjson.com/api/v5/AllPrintings.json", stream_body: true) do |fragment|
152
+ file.write(fragment)
153
+ end
154
+ end
155
+ end
156
+
148
157
  def self.commanders
149
158
  unless File.exist?(@@meta_dir+"commanders.json")
150
159
  update_commanders()
@@ -167,6 +176,13 @@ module CockatriceFeeder
167
176
  JSON.parse(File.read(@@meta_dir+"tiers.json"))
168
177
  end
169
178
 
179
+ def self.full_data
180
+ unless File.exist?(@@meta_dir+"AllPrintings.json")
181
+ update_full_data()
182
+ end
183
+ JSON.parse(File.read(@@meta_dir+"AllPrintings.json"))
184
+ end
185
+
170
186
  def self.deck_obj(link = "", name = "", commanders = [], date = nil, price = nil)
171
187
  {
172
188
  link: link,
@@ -367,7 +383,7 @@ module CockatriceFeeder
367
383
  [
368
384
  (andcolors.nil? ? nil : "true"),
369
385
  (colors.nil? ? nil : "colors=#{URI.encode_www_form_component(colors)}"),
370
- (commander.nil? ? nil : "commanders=#{URI.encode_www_form_component(commander)}"),
386
+ (commander.nil? ? nil : "commanders=\"#{URI.encode_www_form_component(commander)}\""),
371
387
  (owner.nil? ? nil : "owner=#{URI.encode_www_form_component(owner)}"),
372
388
  "formats=#{formats}",
373
389
  "orderBy=#{orderBy}",
@@ -495,6 +511,118 @@ module CockatriceFeeder
495
511
  content.strip.split(" ").last.split(".").first.gsub(",","")
496
512
  end
497
513
 
514
+ def self.mtgapi_card(params = {multiverse_id: nil, name: nil, set:nil})
515
+ defaults = {multiverse_id: nil, name: nil}
516
+ params = defaults.merge(params)
517
+
518
+ puts "looking up #{params}"
519
+
520
+ card = nil
521
+ if params[:multiverse_id] != nil
522
+ card = JSON.parse(
523
+ HTTParty.get("https://api.magicthegathering.io/v1/cards/#{params[:multiverse_id]}").body
524
+ )["card"]
525
+ elsif params[:name] != nil
526
+ query = [
527
+ "name=#{URI.encode_www_form_component(params[:name])}",
528
+ (params[:set] != nil ? "set=#{params[:set]}" : nil)
529
+ ].compact.join("&")
530
+
531
+ card = JSON.parse(
532
+ HTTParty.get("https://api.magicthegathering.io/v1/cards?#{query}").body
533
+ )["cards"].first
534
+ end
535
+ return card
536
+ end
537
+
538
+ # CockatriceFeeder.build_deck_from_sets("Lazav, Dimir Mastermind", ["RAV", "GPT", "DIS", "RTR", "GTC", "DGM", "GRN", "RNA", "WAR"])
539
+ def self.build_deck_from_sets(commander, sets)
540
+ #lookup edhrecavg deck for commander
541
+ c = commanders.select{|c| c["name"] == commander}.first
542
+ d = deck_obj("https://edhrec-json.s3.amazonaws.com/en/decks/#{c["link"]}.json", c["name"]+" SCRAW", [c["name"]])
543
+ edhrecavg_deck(d)
544
+
545
+ #remember cards to avoid repeat lookups to mtgapi
546
+ mem = {}
547
+
548
+ #throw out any cards not in sets
549
+ d[:cardlist] = d[:cardlist].select do |cl|
550
+ name = cl.split(' ')[1..-1].join(" ")
551
+ unless mem.has_key?(name)
552
+ mem[name] = mtgapi_card(name: cl.split(' ')[1..-1].join(" "))
553
+ end
554
+ card = mem[name]
555
+
556
+ (card["printings"] & sets).length > 0
557
+ end
558
+
559
+ #lookup archidekt decks for the commander to find other cards from the set
560
+ arch_decks = archidekt_decklist(nil, nil, c["name"])
561
+ arch_decks.each do |ad| archidekt_deck(ad) end
562
+ arch_decks.each do |ad|
563
+ in_set = ad[:cardlist].select do |cl|
564
+ name = cl.split(' ')[1..-1].join(" ")
565
+ unless mem.has_key?(name)
566
+ mem[name] = mtgapi_card(name: cl.split(' ')[1..-1].join(" "))
567
+ end
568
+ card = mem[name]
569
+
570
+ #flip/dual cards don't always work
571
+ if card != nil
572
+ (card["printings"] & sets).length > 0
573
+ end
574
+ end
575
+
576
+ in_set.each do |cl|
577
+ name = cl.split(' ')[1..-1].join(" ")
578
+ cur = d[:cardlist].map{|x| x.split(' ')[1..-1].join(" ")}
579
+ curlen = d[:cardlist].map{|x| x.split(' ').first.to_i}.inject(0){|sum,x| sum + x }
580
+ unless cur.include?(name) || curlen >= 100
581
+ d[:cardlist] << cl
582
+ end
583
+ end
584
+
585
+ curlen = d[:cardlist].map{|x| x.split(' ').first.to_i}.inject(0){|sum,x| sum + x }
586
+ if curlen >= 100
587
+ break
588
+ end
589
+ end
590
+
591
+ #lookup deckstats decks for the commander
592
+ curlen = d[:cardlist].map{|x| x.split(' ').first.to_i}.inject(0){|sum,x| sum + x }
593
+ if curlen < 100
594
+ dstat_decks = deckstats_decklist(c["name"],1..5)
595
+ dstat_decks.each do |ds| deckstats_deck(ds) end
596
+ dstat_decks.each do |ds|
597
+ in_set = ds[:cardlist].select do |cl|
598
+ name = cl.split(' ')[1..-1].join(" ")
599
+ unless mem.has_key?(name)
600
+ mem[name] = mtgapi_card(name: cl.split(' ')[1..-1].join(" "))
601
+ end
602
+ card = mem[name]
603
+
604
+ (card["printings"] & sets).length > 0
605
+ end
606
+
607
+ in_set.each do |cl|
608
+ name = cl.split(' ')[1..-1].join(" ")
609
+ cur = d[:cardlist].map{|x| x.split(' ')[1..-1].join(" ")}
610
+ curlen = d[:cardlist].map{|x| x.split(' ').first.to_i}.inject(0){|sum,x| sum + x }
611
+ unless cur.include?(name) || curlen >= 100
612
+ d[:cardlist] << cl
613
+ end
614
+ end
615
+
616
+ curlen = d[:cardlist].map{|x| x.split(' ').first.to_i}.inject(0){|sum,x| sum + x }
617
+ if curlen >= 100
618
+ break
619
+ end
620
+ end
621
+ end
622
+
623
+ d
624
+ end
625
+
498
626
  def self.gobble
499
627
  setup(skip_meta = true)
500
628
  update_commanders()
@@ -537,6 +665,16 @@ module CockatriceFeeder
537
665
  end
538
666
  }
539
667
 
668
+ puts "Fetching the first page of edh decks from archidekt ordered by createdAt"
669
+ decks = CockatriceFeeder.archidekt_decklist()
670
+ puts "#{decks.length} decks found."
671
+ decks.each {|d|
672
+ CockatriceFeeder.archidekt_deck(d)
673
+ if d[:cardlist].length > 0
674
+ total_decks += 1
675
+ end
676
+ }
677
+
540
678
  puts "#{total_decks} decks created at #{@@deck_dir}."
541
679
 
542
680
  puts "cleaning up"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cockatrice_feeder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Steinwachs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-13 00:00:00.000000000 Z
11
+ date: 2020-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri