mtgtop8_scrapper 0.0.4 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -12
- data/lib/mtgtop8_scrapper.rb +14 -4
- metadata +23 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 351d162e1d9c8997ea331b73dc4ed73f33c4c05ed79d424f64a1bc72112a8cee
|
4
|
+
data.tar.gz: 21d8faaa5f5b593058dee9c749392361287d3dd826e527eb60cbf143f1af2ee9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87b440a5680d672b39b76988dd154a7147de438c29b85cd499e3b825611cba53ae90a26f93b74c84cb2bfb19cb4d67d6df3e47de7c1b2b19e710a3baba6eb5a9
|
7
|
+
data.tar.gz: 105c1597588ebb67098c632f2b67cd21cb45172ce400de2870b612e0dcd7732fa0d07a3c05119fa11eae43034248e9fb33dbb89d0d77f7c3b9b4a29bb99e7889
|
data/README.md
CHANGED
@@ -32,25 +32,25 @@ https://user-images.githubusercontent.com/34798570/220813931-7d3d73db-6b1e-4564-
|
|
32
32
|
## Why?
|
33
33
|
- 🥹 Mixing coding and Magic 💛
|
34
34
|
- 🎲 Being able to extract & format in a fast/easy way is really helpful, so it's possible to play with it around later.
|
35
|
-
- 📈 Reports are being used to generate Monthly Retrospectives related to the weekly tournaments around the city.
|
35
|
+
- 📈 Reports are being used to generate Monthly Retrospectives related to the weekly tournaments around the city with [MTG Standings Generator](https://github.com/kammradt/mtg-standings-generator).
|
36
36
|
- 🧑💻 All of them are available [here, in mtgjoinville.super.site](https://mtgjoinville.super.site/)
|
37
37
|
|
38
38
|
### The current ecosystem
|
39
39
|
|
40
40
|
- [MTG Joinville Website](https://mtgjoinville.super.site/)
|
41
|
-
|
41
|
+
- 😉 Entrypoint for a bunch of information related to Magic in our city
|
42
42
|
- [MTGTop8 Scrapper](https://github.com/kammradt/mtgtop8-scrapper)
|
43
|
-
|
44
|
-
- [MTG
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
- 🪓 Will gather data from the main website that holds results from many tournaments
|
44
|
+
- [MTG Standings Generator](https://github.com/kammradt/mtg-standings-generator)
|
45
|
+
- Use reports from [MTGTop8 Scrapper](https://github.com/kammradt/mtgtop8-scrapper) to build social media ready images showing top 8 players and their decks.
|
46
|
+
- This is currently being used in our [MTG Joinville Website](https://mtgjoinville.super.site/) 🙏🏻.
|
47
|
+
- <details>
|
48
48
|
|
49
|
-
|
49
|
+
<summary>Some image examples</summary>
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
<img alt="retro" src="assets/retro.png" />
|
52
|
+
<img alt="retro1" src="assets/retro1.png" />
|
53
|
+
</details>
|
54
54
|
|
55
55
|
## Install
|
56
56
|
> None of the builds/versions will probably be stable. This is a kind of pet project, so use at your own risk.
|
@@ -63,7 +63,12 @@ gem install mtgtop8_scrapper
|
|
63
63
|
|
64
64
|
> Feel free to copy it from examples.rb file
|
65
65
|
|
66
|
-
```
|
66
|
+
```ruby
|
67
|
+
# If you are offline/don't want to hit the real server,
|
68
|
+
# you can use the flag ENV['TESTING'] for work with files under /offline
|
69
|
+
#
|
70
|
+
# Just use any truthy value for the ENV['TESTING'] var, such as '1' or 'true'
|
71
|
+
|
67
72
|
require 'mtgtop8_scrapper'
|
68
73
|
|
69
74
|
link = 'https://www.mtgtop8.com/event?e=41158&d=505864&f=PAU'
|
data/lib/mtgtop8_scrapper.rb
CHANGED
@@ -18,13 +18,14 @@ class MTGTop8Scrapper < Scrapper
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def top_8_players
|
21
|
-
# TODO: Handle events with less than/more than 8
|
22
21
|
indexes_for_top_8_player_table = (2..9).to_a
|
23
22
|
|
24
|
-
indexes_for_top_8_player_table.map { |i| map_doc_to_report(i) }.sort_by { |player| player[:rank] }
|
23
|
+
indexes_for_top_8_player_table.map { |i| map_doc_to_report(i) }.compact.sort_by { |player| player[:rank] }
|
25
24
|
end
|
26
25
|
|
27
26
|
def map_doc_to_report(index)
|
27
|
+
return unless index_exists?(index)
|
28
|
+
|
28
29
|
rank = rank_value(index)
|
29
30
|
player = player_value(index)
|
30
31
|
deck = deck_value(index)
|
@@ -32,6 +33,11 @@ class MTGTop8Scrapper < Scrapper
|
|
32
33
|
{ rank:, player:, deck: }
|
33
34
|
end
|
34
35
|
|
36
|
+
def index_exists?(index)
|
37
|
+
# We verify if the rank exists to skip trying to get the 5th person if the event only has 4 people in it.
|
38
|
+
!find_rank_element(index).nil?
|
39
|
+
end
|
40
|
+
|
35
41
|
def event_format
|
36
42
|
path = '/html/body/div/div/div[7]/div[1]/div/div[1]/div[1]/div[1]'
|
37
43
|
|
@@ -44,10 +50,14 @@ class MTGTop8Scrapper < Scrapper
|
|
44
50
|
@doc.at(path).text.partition('-').last.strip
|
45
51
|
end
|
46
52
|
|
47
|
-
def
|
53
|
+
def find_rank_element(index)
|
48
54
|
path = "/html/body/div/div/div[7]/div[1]/div/div[1]/div[#{index}]/div/div[1]"
|
49
55
|
|
50
|
-
@doc.at(path)
|
56
|
+
@doc.at(path)
|
57
|
+
end
|
58
|
+
|
59
|
+
def rank_value(index)
|
60
|
+
find_rank_element(index).text.strip.to_i
|
51
61
|
end
|
52
62
|
|
53
63
|
def player_value(index)
|
metadata
CHANGED
@@ -1,15 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mtgtop8_scrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vinicius Kammradt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
12
|
-
dependencies:
|
11
|
+
date: 2023-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.14.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.14'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.14.1
|
13
33
|
description: Scrape data from MTGTop8 into simple reports
|
14
34
|
email: vinicius.kammradt1@gmail.com
|
15
35
|
executables: []
|