unisat 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 67fa8182506bbe32a101682e64ba4660f0b558789d876f2dafd3628dafc257be
4
+ data.tar.gz: 64dbb1c6e34b9b84a8df7bebbea5b08bac283cd3aaaadf1ec91051e3884fc89b
5
+ SHA512:
6
+ metadata.gz: a503beaab753968070d54cf00be80a733dcb27fcd3e7d581e93ae920eb35a4615f20b9e1757976502f2c4d41700a75be810692baf1cd7d17a6a862deeb00c35d
7
+ data.tar.gz: 9757e1a741d451cc155e017ec694764019e17b138171a0fc57d54876ce508bda2455f87a536cd703006166f15dc1dec0c8b1b21730aaec4bb457fe464d8ccdf6
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ### 0.0.1 / 2023-08-14
2
+
3
+ * Everything is new. First release
data/Manifest.txt ADDED
@@ -0,0 +1,7 @@
1
+ CHANGELOG.md
2
+ Manifest.txt
3
+ README.md
4
+ Rakefile
5
+ lib/unisat.rb
6
+ lib/unisat/cache.rb
7
+ lib/unisat/version.rb
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # UniSat.io Lite Helpers for Full-Text Search in Bitcoin Ordinal Inscriptions
2
+
3
+ unisat - lite helpers for full-text search in bitcoin ordinal inscriptions powered by unisat.io
4
+
5
+ * home :: [github.com/ordbase/unisat](https://github.com/ordbase/unisat)
6
+ * bugs :: [github.com/ordbase/unisat/issues](https://github.com/ordbase/unisat/issues)
7
+ * gem :: [rubygems.org/gems/unisat](https://rubygems.org/gems/unisat)
8
+ * rdoc :: [rubydoc.info/gems/unisat](http://rubydoc.info/gems/unisat)
9
+
10
+
11
+
12
+ ## Usage
13
+
14
+ To be done
15
+
16
+
17
+
18
+
19
+
20
+
21
+ ## License
22
+
23
+ The scripts are dedicated to the public domain.
24
+ Use it as you please with no restrictions whatsoever.
25
+
26
+
27
+ ## Questions? Comments?
28
+
29
+ Join us in the [Ordgen / ORC-721 discord (chat server)](https://discord.gg/dDhvHKjm2t). Yes you can.
30
+ Your questions and commetary welcome.
31
+
32
+
33
+ Or post them over at the [Help & Support](https://github.com/geraldb/help) page. Thanks.
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require 'hoe'
2
+ require './lib/unisat/version.rb'
3
+
4
+ Hoe.spec 'unisat' do
5
+
6
+ self.version = Unisat::VERSION
7
+
8
+ self.summary = "unisat - lite helpers for full-text search in bitcoin ordinal inscriptions powered by unisat.io"
9
+ self.description = summary
10
+
11
+ self.urls = { home: 'https://github.com/ordbase/ordbase' }
12
+
13
+ self.author = 'Gerald Bauer'
14
+ self.email = 'gerald.bauer@gmail.com'
15
+
16
+ # switch extension to .markdown for gihub formatting
17
+ self.readme_file = 'README.md'
18
+ self.history_file = 'CHANGELOG.md'
19
+
20
+ self.extra_deps = [
21
+ ['cocos'],
22
+ ['puppeteer-ruby'],
23
+ ['nokogiri'],
24
+ ]
25
+
26
+ self.licenses = ['Public Domain']
27
+
28
+ self.spec_extras = {
29
+ required_ruby_version: '>= 2.3'
30
+ }
31
+ end
@@ -0,0 +1,108 @@
1
+ module Unisat
2
+ ###
3
+ ## todo: use a config block in the future - why? why not?
4
+ def self.cache_dir=( dir ) @cache = Cache.new( dir ); end
5
+ def self.cache() @cache ||= Cache.new( './unisat' ); end
6
+
7
+
8
+ def self.parse_page( html )
9
+ doc = Nokogiri::HTML( html )
10
+
11
+ items = []
12
+
13
+ sats = doc.css( '.item-container' )
14
+ sats.each_with_index do |el,i|
15
+ puts "==> sat ##{i+1}/#{sats.size}..."
16
+
17
+ h = {}
18
+ # <a href="https://ordinals.com/inscription/
19
+ # 9613d44f53a1245bf34f43820163bb3064a5715c19f0d6c767a14d1b49f46614i0"
20
+ # target="_blank" rel="noreferrer" class="sats-item ">
21
+ a = el.at( 'a.sats-item' )
22
+ h['href'] = a['href']
23
+
24
+ name = el.at( '.name' )
25
+ h['name'] = name.text
26
+
27
+ num = el.at( '.num' )
28
+ h['num'] = num.text
29
+
30
+ address = el.at( '.address' )
31
+ h['address'] = address.text
32
+
33
+ date = el.at( '.date' )
34
+ h['date'] = date.text
35
+ ##pp h
36
+
37
+ items << h
38
+ end
39
+ items
40
+ end # method _parse_page
41
+
42
+
43
+ class Cache
44
+ def initialize( dir )
45
+ @dir = dir
46
+ end
47
+
48
+ ## todo:
49
+ ## - add offset: nil, limit: nil - why? why not?
50
+ def read( key )
51
+ recs = []
52
+
53
+ paths = Dir.glob( "#{@dir}/#{key}/*.json" )
54
+ puts " #{paths.size} page(s) in cache"
55
+
56
+ paths.each_with_index do |path,i|
57
+ results = read_json( path )
58
+ puts "==> #{i+1}/#{paths.size} - #{results.size} inscribe(s) in >#{path}<..."
59
+
60
+ results.each do |h|
61
+ date = h['date'] # note: might include unconfirmed!!!
62
+ ## always "auto-magically" filter out unconfirmed for now
63
+ if date == 'unconfirmed'
64
+ puts " !! INFO - skipping unconfirmed inscribe"
65
+ next
66
+ end
67
+
68
+ ## todo/fix:
69
+ ## reformat date here/parse
70
+ ## and change to iso e.g. 2023-12-24 17:18 or such - why? why not!!!!
71
+
72
+
73
+ ## id -- split href by / and get last part (is id)
74
+ id = h['href'].split( '/')[-1]
75
+ ## num -- remove/ strip leadingnumber sign (#)
76
+ num = h['num'].sub( '#', '' )
77
+ recs << {
78
+ 'id' => id,
79
+ 'num' => num,
80
+ 'date' => date,
81
+ 'address' => h['address'],
82
+ 'text' => h['name'], ## change name to text
83
+ }
84
+ end
85
+ end
86
+ puts " #{recs.size} inscribe(s) - total"
87
+ recs
88
+ end # method read
89
+
90
+
91
+ def exist?( key, offset: )
92
+ outpath = "#{@dir}/#{key}/#{offset}.json"
93
+ File.exist?( outpath )
94
+ end
95
+
96
+ def add_page( page, key, offset: )
97
+ data = Unisat.parse_page( page )
98
+
99
+ ## note: only write if results > 0
100
+ if data.size > 0
101
+ outpath = "#{@dir}/#{key}/#{offset}.json"
102
+ write_json( outpath, data )
103
+ else
104
+ puts "!! WARN - no results found in page #{offset} for key >#{key}<"
105
+ end
106
+ end
107
+ end # class Cache
108
+ end # module Unisat
@@ -0,0 +1,21 @@
1
+
2
+ module Unisat
3
+
4
+ # sync version w/ sport.db n friends - why? why not?
5
+ MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
+ MINOR = 0
7
+ PATCH = 1
8
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
9
+
10
+ def self.version
11
+ VERSION
12
+ end
13
+
14
+ def self.banner
15
+ "unisat/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in >#{root}<"
16
+ end
17
+
18
+ def self.root
19
+ File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
20
+ end
21
+ end
data/lib/unisat.rb ADDED
@@ -0,0 +1,116 @@
1
+ require 'cocos'
2
+
3
+ require 'puppeteer-ruby'
4
+ require 'nokogiri'
5
+
6
+
7
+ # our own code
8
+ require_relative 'unisat/version' # always goes first
9
+ require_relative 'unisat/cache'
10
+
11
+
12
+
13
+
14
+ module Unisat
15
+ module Puppeteer
16
+
17
+ ###
18
+ ## todo: use a config block in the future - why? why not?
19
+ def self.chrome_path=( path )
20
+ if File.exist?( path )
21
+ puts "** bingo! found chrome executable @ path >#{path}<"
22
+ else
23
+ puts "*** ERROR - sorry; cannot find chrome executable @ path >#{path}<"
24
+ exit 1
25
+ end
26
+
27
+ @chrome_path = path
28
+ end
29
+
30
+ def self.chrome_path() @chrome_path; end
31
+
32
+ ## use/rename to wait_in_secs - why? why not?
33
+ def self.wait_in_s=( s ) @wait_in_s = s; end
34
+ def self.wait_in_s() @wait_in_s ||= 10; end
35
+
36
+ ## shortcut helper
37
+ def self.cache() Unisat.cache; end
38
+
39
+
40
+ ###
41
+ # search
42
+ def self.search( q, offset: 1,
43
+ limit: 1,
44
+ force: false )
45
+
46
+ opts = {}
47
+ opts[:headless] = false
48
+ opts[:executable_path] = chrome_path if chrome_path ## add only if set (default is nil)
49
+
50
+
51
+ ::Puppeteer.launch( **opts ) do |browser|
52
+
53
+ page = browser.new_page
54
+
55
+ limit.times do |i|
56
+ count = offset+i
57
+
58
+ page_url = "https://unisat.io/search?q=#{q}&type=text&p=#{count}"
59
+ print page_url
60
+
61
+ ## check if already in cache
62
+ if force == false && cache.exist?( q, offset: count )
63
+ print "...in cache\n"
64
+ next
65
+ end
66
+
67
+ print "... goto page ...\n"
68
+ response = page.goto( page_url )
69
+ pp response.headers
70
+
71
+ puts "sleeping #{wait_in_s} sec(s)..."
72
+ sleep( wait_in_s )
73
+
74
+ ## print search result summary / counts
75
+ page.wait_for_selector('div.result-notice')
76
+ el = page.query_selector("div.result-notice")
77
+ puts
78
+ puts el.evaluate("el => el.innerText")
79
+ #=> Searched for "biixel" among 3252336 records, found 1105 results.
80
+
81
+
82
+ ## print pagination
83
+ page.wait_for_selector('ul.ant-pagination')
84
+ el = page.query_selector("ul.ant-pagination")
85
+ puts
86
+ puts el.evaluate("el => el.innerText")
87
+ #=> 1 ••• 32 33 34 35
88
+
89
+
90
+ ## get search results (32 inscribes per page)
91
+ page.wait_for_selector('div.sats-list')
92
+ el = page.query_selector("div.sats-list")
93
+
94
+ html = el.evaluate("el => el.innerHTML")
95
+ # puts
96
+ # puts html
97
+
98
+ cache.add_page( html, q,
99
+ offset: count )
100
+ end
101
+
102
+ puts "sleeping 2 secs before shutdown..."
103
+ sleep( 2 )
104
+ end
105
+ end # method search
106
+ end # module Puppeteer
107
+ end # module Unisat
108
+
109
+
110
+
111
+ ## add alternate name alias - why? why not?
112
+ UniSat = Unisat
113
+
114
+
115
+
116
+ puts Unisat.banner
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unisat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gerald Bauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cocos
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: puppeteer-ruby
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rdoc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '7'
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '4.0'
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '7'
75
+ - !ruby/object:Gem::Dependency
76
+ name: hoe
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '4.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '4.0'
89
+ description: unisat - lite helpers for full-text search in bitcoin ordinal inscriptions
90
+ powered by unisat.io
91
+ email: gerald.bauer@gmail.com
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files:
95
+ - CHANGELOG.md
96
+ - Manifest.txt
97
+ - README.md
98
+ files:
99
+ - CHANGELOG.md
100
+ - Manifest.txt
101
+ - README.md
102
+ - Rakefile
103
+ - lib/unisat.rb
104
+ - lib/unisat/cache.rb
105
+ - lib/unisat/version.rb
106
+ homepage: https://github.com/ordbase/ordbase
107
+ licenses:
108
+ - Public Domain
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options:
112
+ - "--main"
113
+ - README.md
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '2.3'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubygems_version: 3.4.10
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: unisat - lite helpers for full-text search in bitcoin ordinal inscriptions
131
+ powered by unisat.io
132
+ test_files: []