ordinals 1.1.1 → 1.1.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/Manifest.txt +1 -0
- data/Rakefile +1 -1
- data/lib/ordinals/sandbox.rb +127 -0
- data/lib/ordinals.rb +2 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 19ed27e28ef41fc1d249f8275cc9a5dc829dee789693c3b32ee4af3ebfd40408
|
|
4
|
+
data.tar.gz: 28b5186c473c0b21fcf493d446edb718c3715667cf1ba89eebff2609a7d0f28b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 61a44488afd23242742de448620670b9b610ec68b5df9fe00c94f7e282449c41785476e35f4a78a29429a3d1ace452382eb62b42f4a013d69d84f88cd546b1da
|
|
7
|
+
data.tar.gz: 9faa0175c1a53637db9f2119f9b20dd6c632c72f8f631b2daef505c67f85056820d1259bfe6f8d7c618dd8f26908f241f8dd467e7a7140db553137f53a63fb40
|
data/CHANGELOG.md
CHANGED
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
module Ordinals
|
|
4
|
+
class Sandbox
|
|
5
|
+
def initialize( dir='./content' )
|
|
6
|
+
@dir = dir
|
|
7
|
+
@force = false
|
|
8
|
+
@delay_in_s = 0.5 ## wait 0.5s before next (possible) request
|
|
9
|
+
@requests = 0
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def exist?( id ) ### add alias for different name(s) - why? why not?
|
|
14
|
+
path = "#{@dir}/#{id}"
|
|
15
|
+
File.exist?( path )
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def read( id )
|
|
19
|
+
path = "#{@dir}/#{id}"
|
|
20
|
+
read_blob( path )
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def add( id )
|
|
24
|
+
path = "#{@dir}/#{id}"
|
|
25
|
+
if !@force && File.exist?( path )
|
|
26
|
+
## puts " in sandbox"
|
|
27
|
+
else
|
|
28
|
+
sleep( @delay_in_s ) if @delay_in_s && @requests > 0
|
|
29
|
+
|
|
30
|
+
## note: save text as blob - byte-by-byte as is (might be corrupt text)
|
|
31
|
+
content = Ordinals.content( id )
|
|
32
|
+
## pp content
|
|
33
|
+
#=> #<Ordinals::Api::Content:0x000001a1352df938
|
|
34
|
+
# @data="RIFF\xF8\v\x00\x00WEBPVP8 \xEC\v\x00\x00...",
|
|
35
|
+
# @length=3072,
|
|
36
|
+
# @type="image/png"
|
|
37
|
+
|
|
38
|
+
## puts "data:"
|
|
39
|
+
## puts content.data
|
|
40
|
+
write_blob( path, content.data )
|
|
41
|
+
@requests += 1
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def add_csv( path )
|
|
47
|
+
recs = read_csv( path )
|
|
48
|
+
puts " #{recs.size} record(s)"
|
|
49
|
+
|
|
50
|
+
recs.each_with_index do |rec,i|
|
|
51
|
+
id = rec['id']
|
|
52
|
+
puts "==> #{i+1}/#{recs.size} - #{id}..."
|
|
53
|
+
add( id )
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def add_collection( path )
|
|
58
|
+
data = read_json( path )
|
|
59
|
+
puts " #{data['items'].size} record(s)"
|
|
60
|
+
|
|
61
|
+
data['items'].each_with_index do |rec,i|
|
|
62
|
+
name = rec['name']
|
|
63
|
+
id = rec['inscription_id']
|
|
64
|
+
puts "==> #{i+1}/#{data['items'].size} - #{name} @ #{id}..."
|
|
65
|
+
add( id )
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
ID_RX = /[a-f0-9]{64}i[0-9]/x
|
|
72
|
+
|
|
73
|
+
def _find_ids( values )
|
|
74
|
+
values.select { |val| val.is_a?(String) && ID_RX.match(val) }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def add_data( obj )
|
|
78
|
+
if obj.is_a?( Array )
|
|
79
|
+
recs = obj
|
|
80
|
+
puts " #{recs.size} record(s)"
|
|
81
|
+
recs.each_with_index do |rec,i|
|
|
82
|
+
if rec.is_a?( String )
|
|
83
|
+
id = rec
|
|
84
|
+
puts "==> #{i+1}/#{recs.size} #{id}..."
|
|
85
|
+
add( id )
|
|
86
|
+
else ## assume array of strings for now
|
|
87
|
+
values = rec
|
|
88
|
+
print "==> #{i+1}/#{recs.size} "
|
|
89
|
+
ids = _find_ids( values )
|
|
90
|
+
if ids.size == 1
|
|
91
|
+
id = ids[0]
|
|
92
|
+
puts " #{id}..."
|
|
93
|
+
add( id )
|
|
94
|
+
else
|
|
95
|
+
puts
|
|
96
|
+
if ids.empty?
|
|
97
|
+
puts "!! ERROR - no inscribe id found in data row:"
|
|
98
|
+
else
|
|
99
|
+
puts "!! ERROR - more than one (that is, #{ids.size}) inscribe id found in data row:"
|
|
100
|
+
end
|
|
101
|
+
pp values
|
|
102
|
+
exit 1
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
else
|
|
107
|
+
## todo/fix: raise ArgumentError - why? why not?
|
|
108
|
+
puts "!! ERROR - sorry"
|
|
109
|
+
exit 1
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# todo/add
|
|
114
|
+
# def add_html( path )
|
|
115
|
+
# end
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def add_dir( rootdir )
|
|
119
|
+
## glob for **.csv and **.html
|
|
120
|
+
datasets = Dir.glob( "#{rootdir}/**/*.csv" )
|
|
121
|
+
datasets.each do |path|
|
|
122
|
+
add_csv( path )
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end ## class Sandbox
|
|
126
|
+
end ## module Ordinals
|
|
127
|
+
|
data/lib/ordinals.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ordinals
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gerald Bauer
|
|
@@ -91,6 +91,7 @@ files:
|
|
|
91
91
|
- lib/ordinals/recursive/composite.rb
|
|
92
92
|
- lib/ordinals/recursive/generator.rb
|
|
93
93
|
- lib/ordinals/recursive/image.rb
|
|
94
|
+
- lib/ordinals/sandbox.rb
|
|
94
95
|
- lib/ordinals/stats.rb
|
|
95
96
|
homepage: https://github.com/ordbase/ordbase
|
|
96
97
|
licenses:
|