From d1a686dde7bcccbf411b7e833efa5a59a3fc6bc2 Mon Sep 17 00:00:00 2001 From: gabrielkheisa Date: Fri, 4 Nov 2022 22:42:29 +0700 Subject: [PATCH] update --- README.md | 26 +++++++++++----- index.php | 2 +- script2.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 script2.py diff --git a/README.md b/README.md index e327589..609199b 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,13 @@ https://api.gabrielkheisa.xyz/stocks/usdidr/
 {
-    "price": "15,645.0000",
-    "price_change": "0.0000",
-    "change": "(0.0000%)",
-    "last_update": "As of  09:05PM GMT. Market open.",
-    "server_update": "03-11-2022 08:46:35 GMT+7",
-    "symbol": "#ff0000",
-    "color": "🔴"
+    "price": "15,735",
+    "price_change": "+40.0",
+    "change": "(+0.25%)",
+    "last_update": "As of  03:24PM GMT. Market open.",
+    "server_update": "04-11-2022 22:34:34 GMT+7",
+    "color": "#40ff00",
+    "symbol": "🟢"
 }
 
@@ -39,7 +39,17 @@ https://api.gabrielkheisa.xyz/stocks/ixic/
  • BTC-USD https://api.gabrielkheisa.xyz/stocks/btcusd/ - +
    +{
    +    "price": "21,188.77",
    +    "price_change": "+869.87",
    +    "change": "(+4.28%)",
    +    "last_update": "As of  02:52PM UTC. Market open.",
    +    "server_update": "04-11-2022 21:54:44 GMT+7",
    +    "color": "#40ff00",
    +    "symbol": "🟢"
    +}
    +
  • diff --git a/index.php b/index.php index acf5adc..48ef0e8 100644 --- a/index.php +++ b/index.php @@ -12,7 +12,7 @@ fclose($myfile); $pieces = explode("=", $teks); -$marks = array("price"=>$pieces[0], "price_change"=>$pieces[1], "change"=>$pieces[2], "last_update"=>$pieces[3],"server_update"=>$pieces[4], "symbol"=>$pieces[5], "color"=>$pieces[6]); +$marks = array("price"=>$pieces[0], "price_change"=>$pieces[1], "change"=>$pieces[2], "last_update"=>$pieces[3],"server_update"=>$pieces[4], "color"=>$pieces[5], "symbol"=>$pieces[6]); echo json_encode($marks, JSON_PRETTY_PRINT); } diff --git a/script2.py b/script2.py new file mode 100644 index 0000000..5755f01 --- /dev/null +++ b/script2.py @@ -0,0 +1,91 @@ +import requests +from selenium import webdriver +from selenium.webdriver.chrome.options import Options +import time +from datetime import datetime +import base64 + +import math + +from selenium.webdriver.chrome.options import Options + +key = "API_KEY" + +while(1): + try: + now = datetime.now() + dt_string = now.strftime("%d-%m-%Y %H:%M:%S") + + options = Options() + options.add_argument('--no-sandbox') + options.add_argument('--window-size=1420,1080') + options.add_argument('--headless') + options.add_argument('--disable-gpu') + browser = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver", chrome_options=options) + + browser.delete_all_cookies() + browser.get("https://finance.yahoo.com/quote/IDR=X") + + time.sleep(5) + + + harga = browser.find_element_by_xpath("//*[@id=\"quote-header-info\"]/div[3]/div[1]/div/fin-streamer[1]").get_attribute('textContent') + price_change = browser.find_element_by_xpath("//*[@id=\"quote-header-info\"]/div[3]/div[1]/div/fin-streamer[2]/span").get_attribute('textContent') + change = browser.find_element_by_xpath("//*[@id=\"quote-header-info\"]/div[3]/div[1]/div/fin-streamer[3]/span").get_attribute('textContent') + last_update = browser.find_element_by_xpath("//*[@id=\"quote-market-notice\"]/span").get_attribute('textContent') + + harga = harga.split(".")[0] + + change_flag = "" + + if "+" in price_change: + change_flag = "+" + price_change.replace('+', '') + else: + change_flag = "" + price_change.replace('+', '') + + price_change = math.floor(float(price_change) * 100)/100.0 + + price_change = change_flag + str(price_change) + + change = change.replace('(', '') + change = change.replace(')', '') + change = change.replace('%', '') + if "+" in change: + change_flag = "+" + change.replace('+', '') + else: + change_flag = "" + change.replace('+', '') + + change = math.floor(float(change) * 100)/100.0 + change = "(" + change_flag + str(change) + "%)" + + + if "+" in change: + sym = "#40ff00" + sym2 = "🟢" + else: + sym = "#ff0000" + sym2 = "🔴" + + + payload = harga + "=" + price_change + "=" + change + "=" + last_update + "=" + dt_string + " GMT+7" + "=" + sym + "=" + sym2 + "=" + key + + + print(payload) + + payload_encoded = base64.b64encode(bytes(payload, 'utf-8')) + + print(payload_encoded.decode('utf-8')) + + response = requests.get('https://api.dev.gabrielkheisa.xyz/stocks/usdidr/index.php?q='+str(payload_encoded.decode('ascii'))) + + browser.quit() + print("Sleep for 1 hour") + time.sleep(60*60) + + except: + print("Error gak jelas, skip") + browser.quit() \ No newline at end of file