-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
152 lines (140 loc) · 4.83 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from flask import Flask
from flask_cors import CORS
import requests
import os
port = int(os.environ.get('PORT', 5000))
app = Flask(__name__)
# CORS problem
CORS(app)
def getDate(raw_html):
pattern_start = 'ประจำวันที่ <span id="DetailPlace_uc_goldprices1_lblAsTime"><b><font size="3">'
pattern_end = 'เ'
index = 0
length = len(raw_html)
while index < length:
start = raw_html.find(pattern_start, index)
if start > 0:
start = start + len(pattern_start)
end = raw_html.find(pattern_end, start)
date = raw_html[start:end]
index = end
else:
break
return date
def getTime(raw_html):
pattern_start = 'เวลา'
pattern_end = 'น.'
index = 0
length = len(raw_html)
while index < length:
start = raw_html.find(pattern_start, index)
if start > 0:
start = start + len(pattern_start)
end = raw_html.find(pattern_end, start)
time = raw_html[start:end]
index = end
else:
break
return time
# ราคาขายออกทองคำแท่ง 96.5%
def getGoldBullionSellingPrice(raw_html):
pattern_start = '<span id="DetailPlace_uc_goldprices1_lblBLSell"><b><font color='
pattern_end = '</font>'
index = 0
length = len(raw_html)
while index < length:
start = raw_html.find(pattern_start, index)
if start > 0:
start = start + len(pattern_start)
end = raw_html.find(pattern_end, start)
cost = raw_html[start:end]
cost = cost.replace('"','')
costNtrend = cost.split(">")
index = end
else:
break
return costNtrend
# ราคารับซื้อทองคำแท่ง 96.5%
def getGoldBullionPurchasePrice(raw_html):
pattern_start = '<span id="DetailPlace_uc_goldprices1_lblBLBuy"><b><font color='
pattern_end = '</font>'
index = 0
length = len(raw_html)
while index < length:
start = raw_html.find(pattern_start, index)
if start > 0:
start = start + len(pattern_start)
end = raw_html.find(pattern_end, start)
cost = raw_html[start:end]
cost = cost.replace('"','')
costNtrend = cost.split(">")
index = end
else:
break
return costNtrend
# ราคาขายออกทองรูปพรรณ 96.5%
def getGoldJewelrySellingPrice(raw_html):
pattern_start = '<span id="DetailPlace_uc_goldprices1_lblOMSell"><b><font color='
pattern_end = '</font>'
index = 0
length = len(raw_html)
while index < length:
start = raw_html.find(pattern_start, index)
if start > 0:
start = start + len(pattern_start)
end = raw_html.find(pattern_end, start)
cost = raw_html[start:end]
cost = cost.replace('"','')
costNtrend = cost.split(">")
index = end
else:
break
return costNtrend
# ฐานภาษีทองคำรูปพรรณ 96.5%
def getTaxBase(raw_html):
pattern_start = '<span id="DetailPlace_uc_goldprices1_lblOMBuy"><b><font color='
pattern_end = '</font>'
index = 0
length = len(raw_html)
while index < length:
start = raw_html.find(pattern_start, index)
if start > 0:
start = start + len(pattern_start)
end = raw_html.find(pattern_end, start)
cost = raw_html[start:end]
cost = cost.replace('"','')
costNtrend = cost.split(">")
index = end
else:
break
return costNtrend
# main proccess
url = "https://www.goldtraders.or.th"
raw_html = requests.get(url).text
# print(raw_html)
# print(getDate(raw_html))
# print(getTime(raw_html))
# print(getGoldBullionSellingPrice(raw_html))
# print(getGoldBullionPurchasePrice(raw_html))
# print(getGoldJewelrySellingPrice(raw_html))
# print(getTaxBase(raw_html))
gold = {
# ข้อมูลประจำวันที่
"Date":getDate(raw_html),
# ณ เวลา
"Time":getTime(raw_html),
# ราคาขายออกทองคำแท่ง 96.5%
"Gold bullion selling price 96.5%":getGoldBullionSellingPrice(raw_html),
# ราคารับซื้อทองคำแท่ง 96.5%
"Gold bullion purchase price 96.5%":getGoldBullionPurchasePrice(raw_html),
# ราคาขายออกทองคำรูปพรรณ 96.5%
"Gold jewelry selling price 96.5%":getGoldJewelrySellingPrice(raw_html),
# ฐานภาษี ทองคำรูปประพรรณ
"Tax base":getTaxBase(raw_html),
}
# print(gold)
@app.route('/')
def index():
return gold
if __name__ == '__main__':
app.run(host='0.0.0.0', port=port, debug=True)