Beispiel #1
0
    microformat.debug = 1

    from optparse import OptionParser

    parser = OptionParser()
    parser.add_option("", "--uri", default="", dest="page_uri", help="The URI of the page being processed")
    parser.add_option(
        "", "--verbose", default=False, action="store_true", dest="verbose", help="print a lot about what is happening"
    )
    parser.add_option(
        "",
        "--scrub",
        default=False,
        action="store_true",
        dest="scrub",
        help="scrub the resulting hCard for nicer/more complete results",
    )

    (options, args) = parser.parse_args()
    Log.verbose = options.verbose

    parser = MicroformatHCard(page_uri=options.page_uri)
    parser.PragmaCLI(args)

    for resultd in parser.Iterate():
        if options.scrub:
            uf_vcard.scrub(resultd)

        pprint.pprint(resultd, width=1)
Beispiel #2
0
				if hasattr(fin, "name"):
					errors.append((fin.name, str(x)))
				else:
					errors.append(('<stdin>', str(x)))

				continue

		list_re = "^(?P<count>\d\d+)-(?P<tag>[^.]+)(?P<remainder>.*)$"
		list_rex = re.compile(list_re)

		mf_count = -1
		for parsed in parser.Iterate():
			mf_count += 1

			if options.microformat in [ "hcard-scrubbed", ]:
				uf_vcard.scrub(parsed)

			print "<h2>%s: %s</h2>" % (
				parsed.get('@uf', '[No uF]'),
				_(parsed.get('@title', '[No Title]')),
			)

			at_index = parsed.get('@index')
			if at_index:
				print " <div id='%s'>" % ( at_index, )
			else:
				print " <div>"

			if type(fin) in types.StringTypes:
				parsed['@uri'] = fin
			elif hasattr(fin, "name"):
Beispiel #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