import sys
import json
sys.path.insert(0,'./kw_tools/web')
import browser_common


import rpyc
from rpyc.utils.server import ThreadedServer # or ForkingServer

class MyService(rpyc.Service):
    def __init__(self):
        self.jb=browser_common.JBrowser()
        #jb.set_profile_path('/home/jared/.config/google-chrome/Default/')
        self.jb.set_profile_path('"/home/jared/.config/google-chrome/"')

    def exposed_get_url(self,url):
        self.jb.get(url)
        driver=self.jb.get_driver()
        src=driver.page_source
        return json.loads(driver.find_element_by_tag_name('body').text)
#        return src

    def exposed_get_driver(self):
        return self.jb.get_driver()


#        print(src)
#'https://data.similarweb.com/api/v1/data?domain=yahoo.com.tw'
if __name__ == "__main__":
    server = ThreadedServer(MyService, port = 12345)
    server.start()


