Ejemplo n.º 1
0
 def go_google(cls, quantity):
     chrome_options = Options()
     chrome_options.add_argument("--headless")
     chrome_options.add_argument("--disable-gpu")
     driver = webdriver.Chrome('chromedriver.exe',
                               chrome_options=chrome_options)
     driver.get(
         'https://www.google.com/search?q=test&oq=test&aqs=chrome..69i57.2306j0j7&sourceid=chrome&ie=UTF-8'
     )
     ratings_dict = {}
     address_dict = get_addresses()
     #count = 0
     for key, val in address_dict.items():
         #if count > 20: break
         if (val[0][3] not in ratings_dict) and (
                 val[0][1] + ' ' + val[0][2]
                 not in [x[0] for _, x in ratings_dict.items()]):
             ratings_dict[val[0][3]] = (
                 val[0][1] + ' ' + val[0][2],
                 tuple(x for x in cls._get_google_ratings(key, driver))
             )  #name: (address, [(rating, link, count)]
             #count+=1
     temp_map = GRatingsMap()
     for key, val in ratings_dict.items():
         if len(val[1]) == 0: continue
         temp_map.add_marker(key,
                             ratings=[x[0] for x in val[1]],
                             links=[x[1] for x in val[1]],
                             counts=[x[2] for x in val[1]],
                             lat_long_list=get_lat_long(val[0]))
     driver.quit()
     temp_map.save_open()
Ejemplo n.º 2
0
    def collect_links(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://www.google.com/search?q=test&oq=test&aqs=chrome..69i57.2306j0j7&sourceid=chrome&ie=UTF-8')
        address_dict = get_addresses()
        yelp_list = []
        for key in address_dict:
            link = self._get_google_link(key, 'yelp')
            print(link)
            if link != 'None' and link not in yelp_list: yelp_list.append(link)

        with open('yelp_links.p', 'wb') as f:
            pickle.dump(yelp_list, f)
        self.driver.quit()
Ejemplo n.º 3
0
 def _get_doctor_links(cls):
     data = get_addresses()
     links_dict = pickle.load(open('healthgrade_links.p', 'rb'))
     #links_dict = {} #{link: (name, address)}
     address_start_check = [x[1] for _, x in links_dict.items()]
     for _, val in data.items():
         for name_list in val:
             address = name_list[1]+' '+name_list[2]
             if address in address_start_check: continue
             full_name = name_list[0].lower().capitalize()
             city_state = name_list[2]
             #print(int(ind/len(res)*100), '%')
             name, link = cls._search_google_links(full_name, city_state)
             if link not in links_dict and link != '':
                 print(len(links_dict))
                 links_dict[link] = (name, address)
         #print(len(links_dict))
         if len(links_dict) > 75: break
     return links_dict
    def __init__(self, things, port=80, hostname=None, ssl_options=None,
                 additional_routes=None):
        """
        Initialize the WebThingServer.

        For documentation on the additional route format, see:
        https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/microWebSrv

        things -- list of Things managed by this server
        port -- port to listen on (defaults to 80)
        hostname -- Optional host name, i.e. mything.com
        ssl_options -- dict of SSL options to pass to the tornado server
        additional_routes -- list of additional routes to add to the server
        """
        self.ssl_suffix = '' if ssl_options is None else 's'

        self.things = things
        self.name = things.get_name()
        self.port = port
        self.hostname = hostname

        station = network.WLAN()
        mac = station.config('mac')
        self.system_hostname = 'esp32-upy-{:02x}{:02x}{:02x}'.format(
          mac[3], mac[4], mac[5])

        self.hosts = [
            'localhost',
            'localhost:{}'.format(self.port),
            '{}.local'.format(self.system_hostname),
            '{}.local:{}'.format(self.system_hostname, self.port),
        ]

        for address in get_addresses():
            self.hosts.extend([
                address,
                '{}:{}'.format(address, self.port),
            ])

        if self.hostname is not None:
            self.hostname = self.hostname.lower()
            self.hosts.extend([
                self.hostname,
                '{}:{}'.format(self.hostname, self.port),
            ])

        if isinstance(self.things, MultipleThings):
            log.info('Registering multiple things')
            for idx, thing in enumerate(self.things.get_things()):
                thing.set_href_prefix('/{}'.format(idx))

            handlers = [
                (
                    '/',
                    'GET',
                    self.thingsGetHandler
                ),
                (
                    '/<thing_id>',
                    'GET',
                    self.thingGetHandler
                ),
                (
                    '/<thing_id>/properties',
                    'GET',
                    self.propertiesGetHandler
                ),
                (
                    '/<thing_id>/properties/<property_name>',
                    'GET',
                    self.propertyGetHandler
                ),
                (
                    '/<thing_id>/properties/<property_name>',
                    'PUT',
                    self.propertyPutHandler
                ),
            ]
        else:
            log.info('Registering a single thing')
            handlers = [
                (
                    '/',
                    'GET',
                    self.thingGetHandler
                ),
                (
                    '/properties',
                    'GET',
                    self.propertiesGetHandler
                ),
                (
                    '/properties/<property_name>',
                    'GET',
                    self.propertyGetHandler
                ),
                (
                    '/properties/<property_name>',
                    'PUT',
                    self.propertyPutHandler
                ),
            ]

        if isinstance(additional_routes, list):
            handlers = additional_routes + handlers

        self.server = MicroWebSrv(webPath='/flash/www',
                                  routeHandlers=handlers,
                                  port=port)
        self.server.MaxWebSocketRecvLen = 256
        self.WebSocketThreaded = ws_run_in_thread
        self.server.WebSocketStackSize = 8 * 1024
        self.server.AcceptWebSocketCallback = self._acceptWebSocketCallback
Ejemplo n.º 5
0
    def __init__(self, things, port=80, hostname=None, ssl_options=None,
                 additional_routes=None, base_path='',
                 disable_host_validation=False):
        """
        Initialize the WebThingServer.

        For documentation on the additional route format, see:
        https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/microWebSrv

        things -- things managed by this server -- should be of type
                  SingleThing or MultipleThings
        port -- port to listen on (defaults to 80)
        hostname -- Optional host name, i.e. mything.com
        ssl_options -- dict of SSL options to pass to the tornado server
        additional_routes -- list of additional routes to add to the server
        base_path -- base URL path to use, rather than '/'
        disable_host_validation -- whether or not to disable host validation --
                                   note that this can lead to DNS rebinding
                                   attacks
        """
        self.ssl_suffix = '' if ssl_options is None else 's'

        self.things = things
        self.name = things.get_name()
        self.port = port
        self.hostname = hostname
        self.base_path = base_path.rstrip('/')
        self.disable_host_validation = disable_host_validation

        station = network.WLAN()
        mac = station.config('mac')
        self.system_hostname = 'esp32-upy-{:02x}{:02x}{:02x}'.format(
          mac[3], mac[4], mac[5])

        self.hosts = [
            'localhost',
            'localhost:{}'.format(self.port),
            '{}.local'.format(self.system_hostname),
            '{}.local:{}'.format(self.system_hostname, self.port),
        ]

        for address in get_addresses():
            self.hosts.extend([
                address,
                '{}:{}'.format(address, self.port),
            ])

        if self.hostname is not None:
            self.hostname = self.hostname.lower()
            self.hosts.extend([
                self.hostname,
                '{}:{}'.format(self.hostname, self.port),
            ])

        if isinstance(self.things, MultipleThings):
            for idx, thing in enumerate(self.things.get_things()):
                thing.set_href_prefix('{}/{}'.format(self.base_path, idx))

            handlers = [
                [
                    '/.*',
                    'OPTIONS',
                    self.optionsHandler
                ],
                [
                    '/',
                    'GET',
                    self.thingsGetHandler
                ],
                [
                    '/<thing_id>',
                    'GET',
                    self.thingGetHandler
                ],
                [
                    '/<thing_id>/properties',
                    'GET',
                    self.propertiesGetHandler
                ],
                [
                    '/<thing_id>/properties/<property_name>',
                    'GET',
                    self.propertyGetHandler
                ],
                [
                    '/<thing_id>/properties/<property_name>',
                    'PUT',
                    self.propertyPutHandler
                ],
            ]
        else:
            self.things.get_thing().set_href_prefix(self.base_path)
            handlers = [
                [
                    '/.*',
                    'OPTIONS',
                    self.optionsHandler
                ],
                [
                    '/',
                    'GET',
                    self.thingGetHandler
                ],
                [
                    '/properties',
                    'GET',
                    self.propertiesGetHandler
                ],
                [
                    '/properties/<property_name>',
                    'GET',
                    self.propertyGetHandler
                ],
                [
                    '/properties/<property_name>',
                    'PUT',
                    self.propertyPutHandler
                ],
            ]

        if isinstance(additional_routes, list):
            handlers = additional_routes + handlers

        if self.base_path:
            for h in handlers:
                h[0] = self.base_path + h[0]

        self.server = MicroWebSrv(webPath='/flash/www',
                                  routeHandlers=handlers,
                                  port=port)
        self.server.MaxWebSocketRecvLen = 256
        self.WebSocketThreaded = ws_run_in_thread
        self.server.WebSocketStackSize = 8 * 1024
        self.server.AcceptWebSocketCallback = self._acceptWebSocketCallback
Ejemplo n.º 6
0
    def __init__(
        self,
        thing: Thing,
        port: int = 80,
        hostname: str = None,
        ssl_options=None,
        additional_routes=None,
    ):
        """
        Initialize the WebThingServer.

        things -- list of Things managed by this server
        port -- port to listen on (defaults to 80)
        hostname -- Optional host name, i.e. mything.com
        ssl_options -- dict of SSL options to pass to the tornado server
        additional_routes -- list of additional routes to add to the server
        """
        self.ssl_suffix = "" if ssl_options is None else "s"

        self.thing = thing
        self.name = thing.title
        self.port = port
        self.hostname = hostname

        station = network.WLAN()
        mac = station.config("mac")
        self.system_hostname = "esp32-upy-{:02x}{:02x}{:02x}".format(
            mac[3], mac[4], mac[5])

        self.hosts = [
            "localhost",
            "localhost:{}".format(self.port),
            "{}.local".format(self.system_hostname),
            "{}.local:{}".format(self.system_hostname, self.port),
        ]

        for address in get_addresses():
            self.hosts.extend([
                address,
                "{}:{}".format(address, self.port),
            ])

        if self.hostname is not None:
            self.hostname = self.hostname.lower()
            self.hosts.extend([
                self.hostname,
                "{}:{}".format(self.hostname, self.port),
            ])

        log.info("Registering a single thing")
        handlers = [
            ("/.*", "OPTIONS", self.optionsHandler),
            ("/", "GET", self.thingGetHandler),
            ("/properties", "GET", self.propertiesGetHandler),
            ("/properties/<property_name>", "GET", self.propertyGetHandler),
            ("/properties/<property_name>", "PUT", self.propertyPutHandler),
        ]

        if isinstance(additional_routes, list):
            handlers = additional_routes + handlers

        self.server = MicroWebSrv2()
        self.server.SetEmbeddedConfig()
        self.server.BindAddress = ("0.0.0.0", self.port)

        for handler in handlers:
            print((handler[2], handler[1], handler[0]))
            RegisterRoute(handler[2], handler[1], handler[0])

        wsMod = self.server.LoadModule("WebSockets")
        wsMod.OnWebSocketAccepted = self._OnWebSocketAcceptedCallback