way_to_sultan 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 +7 -0
- data/lib/way_to_sultan.rb +90 -0
- metadata +43 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 2443d77d7c7dec4f2a7d95606d29557e581fa382cd818916ffa37dff2114bf4c
|
|
4
|
+
data.tar.gz: a5a7714c2755f42da17a4dd00090484100fe358f0fcc4a2e3f619b1386c5c83f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: fd21f1776a0c5f831c34abd1ab645e356f8a24e396b11064cc34fd18412f0cb60ebcc40303ba83e78012795f82327a1fad2ff988fb06894ab7a1d2289597d852
|
|
7
|
+
data.tar.gz: '087446515aebed3efc1f8ede1c981bf7f61ac465bedcf944f8939a2c6229479f3b7ac138989b33cb5213071a606860052b44d2efd88e9f24938524b189a2404b'
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Pattarin Wongwaipanich
|
|
2
|
+
# 6210545564
|
|
3
|
+
|
|
4
|
+
require 'net/http'
|
|
5
|
+
require 'uri'
|
|
6
|
+
|
|
7
|
+
class WayToSultan
|
|
8
|
+
def self.print_asset(source)
|
|
9
|
+
elements = source.split("\n")
|
|
10
|
+
|
|
11
|
+
company, assets = ''
|
|
12
|
+
|
|
13
|
+
elements.each_with_index do |each_element, index|
|
|
14
|
+
line = each_element.strip
|
|
15
|
+
if line.include? '<div class="col-xs-12 col-md-12 col-lg-8">'
|
|
16
|
+
company = elements[index + 1].strip.to_s
|
|
17
|
+
company.delete_prefix!('<h3>').delete_suffix!('</h3>')
|
|
18
|
+
end
|
|
19
|
+
if (line.force_encoding('UTF-8').include? 'Assets') || (line.force_encoding('UTF-8').include? 'สินทรัพย์รวม')
|
|
20
|
+
assets = elements[index + 4].strip.to_s
|
|
21
|
+
assets.slice!(assets.index('&')..-1)
|
|
22
|
+
assets.delete_prefix!('<td >')
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
puts "#{company.force_encoding('UTF-8')} : #{assets.force_encoding('UTF-8')}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.stock
|
|
30
|
+
url = 'https://www.set.or.th/set/commonslookup.do?'
|
|
31
|
+
|
|
32
|
+
base_url = 'https://www.set.or.th'
|
|
33
|
+
|
|
34
|
+
source = Net::HTTP.get(URI.parse(url))
|
|
35
|
+
|
|
36
|
+
# 0-9, A, B, C, ..., Y, Z
|
|
37
|
+
index_menu = source.split("\n")
|
|
38
|
+
|
|
39
|
+
# find index menu
|
|
40
|
+
i = 0
|
|
41
|
+
index_menu.each_with_index do |line, index|
|
|
42
|
+
if line.include? 'class="col-xs-12 padding-top-10 text-center capital-letter"'
|
|
43
|
+
index_menu[index+1..-1].each do |word|
|
|
44
|
+
w = word.strip
|
|
45
|
+
if w != ""
|
|
46
|
+
index += 1
|
|
47
|
+
i = index
|
|
48
|
+
break
|
|
49
|
+
end
|
|
50
|
+
index += 1
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
c = 25
|
|
56
|
+
while c >= 0
|
|
57
|
+
# get suffix link
|
|
58
|
+
index_page = index_menu[i+1].strip.to_s.split('"')[1]
|
|
59
|
+
# go to alphabetic page
|
|
60
|
+
url = base_url + index_page
|
|
61
|
+
source = Net::HTTP.get(URI.parse(url))
|
|
62
|
+
start_at_line = 0
|
|
63
|
+
source = source.split("\n")
|
|
64
|
+
source.each_with_index do |each_line, ind|
|
|
65
|
+
if each_line.include? '<div class="text-right">'
|
|
66
|
+
start_at_line = ind + 1
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
source[start_at_line..-1].each_with_index do |each_line, index|
|
|
70
|
+
if each_line.include? '<tr valign="top">'
|
|
71
|
+
w = source[start_at_line + index + 1].strip
|
|
72
|
+
if w == ""
|
|
73
|
+
increment = 2
|
|
74
|
+
while w == ""
|
|
75
|
+
w = source[start_at_line + index + increment].strip
|
|
76
|
+
increment += 1
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
abb_company_name = w.split('target="">')[-1].delete_suffix('</a></td>')
|
|
80
|
+
|
|
81
|
+
company_page = "https://www.set.or.th/set/companyhighlight.do?symbol=#{abb_company_name}&ssoPageId=5&language=th&country=TH"
|
|
82
|
+
info = Net::HTTP.get(URI.parse(company_page))
|
|
83
|
+
print_asset(info)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
i += 1
|
|
87
|
+
c -= 1
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: way_to_sultan
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- '6210545564'
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-01-31 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: you need to do something more than just installing this gem
|
|
14
|
+
email:
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/way_to_sultan.rb
|
|
20
|
+
homepage:
|
|
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: way to be richer
|
|
43
|
+
test_files: []
|