Пример #1
0
def get_car(color, brand, model, num, out_file, out_error):
    """
    For a specific make model and color of car attempt to get 'num' images
    """
    make_p = brand.replace(' ', '+')
    model_p = model.replace(' ', '+')
    query_str = '{0}+{1}+{2}'.format(color, make_p, model_p)

    # query with no usage image rights
    # url = 'https://www.google.co.in/search?q=' + query + '&source=lnms&tbm=isch'

    # return images with appropriate usage rights
    url = 'https://www.google.co.in/search?q=' + query_str + '&tbs=sur:fc&tbm=isch'
    header = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 ' +
                      '(KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36'}
    try:
        # TODO check color of the cars and num
        soup = get_soup(url, header)
        actual_images = []
        # parse all photo urls
        for a in soup.find_all('div', {'class': 'rg_meta'}):
            link, link_type = json.loads(a.text)['ou'], json.loads(a.text)['ity']
            actual_images.append((link, link_type))

        for i, (link, link_type) in enumerate(actual_images[:num]):
            if link_type is not None:
                # write out where to get the image from
                data = format_line(color, brand, model, link, link_type)
                out_file.write(json.dumps(data) + '\n')
    except:
        # spout some error messages when things go poorly
        data = format_line(color, brand, model, link, 'FAIL')
        out_error.write(json.puts(data) + '\n')
Пример #2
0
def getCAR(color, makeIn, modelIn, num, outFile, outError):
    make = makeIn.replace(' ', '+')
    model = modelIn.replace(' ', '+')
    query = '{0}+{1}+{2}'.format(color, make, model)
    # query with no usage rights
    # url = 'https://www.google.co.in/search?q=' + query + '&source=lnms&tbm=isch'

    # return images with appropriate usage rights
    url = 'https://www.google.co.in/search?q=' + query + '&tbs=sur:fc&tbm=isch'
    header = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36'}
    try:
        soup = get_soup(url, header)
        ActualImages = []
        for a in soup.find_all('div', {'class': 'rg_meta'}):
            link, Type = json.loads(a.text)['ou'], json.loads(a.text)['ity']
            ActualImages.append((link, Type))

        for i, (img, Type) in enumerate(ActualImages[:num]):
            if Type is not None:
                # write out where to get the image from
                data = makeLine(color, makeIn, modelIn, img, Type)
                outFile.write(json.dumps(data) + '\n')

    except:
        # spout some error messages when things go poorly
        data = makeLine(color, makeIn, modelIn, img, 'FAIL')
        outError.write(json.puts(data) + '\n')
 def send_addr(self, mine=False):
     now = time()
     if mine:
         peers = [self.host_ip]
     else:
         peers = [(peer.remote_ip, peer.remote_nodeid)
                  for peer in self.factory.peers
                  if peer.peertype == 1 and peer.lastping > now - 240]
     addr = js.puts({'msgtype': 'addr', 'peers': peers})
     self.transport.write(peers + "\n")
Пример #4
0
def hit_websockets(host, data, times):
    url = "ws://{}:8000".format(host)
    ws = websocket.create_connection(url, sslopt={
        "cert_reqs": ssl.CERT_NONE,
        "check_hostname": False})
    payload = json.puts(data)
    for _ in range(NUMBER_TRIES):
        start_time = datetime.datetime.now()
        ws.send(payload)
        ws.result = ws.recv()
        yield datetime.datetime.now() - start_time
 def send_ping(self):
     ping = js.puts({'msgtype': 'ping'})
     print "Pinging", self.remote_nodeid
     self.transport.write(ping + "\n")
Пример #6
0
 def send_hello(self):
   hello = json.puts({ 'nodeid': self.nodeid, 'msgtype': 'hello' })
   self.transport.write(hello + '\n')
Пример #7
0
 def _repr_json_(self):
     """A json object representing the attributes of this object."""
     return json.puts(self._repr_dict_)
Пример #8
0
 def contents(self, contents):
     self._contents = contents
     self.values_json = json.puts(self._contents)
Пример #9
0
 def contents(self, contents):
     self._contents = contents
     self.values_json = json.puts(self._contents)