File size: 1,380 Bytes
8f94120
720f322
 
 
36d0d44
720f322
 
 
 
 
 
9fca04f
720f322
 
 
 
 
36d0d44
720f322
 
 
 
 
 
 
 
 
 
 
 
 
 
9fca04f
08fa15a
720f322
56afc60
 
 
 
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
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import urllib
#from selenium_webdriver import WebElement
import uuid

driver_type = 'chromedriver'
driver=False

def create_ss(graph,width=1000,height=8000):
    uid=uuid.uuid4()
    code_out=""
    for ea in graph.split("\n"):
        code=ea.strip().strip("\n")
        code_out+=code
    url=f"https://omnibus-mermaid-script.static.hf.space/index.html?mermaid={urllib.parse.quote_plus(code_out)}"
    is_url=True
    wait_time=10000
    if is_url:
        options = webdriver.ChromeOptions()
        options.add_argument('--headless')
        options.add_argument('--no-sandbox')
        options.add_argument('--disable-dev-shm-usage')
        mes='<center>operation success'
        try:
            driver = webdriver.Chrome(options=options)
            driver.get(url)
            html=driver.page_source
            print(html)            
            driver.implicitly_wait(int(wait_time*30))
            driver.set_window_size(int(width), int(height))
            obj = driver.find_element(By.ID, "chart")            
            screenshot = obj.screenshot(f'{uid}-tmp.png')
            return(f'{uid}-tmp.png')  
        except Exception as e:
            print(e)
            return None