From 5f21810bccfc656284029215a47c999d32b94006 Mon Sep 17 00:00:00 2001 From: gabrielkheisa Date: Fri, 4 Nov 2022 23:43:25 +0700 Subject: [PATCH] first --- README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ index.php | 35 +++++++++++++++++++++++++++++++++++ script.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 README.md create mode 100644 index.php create mode 100644 script.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..a03da7d --- /dev/null +++ b/README.md @@ -0,0 +1,52 @@ +

Get weather data from Google Search using Selenium

+

Requirements:

+ +

Trivia:

+ +

Example:

+ + diff --git a/index.php b/index.php new file mode 100644 index 0000000..6ceaec8 --- /dev/null +++ b/index.php @@ -0,0 +1,35 @@ +$pieces[0], "kelembapan"=>$pieces[1], "presipitasi"=>$pieces[2], "angin"=>$pieces[3],"cuaca"=>$pieces[4], "last_update"=>$pieces[5], "server_update"=>$pieces[6]); + +echo json_encode($marks, JSON_PRETTY_PRINT); +} +else { +$txt = base64_decode($q); + +$pieces = explode("=", $txt); + +if(strcmp($pieces[7], $key) == 0) { + $myfile = fopen("cache.txt", "w") or die("Unable to open file!"); + fwrite($myfile, $txt); + fclose($myfile); + echo "Done!"; +} +else { + echo "Key Invalid"; + fclose($myfile); +} +} +?> \ No newline at end of file diff --git a/script.py b/script.py new file mode 100644 index 0000000..1db3304 --- /dev/null +++ b/script.py @@ -0,0 +1,55 @@ +import requests +from selenium import webdriver +from selenium.webdriver.chrome.options import Options +import time +from datetime import datetime +import base64 + +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('--headless') + options.add_argument('--disable-gpu') + browser = webdriver.Chrome(executable_path="/usr/bin/chromedriver", chrome_options=options) + + browser.delete_all_cookies() + browser.get("https://www.google.com/search?q=weather+yogyakarta") + + time.sleep(5) + + + suhu = browser.find_element_by_xpath("//*[@id=\"wob_tm\"]").get_attribute('textContent') + kelembapan = browser.find_element_by_xpath("//*[@id=\"wob_hm\"]").get_attribute('textContent') + presipitasi = browser.find_element_by_xpath("//*[@id=\"wob_pp\"]").get_attribute('textContent') + angin = browser.find_element_by_xpath("//*[@id=\"wob_ws\"]").get_attribute('textContent') + cuaca = browser.find_element_by_xpath("//*[@id=\"wob_dc\"]").get_attribute('textContent') + last_update = browser.find_element_by_xpath("//*[@id=\"wob_dts\"]").get_attribute('textContent') + + + + + payload = suhu + "=" + kelembapan + "=" + presipitasi + "=" + angin + "=" + cuaca + " GMT+7" + "=" + last_update + "=" + dt_string + "=" + key + + + print(payload) + + payload_encoded = base64.b64encode(bytes(payload, 'utf-8')) + + print(payload_encoded.decode('utf-8')) + + response = requests.get('https://api.gabrielkheisa.xyz/weather/yogyakarta/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