Skip to content

Instantly share code, notes, and snippets.

@windows98SE
Last active September 29, 2020 09:52
Show Gist options
  • Save windows98SE/4b1cbc9a63da1d130b50178d2ff3c61e to your computer and use it in GitHub Desktop.
Save windows98SE/4b1cbc9a63da1d130b50178d2ff3c61e to your computer and use it in GitHub Desktop.
THAILAND SETTRADE for scrollphathd
import requests
import time
import scrollphathd
from scrollphathd.fonts import font3x5
class SETTRADE:
def __init__(self):
self.url = 'https://api.settrade.com/api/market/SET/info'
def run(self):
req = requests.get(self.url)
if req.status_code == 200:
return self.extract_data(req.json())
@staticmethod
def extract_data(j):
data = {
# 'status': j['market_status'],
'last': j['index'][0]['last'],
'change': j['index'][0]['change'],
'percent_change': round(j['index'][0]['percent_change'], 2)
}
return ("SET:{:+.2f}({:+.2f}%){:.2f}".format(
data['change'],
data['percent_change'],
data['last']
)
)
def scroll_message(message):
scrollphathd.clear()
length = scrollphathd.write_string(message, y=2)
scrollphathd.show()
time.sleep(0.5)
length -= scrollphathd.width
while length > 0:
scrollphathd.scroll(1)
scrollphathd.show()
length -= 1
time.sleep(0.05)
time.sleep(0.5)
if __name__ == "__main__":
settrade = SETTRADE()
scrollphathd.set_font(font3x5)
scrollphathd.set_brightness(0.1)
try:
while True:
data = settrade.run()
if data:
print(data)
scroll_message(data)
time.sleep(2)
except KeyboardInterrupt:
print("Exiting!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment