コード例 #1
0
ファイル: cblib.py プロジェクト: tchaymore/prosperime
        sys.stdout.write(entity.name.encode("utf8", "ignore") + " updated\n")

    def get_cb_image(self, entity, url):

        img_url = "http://www.crunchbase.com/" + url
        img_filename = urlparse(img_url).path.split("/")[-1]
        img = None
        try:
            img = urllib2.urlopen(img_url)
        except urllib2.HTTPError, e:
            sys.stdout.write(str(e.code))
        if img:
            logo = Image()
            logo.entity = entity
            logo.source = "crunchbase"
            logo.type = "logo"
            logo.save()
            with open("tmp_img", "wb") as f:
                f.write(img.read())
            with open("tmp_img", "r") as f:
                img_file = File(f)
                logo.logo.save(img_filename, img_file, True)
            os.remove("tmp_img")
        sys.stdout.write("Added image for " + entity.name.encode("utf8", "ignore") + "\n")

    def get_entity_cb_info(self, entity):
        """ fetches full profile of entity from CB """
        cb_url = self.get_cb_url("info", entity.cb_type, entity=entity)
        data = self.get_json(cb_url)
        if data:
            data["cb_type"] = entity.cb_type
コード例 #2
0
ファイル: cbparse.py プロジェクト: tchaymore/prosperime
		self.stdout.write(entity.name.encode("utf8","ignore") + " updated\n")
	
	def getCBImage(self,entity,url):
		
		img_url = "http://www.crunchbase.com/" + url
		img_filename = urlparse(img_url).path.split('/')[-1]
		img = None
		try:
			img = urllib2.urlopen(img_url)
		except urllib2.HTTPError, e:
			self.stdout.write(str(e.code))
		if img:
			logo = Image()
			logo.entity = entity
			logo.source = 'crunchbase'
			logo.type = 'logo'
			logo.save()
			with open('tmp_img','wb') as f:
				f.write(img.read())
			with open('tmp_img','r') as f:
				img_file = File(f)
				logo.logo.save(img_filename,img_file,True)
			os.remove('tmp_img')
		self.stdout.write("Added image for " + entity.name.encode('utf8','ignore') + "\n")

	def getEntityCBInfo(self,entity):
		""" fetches full profile of entity from CB """
		cb_url = self.getCBURL('info',entity.cb_type,entity=entity)
		data = self.getJSON(cb_url)
		if data:
			data['cb_type'] = entity.cb_type