Skip to content

Instantly share code, notes, and snippets.

@stevedep
Last active April 3, 2023 07:59
Show Gist options
  • Save stevedep/74f989fc884d6d1fdbbefd6d52771a52 to your computer and use it in GitHub Desktop.
Save stevedep/74f989fc884d6d1fdbbefd6d52771a52 to your computer and use it in GitHub Desktop.
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from datetime import datetime
from pyIndego import IndegoClient
from svglib.svglib import svg2rlg
from reportlab.graphics import renderPM
import xml.etree.ElementTree as ET
ET.register_namespace("","http://www.w3.org/2000/svg")
def create_svg(x,y):
indego.download_map(filename='map.svg')
tree = ET.parse('map.svg')
root = tree.getroot()
new = ET.SubElement(root, 'circle')
new.attrib["cx"] = str(x)
new.attrib["cy"] = str(y)
new.attrib["r"] = "50"
new.attrib["fill"] = "red"
tree.write("filename.svg")
drawing = svg2rlg('filename.svg')
renderPM.drawToFile(drawing, 'filename.png', fmt='PNG')
def send_message(msg):
path = "/usr/lib/chromium-browser/chromedriver"
website = "https://web.whatsapp.com/"
options=Options()
options.add_argument('--headless')
options.add_argument('-profile')
options.add_argument('/root/.mozilla/firefox/73lsc6ua.python') #je voert met sudo uit, dus..
driver = webdriver.Firefox(options=options)
driver.implicitly_wait(400)
driver.get(website)
try: #catches non connection to internet of WA
searchbar = WebDriverWait(driver,40).until(EC.presence_of_element_located((By.XPATH,"//span[@title='testing']")))
except:
driver.save_screenshot('ss.png')
driver.quit()
print("fail")
group = driver.find_element(By.XPATH, "//span[@title='Henri']")
group.click()
group = driver.find_element(By.XPATH, "//span[@title='testing']")
group.click()
txtbox = driver.find_element(By.XPATH, '/html/body/div[1]/div/div/div[4]/div/footer/div[1]/div/span[2]/div/div[2]/div[1]/div/div[1]')
time.sleep(2)
txtbox.click()
time.sleep(2)
for element in msg:
txtbox.send_keys(element)
time.sleep(2)
attach = driver.find_elements(By.XPATH, "//*[@id='main']/footer/div[1]/div/span[2]/div/div[1]/div[2]/div/div")
attach[0].click()
time.sleep(2)
f = driver.find_elements(By.CSS_SELECTOR, "input[type='file']")
fl = f[0]
fl.send_keys("/home/odroid/Documents/Scraping/filename.png")
time.sleep(8)
btn = driver.find_element(By.CSS_SELECTOR, "div[aria-label='Send']")
btn.click()
time.sleep(8)
driver.save_screenshot('na.png')
driver.close()
driver.quit()
MOWER_STATE_DESCRIPTION_DETAIL = {
0: "Reading status",
101: "Mower lifted",
257: "Charging",
258: "Docked",
259: "Docked - Software update",
260: "Charging",
261: "Docked",
262: "Docked - Loading map",
263: "Docked - Saving map",
266: "Docked - Leaving dock",
512: "Mowing - Leaving dock",
513: "Mowing",
514: "Mowing - Relocalising",
515: "Mowing - Loading map",
516: "Mowing - Learning lawn",
517: "Mowing - Paused",
518: "Border cut",
519: "Idle in lawn",
520: "Mowing - Learning lawn paused",
521: "Border cut",
523: "Mowing - Spot mowing",
524: "Mowing - Random",
525: "Mowing - Random complete",
768: "Returning to Dock",
769: "Returning to Dock",
770: "Returning to Dock",
771: "Returning to Dock - Battery low",
772: "Returning to dock - Calendar timeslot ended",
773: "Returning to dock - Battery temp range",
774: "Returning to dock - requested by user/app",
775: "Returning to dock - Lawn complete",
776: "Returning to dock - Relocalising",
1005: "Connection to dockingstation failed",
1025: "Diagnostic mode",
1026: "End of life",
1027: "Service Requesting Status",
1038: "Mower immobilized",
1281: "Software update",
1537: "Stuck on lawn, help needed",
64513: "Sleeping",
99999: "Offline",
}
indego = IndegoClient(username='', password='', serial='')
indego.start()
indego.login()
indego.update_state()
indego.state
#fix met negatieve waarden
status = 0
while (True):
try:
indego.update_state(force=True)
st = indego.state.state
x = indego.state.svg_xPos
y = indego.state.svg_yPos
except:
print('fout indego')
if st != status:
create_svg(x,y)
send_message("De maaier is nu " + MOWER_STATE_DESCRIPTION_DETAIL[st])
status = st
#print(co2)
time.sleep(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment