Tải bản đầy đủ - 0 (trang)
Hack 58. Map Yahoo! Address Book Contacts

Hack 58. Map Yahoo! Address Book Contacts

Tải bản đầy đủ - 0trang

addressesforU.S.contactscanbeusedtoo.You'lllikelyneed

toiteratethiscleanupacoupleoftimes,withfeedbackfromthe

geocodingscript.Exportyourcontactsbyloading

http://address.yahoo.com,selectingImport/Export,and

selectingExportNow!fortheYahoo!CSVformat.



3.9.2.TheCode

yadr2geo.plisaPerlscriptthattakesthenameofyour

downloadedaddressbookandoutputsageocodedRSSfileto

usewithworldkit.GeocodedRSSreferstoanyflavorofRSS

extendedtoincludeitem-levellatitudeandlongitude.More

detailsontheformatcanbefoundat

http://brainoff.com/worldkit/doc/rss.php#basic.

Thisscriptrequirescommonlyinstalledmodules:URI::Escapefor

formattingwebservicerequests,LWP::Simpleformakingthose

requests,andXML::Simpleforparsingtheresponses.



ThisscriptdoesnotuseamoduletoparseCSV,becausemodulessuch

asText::CSVassumethatanewlineindicatesanewrecord,whilein

Yahoo!CSV(andmostflavorsofthisunofficialspec)it'slegaltoinclude

anewlinewithinanentryifthatentryisquoted.CSVisdiscussedin

moredetailat

http://www.creativyst.com/Doc/Articles/CSV/CSV01.htm.



Yahoo!CSVissimple:allentriesareguaranteedtobequoted,

thefirstlinegivesfieldnames,andthere'snoextraneous

whitespace.Soit'sstraight-forwardtoprogramascripttoparse

Yahoo!CSVcharacterbycharacter.ThesubroutinegeTRecord()

takesanopenfilehandleasanargumentandreturnsanarray

containingthenextCSVrecord.



Savethefollowingcodetoafilecalledyadr2geo.pl:







#!/usr/bin/perl-w













usestrict;

useXML::Simpleqw(XMLin);

useLWP::Simpleqw(get);

useURI::Escapeqw(uri_escape);















#Mapyourpersonalcountrynamingconventions

#tocountrycodeslistedathttp://brainoff.com/geocod

#andchangethedefaultcountryifyouwish

my%countrycode=('USA'=>'US');

my$defaultcountry='US';





















print<








Yahoo!AddressBook



http://address.yahoo.com/



MygeocodedYahoo!AddressBook
RSSHEADER







my(%hash,@vals,$arg,$loc,$lat,$lon,$success,$co









#FirstlineofYahoo!CVSiskeys

my@keys=@{getrecord(*STDIN)};











while(!eof(STDIN)){



@vals=@{getrecord(*STDIN)};



@hash{@keys}=@vals;



















$success=0;

undef($loc);

$country=$countrycode{$hash{'HomeCountry'}











#Checkforsufficientinformationtogeocode

















if(length($hash{'HomeCity'})==0



||($countryeq"US"&&length($hash{'HomeStat



printSTDERR"Couldn'tgeocode:\""





.join("\",\"",@vals)."\"\n";



next;

}















#TrygeocodingUSstreetaddress

if($countryeq'US'



&&length($hash{'HomeAddress'})>0){



$arg=$hash{'HomeAddress'}.",".$hash{'Hom





.",".$hash{'HomeState'};















































eval{











};











}



if(!$@&&defined($loc->{"geo:Point"}->{"geo:l



defined($loc->{"geo:Point"}->{"geo:lat"



$success=1;

}



















#Trygeocodingworldcity

if($countryne'US'||!$success){



if($countryne"US"){





$arg=$hash{'HomeCity'}.",".$coun



}else{





$arg=$hash{'HomeCity'}.",".$hash





.",".$country;



#Bepatient,geocoder.usfreeservice

$loc=XMLin(



get("http://geocoder.us/service



.uri_escape($arg))

);



































}

eval{









};























}



if(!$@&&defined($loc->{"geo:Point"}->{"geo:l



defined($loc->{"geo:Point"}->{"geo:lat"



$success=1;

}



















if($success){



print<




$hash{'First'}$hash{'Last'}



$loc->{"geo:Point"}->{"geo:lat"}


$loc->{"geo:Point"}->{"geo:long"}


















ITEM









}







print"
\n";

















#

#"getrecord"returnsthenextrecordasanarrayfrom

#filehandle.Itisasimplestatemachine,thatexpect

#formattedin'Yahoo!CVS'

#

subgetrecord{



$loc=XMLin(



get("http://brainoff.com/geocod



.uri_escape($arg))

);



}else{



printSTDERR"Couldn'tgeocode:\""





.join("\",\"",@vals)."\"\n

}



























































































































































my$fh=shift;

my$c="";

my$st=0;

my@record;

my$entry="";

while(defined($c)){



$c=getc($fh);



if($st==0){





if($ceq"\n"||!$c){





return\@record;





}elsif($ceq"\""){





$st=1;





}else{





die"error:parsingstate:$stc





}



}elsif($st==1){





if($ceq"\""){





$st=2;





}else{





$entry.=$c;





}



}elsif($st==2){





if($ceq"\""){





$entry.="\"";





$st=1;





}elsif($ceq","){





push@record,$entry;





$entry="";





$st=0;





}elsif($ceq"\n"){





push@record,$entry;





return\@record;





}else{





die"error:parsingstate:$stc





}



}

}











}



die"error:prematureendoffile\n";



Themainbodyofthescriptbuildsahashfromthecurrent

record,attemptstogeocodetheaddress,andoutputsanRSS

itemifit'ssuccessful.ForU.S.locationswithfullstreetaddress,

theRESTservicefromhttp://geocoder.usisemployed.It

expectsanaddress,cityname,andstateabbreviation,andit

returnsasmallbitofXMLcontainingalatitude/longitudepairif

it'ssuccessful.Thefreeserviceisratelimited,soyou'llnotice

pausesduringrequests.Fornon-U.S.locationsandfor

unsuccessfulGeocoderrequestsarequestismadetotheREST

interfaceoftheGeocoderathttp://brainoff.com/geocoder,

whichexpectsacity,stateabbreviationforU.S.cities,and

countrycode.

ThecountrycodesareparticulartotheGNS(http://earthinfo.nga.mil/gns/html)databasethatbacksthisservice.Tolook

upthecodes,goto

http://brainoff.com/geocoder/countryselect.phpandselecta

country;aJavaScriptalertwillgiveyouthecode.Youwillneed

tomapthecountrynamesusedinyouraddressbooktothese

codes,byaddingentriesto%countrycodeinthescript.

Ifyouuseanon-EnglishlanguageonYahoo!,youmighthave

differentfieldnamesfromtheonesexpected.Thescriptuses

HomeAddress,HomeCity,HomeState,andHomeCountry.Youmight

needtoexamineyourCSVexportandreplacethesefieldnames

inthecode.Similarly,ifyouwantedtomapworkaddresses,

you'dreplaceHomewithWorkineachofthesefieldnames.

Anothermodificationtotryisaddingaorfield

toeachitem,set,forexample,tothePersonalWebsitefield.



3.9.3.RunningtheHack



WiththescriptandtheYahoo!CSVexportfile(yahoo.csv)in

place,callthescriptlikethis:





perlyadr2geo.plrss.xml



Thefilerss.xmlwillcontaineachoftheentriesfromyour

Yahoo!AddressBook,alongwithitsgeocodedlocation.



3.9.4.PlottingtheAddresses

Thefinalstepistodownloadworldkitfrom

http://brainoff.com/worldkitandinstallitonyourserveror

locally.Loadingtheincludedindex.htmlinyourbrowserdisplays

thedefaultmap.Replacetheincludedrss.xmlwiththeoutputof

yadr2geo.plandreloadthemap.You'llseethelocationsofyour

friendsspreadovertheglobe,asinthegeographically

dispersedmapinFigure3-20.



Figure3-20.Yahoo!AddressBookentriesplotted

onaworldkitmap



Therearemanypossiblecustomizationsdescribedinthe

worldkitdocumentation,fromchangingthemapfromglobalto

cityscale,tochangingtheannotationcolorsaccordingtothe

categoryofeachcontact.

MikelMaron







Hack59.Discuss,Share,andCollaboratewith

Others



UseYahoo!Groupstosetupaspacetoshareinformation

viaemailandontheWeb.

TheWebisredefininghowgroupsofpeoplecanworktogether

toachieveacommongoal.Atonetime,formingcollaborative

relationshipsmeantmeetinginthesamephysicallocation.By

collaboratingonline,peopleacrosstheglobecancometogether

toworkonaproject,exchangeinformation,orsimplychat.A

familythat'sdistributedacrossthecountrycansharephotos

andstories,oralocalclubcanplanmeetingtimes.

Yahoo!Groupsisaspacethatfacilitatesthesekindsof

relationships,andatitsmostbasic,Yahoo!Groupsprovidesan

easywaytocreateamailinglist.Amailinglistissimplyaway

tosendanemailtoanumberofspecifiedemailaddresses.

Somemailinglistsareone-way,meaningthelistownersends

emailtoeveryoneonthelistbutmembersdon'tcommunicate

betweeneachother;thesearecalledannouncementor

distributionlists.Atwo-waylistiscalledadiscussionlistand

allowsanyofitsmemberstosendanemailtothelist;everyone

onthelistwillreceivethemessage.AYahoo!Groupcanhave

eithertypeofmailinglist,butYahoo!Groupsaremostoften

thoughtofasaplacefordiscussion.



3.10.1.GroupFeatures

Inadditiontoitsmailinglist,everyYahoo!Grouphasitsown

groupsite.Herearethefeaturesyou'llfindataYahoo!Groups



site:



Messages

Everymessagesenttothegroupviaemailisarchivedat

thegroupsite,wherememberscansearchthroughpast

messagesorpostnewmessagestothegroup.



Chat

AJava™applicationthatrunsinthebrowserprovidesrealtimechattingformembersthatareatthegroupsiteatthe

sametime.



File,Photo,andLinkSharing

Memberscanuploadfilesandphotostosharewithothers.

Andthere'saspecialsectionofthegroupsiteforsharing

linkstoothersites.



SharedDatabases

Thegroupcanworktogetheronadatabaseofinformation.

Youcanevencreateyourownstructureforthedata.

Prebuiltoptionsincludeasharedphonebook,CDlibrary,

recipes,andcontactlist.



GroupPolls

Youcantakethepulseofthegroupbycreatingamultiple-



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Hack 58. Map Yahoo! Address Book Contacts

Tải bản đầy đủ ngay(0 tr)

×