set-assets 1.0.0
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 +7 -0
- data/lib/set-assets.rb +51 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6dcc726abd660c1db7cc1f50fdf39bf10703a3298649d80ab21da395bfb3874f
|
4
|
+
data.tar.gz: 9b8c7aac91eb24acaee6ca4b6f5c5151437b8ae9467707b7c3d039be1c4218f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: be249d51fcf36a4b4347761e0120ba700c45b77ad3c75a3137695a0ac23d066a99b6c10ccb8f2eb659d1e57536abfae88a507f43af11c07df42e4f95b5c4beba
|
7
|
+
data.tar.gz: 43fb347e17f6bf27ab2370b74e3b3270c5f8608aa9e69c02f7d12ff8c039ae0f2cb131880d7c2b7e1e993daa09bb032bdd4899b02392e86f8258c05cc98ceebd
|
data/lib/set-assets.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Tatpol Samakpong
|
2
|
+
# 6210546668
|
3
|
+
|
4
|
+
require 'open-uri'
|
5
|
+
require 'nokogiri'
|
6
|
+
|
7
|
+
class SETAssets
|
8
|
+
|
9
|
+
@@feed_url = 'https://www.set.or.th/set/commonslookup.do'
|
10
|
+
@@base_url_site = 'https://www.set.or.th'
|
11
|
+
|
12
|
+
def self.run
|
13
|
+
doc = get_page_doc(@@feed_url)
|
14
|
+
links = get_prefix_links(doc)
|
15
|
+
links.each do |link|
|
16
|
+
link_doc = get_page_doc("#{@@base_url_site}#{link}")
|
17
|
+
table_rows = link_doc.css('table tr')
|
18
|
+
table_rows.each do |row|
|
19
|
+
a_tags = row.css('td:first-child a')
|
20
|
+
a_tags.each do |tag|
|
21
|
+
stock_url = tag['href']
|
22
|
+
stock_url['profile'] = 'highlight'
|
23
|
+
stock_info = get_stock_info("#{@@base_url_site}#{stock_url}")
|
24
|
+
puts "#{stock_info.first} : #{stock_info.last}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def self.get_page_doc(url)
|
33
|
+
source = URI.open(url)
|
34
|
+
doc = Nokogiri::HTML(source)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.get_stock_info(stock_url)
|
38
|
+
doc = get_page_doc(stock_url)
|
39
|
+
stock_name = doc.css('h3').text
|
40
|
+
last_assets_text = doc.css('table tbody tr:nth-child(2) td')[-2].text
|
41
|
+
# remove HTML non-breaking space ( )
|
42
|
+
last_assets = last_assets_text.gsub("\u00A0", "")
|
43
|
+
[stock_name, last_assets]
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.get_prefix_links(doc)
|
47
|
+
links_container = doc.css('div.col-xs-12.padding-top-10.text-center.capital-letter a')
|
48
|
+
all_links = links_container.map {|a_tag| a_tag['href']}
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: set-assets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tatpol Samakpong
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A gem that display the last assets of SET.
|
14
|
+
email: nicenicegame@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/set-assets.rb
|
20
|
+
homepage: https://rubygems.org/gems/set-assets
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.2.3
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: See the last assets of SET!
|
43
|
+
test_files: []
|