Exemplo n.º 1
0
	def CustomizeAtomItem(self, d):
		d = bm_api.APIReader.CustomizeAtomItem(self, d)

		if bm_extract.as_string(d, "geometry.type") == "Point":
			coordinates = bm_extract.as_list(d, "geometry.coordinates")
			if len(coordinates) >= 2:
				bm_api.add_latlon(d, coordinates[0], coordinates[1])

			try: del d["geometry"]
			except: pass

		return	d
Exemplo n.º 2
0
	def CustomizeAtomItem(self, d):
		d = Google.CustomizeAtomItem(self, d)
		
		#
		#	Build a hCard from the data
		#	... should add lat/lon here?
		#
		hd = uf_mfdict.mfdict()
		for k_from, k_to in [
			( "country", "%s.%s.%s" % ( uf_vcard.Work, uf_vcard.ADR, uf_vcard.CountryName, ), ),
			( "streetAddress", "%s.%s.%s" % ( uf_vcard.Work, uf_vcard.ADR, uf_vcard.StreetAddress, ), ),
			( "city", "%s.%s.%s" % ( uf_vcard.Work, uf_vcard.ADR, uf_vcard.Locality, ), ),
			( "region", "%s.%s.%s" % ( uf_vcard.Work, uf_vcard.ADR, uf_vcard.Region, ), ),
			( "staticMapUrl", "%s" % ( uf_vcard.Photo, ), ),
			( "title", uf_vcard.OrganizationName, ),
			( "lat", "%s.%s" % ( uf_vcard.GEO, uf_vcard.Latitude, ), ),
			( "lng", "%s.%s" % ( uf_vcard.GEO, uf_vcard.Longitude, ), ),
		]:
			try:
				value = bm_extract.as_string(d, k_from)
				if value:
					hd[k_to] = value
			except KeyError:
				pass

		for pd in bm_extract.as_list(d, "phoneNumbers"):
			number = bm_extract.as_string(pd, "number")
			if not number:
				continue

			type = bm_extract.as_string(pd, "type")

			if type in [ "main", "" ]:
				hd["%s.%s.%s" % ( uf_vcard.TEL, uf_vcard.Voice, uf_vcard.Work, )] = number
			elif type in [ "fax", "data", ]:
				hd["%s.%s.%s" % ( uf_vcard.TEL, uf_vcard.Fax, uf_vcard.Work, )] = number
			elif type == "mobile":
				hd["%s.%s.%s" % ( uf_vcard.TEL, uf_vcard.Mobile, uf_vcard.Work, )] = number
			else:
				hd["%s.%s.%s" % ( uf_vcard.TEL, uf_vcard.Voice, uf_vcard.Work, )] = number

		if hd:
			d["hcard:hcard"] = hcard.decompose(hd, "hcard")

		#
		#
		#
		try:
			bm_api.add_latlon(d, d.pop("lat"), d.pop("lng"), )
		except KeyError:
			pass

		#
		#	Remove stuff
		#
		for key in [ "country", "streetAddress", "city", "region", "staticMapUrl", "phoneNumbers", ]:
			try:
				del d[key]
			except KeyError:
				pass

		#
		#	The result
		#
		return	d
Exemplo n.º 3
0
	def _ProcessRow(self, rd, uri, rel = None):
		d = {}

		#
		#	Title
		#
		d['title'] = rd['title'] = rd.get('name') or rd.get('nick') or '[No Name]'

		#
		#	Image
		#
		logo = rd.get('image') or rd.get('img')
		if logo:
			rd['logo'] = logo
			d['logo'] = logo

		#
		#	Lat/Lng
		#
		bm_api.add_latlon(d, rd.get('lat'), rd.get('lng'))

		#
		#	Get everything that goes into the hCard
		#
		hd = uf_mfdict.mfdict()
		for k_from, k_to in [
			( "country_name", "%s.%s" % ( uf_vcard.ADR, uf_vcard.CountryName, ), ),
			( "street_address", "%s.%s" % ( uf_vcard.ADR, uf_vcard.StreetAddress, ), ),
			( "extended_address", "%s.%s" % ( uf_vcard.ADR, uf_vcard.ExtendedAddress, ), ),
			( "locality", "%s.%s" % ( uf_vcard.ADR, uf_vcard.Locality, ), ),
			( "region", "%s.%s" % ( uf_vcard.ADR, uf_vcard.Region, ), ),
			( "postal_code", "%s.%s" % ( uf_vcard.ADR, uf_vcard.PostalCode, ), ),
			( "title", uf_vcard.FN, ),
			( "mbox_sha1sum", uf_vcard.UID, ),
			( "phone", "%s.%s" % ( uf_vcard.TEL, uf_vcard.Voice, ), ),
			( "logo", uf_vcard.Logo, ),
			( "lat", "%s.%s" % ( uf_vcard.GEO, uf_vcard.Latitude, ), ),
			( "lng", "%s.%s" % ( uf_vcard.GEO, uf_vcard.Longitude, ), ),
		]:
			try:
				value = bm_extract.as_string(rd, k_from)
				if value:
					if k_from in [ "phone" ]:
						if value.startswith("tel:"):
							value = value[4:]

					hd[k_to] = value

				rd.pop(k_from)
			except KeyError:
				pass

		for key in [ "name", "nick", "photo", "image", "img", ]:
			try: rd.pop(key)
			except KeyError: pass

		if hd:
			uf_vcard.scrub(hd)
			d["hcard:hcard"] = hcard.decompose(hd, "hcard")

		#
		#	Add links
		#
		d["link"] = rd.get('homepage') or rd.get("weblog") or uri

		links = [{
			"rel" : "related",
			"href" : uri,
			"title" : "FOAF source",
		}]
		d["links"] = links

		for html_key in [ "homepage", "weblog", ]:
			try:
				uri = rd.pop(html_key)
				if uri:
					links.append({
						"href" : uri,
						"rel" : "related",
						"type" : "text/html",
						"title" : html_key,
					})
			except KeyError:
				pass

		if uri != self.uri and rel:
			links.append({
				"href" : self.uri,
				"rel" : "xfn",
				"rev" : rel
			})

##		if rel:
##			d["xfn:rel"] = rel

		return	d
Exemplo n.º 4
0
	def CustomizeAtomItem(self, d):
		d = bm_api.APIReader.CustomizeAtomItem(self, d)

		#
		#	Tags become categories
		#
		cats = []

		for tag in bm_extract.as_list(d, "tags.tag"):
			cats.append({
				"term" : tag["name"]
			})

		d["category"] = cats

		#
		#	Geolocation
		#
		bm_api.add_latlon(d, bm_extract.as_string(d, "location.latitude"), bm_extract.as_string(d, "location.longitude"))

		#
		#	hcard
		#
		hd = uf_mfdict.mfdict()
		for k_from, k_to in [
			( "location.country.name", "%s.%s.%s" % ( uf_vcard.Work, uf_vcard.ADR, uf_vcard.CountryName, ), ),
			( "location.streetAddress", "%s.%s.%s" % ( uf_vcard.Work, uf_vcard.ADR, uf_vcard.StreetAddress, ), ),
			( "location.city.name", "%s.%s.%s" % ( uf_vcard.Work, uf_vcard.ADR, uf_vcard.Locality, ), ),
			( "location.regions.province", "%s.%s.%s" % ( uf_vcard.Work, uf_vcard.ADR, uf_vcard.Region, ), ),
			( "location.postal_code", "%s.%s.%s" % ( uf_vcard.Work, uf_vcard.ADR, uf_vcard.PostalCode, ), ),
			( "phone", "%s.%s.%s" % ( uf_vcard.Work, uf_vcard.TEL, uf_vcard.Voice, ), ),
			( "title", uf_vcard.OrganizationName, ),
			( "location.latitude", "%s.%s" % ( uf_vcard.GEO, uf_vcard.Latitude, ), ),
			( "location.longitude", "%s.%s" % ( uf_vcard.GEO, uf_vcard.Longitude, ), ),
		]:
			try:
				value = bm_extract.as_string(d, k_from)
				if value:
					hd[k_to] = value
			except KeyError:
				pass

		if hd:
			d["hcard:hcard"] = hcard.decompose(hd, "hcard")

		#
		#	Links
		#
		try:
			alt = d.pop("short_url")
			if alt:
				d["links"] = [
					{
						"type" : "text/html",
						"rel" : "alternate",
						"href" : alt,
					},
				]
		except KeyError:
			pass

		#
		#	Removables
		#
		for key in [ "tags", "tag_count", "location", "phone", ]:
			try: del d[key]
			except KeyError: pass

		return	d