Tải bản đầy đủ - 0 (trang)
Hack 43. View Movie Lists on Your Cell Phone

Hack 43. View Movie Lists on Your Cell Phone

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

Yahoo!Movies.Typeinthenameofamovieyou'dliketosee.If

youdon'thaveanythinginmind,trytypingBuckarooBanzai.Click

Searchandyoushouldseearesultwiththe1984cultclassic

TheAdventuresofBuckarooBanzai.Clickthe"AddtoMy

Movies"linknexttothetitle,andyou'llseealistofyourmovie

lists.Clickthecheckboxnexttothelistyoujustcreatedand

thenclick"AddtoList."Themoviewillbeonyourlist,andyou

canrepeattheprocessasmanytimesasyouneedtountilyour

movielistisfilledwithfilmsyou'dliketosee,asshownin

Figure2-65.

Onceyourmovielistisreadytogo,youjustneedtojotdown

itsURL.HeadbacktoyourprofilepagebyclickingtheMy

Moviestaborbrowsingto

http://movies.yahoo.com/profiles.Clickthetitleofyourmovie

listandcopytheURLfromyourbrowser'saddressbar.TheURL

shouldlooksomethinglikethis:





http://movies.yahoo.com/mvc/dls?iid=7-2022263&lid=7-150



WiththemovielistURLinhand,you'rereadytobuildthescript

thatwillconvertthatlistintoacellphonefriendlyformat.



Figure2-65.AYahoo!Movieslist



2.22.2.TheCode

Thisscriptneedstorunonapubliclyavailablewebserverthat

canexecutePerlscripts.You'llneedthenonstandardPerl

moduleLWP::Simple,whichwillfetchthemovielistfromYahoo!

Movies.You'llalsoneedHTML::TableExtract,whichwilldothe

toughworkofdeconstructingtheHTMLforyou.

Thisscriptreliesonscreenscrapingtogatherthemoviesina

list,whichmeansit'spickingthroughtheHTMLtofindrelevant

information.ThisalsomeansthatifYahoo!changestheirmovie

listHTML,evenslightly,thisscriptwilllikelyfail.Keepinmind

thatyoumightneedtotinkerwiththescripttokeepupwith

changestoYahoo!Movies.



Tokeepyourfingersfromdoingtoomuchworkwhenyou're

readytobringituponyourphone,you'llwanttokeepthe

nameofthisscriptshort.Savethefollowingcodetoafilecalled

m.cgiandbesuretoincludeyouruniquemovielistURLasthe

valueof$listURLatthetopofthescript:











#!/usr/bin/perl

#m.pl

#ConvertaYahoo!MovieslistintoWMLforcellphones

#Usage:m.cgi







usestrict;









useHTML::TableExtract;

useLWP::Simple;









#SetyourYahoo!MovielistURL

my$listURL="insertyourmovielistURL";









#SetthebasemovieURL

my$movieURL="http://acid1.oa.yahoo.com/mbl/mov/mdet?















#SetthetitlesoftheYahoo!Moviestableyou'repars

#thatifthetitlecontainsHTML,sotoomustthesehe

my@tehs=["#","MovieTitle","User
Grade",







"Avg.User
Grade","Critics<

my$te=HTML::TableExtract->new(headers=>@tehs,keep_h









#FetchtheHTML

my$content=get($listURL);







my($wml,@moviedata);













#Parsethetablethatmatchestheheadersabove.

$te->parse($content);

foreachmy$ts($te->table_states){

foreachmy$r($ts->rows){



























nextif@$r[0]=~/grayText/;#finaltablefoo

my($title,$mid);#parseIDandtitlefrom"M

if(@$r[1]=~m!.*?id=(.*?)">(.*?).*?!gi



$mid=$1;$title=$2;

}













































}

}



my$thisMovie={



title =>$title,



mid=>$mid,



grade=>&clean_text(@$r[2]),



avg



=>&clean_text(@$r[3]),



critics=>&clean_text(@$r[4]),



status=>&clean_text(@$r[5]),



};

push@moviedata,$thisMovie;

























#AssembletheWMLbyloopingthroughthearrayofhash

formy$i(0..scalar(@moviedata)-1){



$wml.="$moviedata[$i]{title}";



$wml.="


$wml.="

\n";



$wml.="Status:$moviedata[$i]{status}<



$wml.="Critics:$moviedata[$i]{critics



$wml.="Users:$moviedata[$i]{avg}\n";



$wml.="

\n";

}









#SendfinalWMLtotheclient

print"Content-Type:text/vnd.wap.wml\n\n";















print"\n";

print"
print"\"http://www.wapforum.org/DTD/wml_1.1.xml\">\n";

print"

print"

MovieWishlist

\n";









print$wml;

print"

\n";





























#ThisfunctionremovesHTML,spaceentities,

#linebreaks,andleading/trailingspacesfromstrings

subclean_text(){



my$text=shift(@_);



$text=~s!<.*?>!!g;



$text=~s! !!g;



$text=~s!\n!!g;



$text=~s!^\s+!!;



$text=~s!\s+$!!;



$text=~s!\s{16}!,!;



return$text;

}



ThisscriptdownloadstheHTMLfromtheURLyousupplyand

picksrelevantinformationfromtheHTML.Whenthescriptruns

intoamovietitle,italsograbstheinternalYahoo!IDforthat

movie.Then,usingthe$movieURLasabase,thescriptassembles

alinktothatmovie'sdetailpageatYahoo!Mobile.Thismeans

thatifyou'reeverbrowsingyourlistonyourphoneandcan't

quiterememberwhatthatparticularmovieisabout,youcan

simplyclickthroughtoYahoo!'smobilesitetogetasummaryof

themovie.

Inadditiontothetitlesinthelist,thescriptincludeswhether

themovieisintheatersoronDVD,thecritics'grade,andthe

averagegradeassignedbyYahoo!users.

Noticethatattheendofthescript,whenit'sprintingoutthe

WML,thecontenttypeissetastext/vnd.wap.wml.Settingthis

contenttypeensuresthatthedeviceviewingthepagewillknow

howtorenderit.Webbrowserswon'tbeabletoviewthepage,

soyoucaneithertestitexclusivelyonyourcellphone,or



temporarilychangethecontenttypetotext/xmlinordertotest

itinawebbrowser.



2.22.3.RunningtheHack

Uploadm.cgitoapubliclyavailablewebserverandbringitup

inyourcellphone'sbrowserasyouwouldanyURL:





http://example.com/m.cgi



You'llhavetokeyintheURLbyhandonyourphone.Butmost

phonebrowserscansetbookmarks,soyoucanaddthistoyour

favoritemobilesitesforone-clickaccessinthefuture.Onyour

phone,youshouldseeyourmovielist,asshowninFigure2-66.



Figure2-66.AYahoo!Movieslistonacellphone



Ofcourse,you'llhavetodotheworkofkeepingyourto-seelist

up-to-date.You'llneedtorevisityourlistfrequentlytoadd

moviesyou'dliketoseeorremovethoseyou'veseen.Withan

activelistandyourcellphoneinyourpocket,you'llneverbe

facedwithdrawingablankasyoubrowsemovies!



Hack44.PlanYourTVViewing



Yahoo!TVcanhelpyouplanwhattowatchandwhento

watchit.

Televisionisabigpartofourlives;accordingtotheBureauof

LaborStatistics,peoplespendabouthalfoftheirleisuretime

watchingTV.Ifyou'veeverstartedalongchannel-surfing

binge,youknowthatyoucanfeelyou'vewastedthatleisure

timebythetimeyou'redone.Eventhoughwenowhave

hundredsofchannelstochoosefrom,itcanstillbehardtofind

somethingtowatch.

Itshouldn'tbeasurprisethatTVGuideisoneofthetop-selling

magazinesinthecountry.Ittakesabitofenergytoreallyfind

whatyou'reinterestedin,andYahoo!TVcanhelpyouplanso

youwon'tbewastingyourtimescanning.TogettoYahoo!TV,

browsetohttp://tv.yahoo.comortypetv!intoanyYahoo!

Searchform.Here'salookatwhatyou'llfindatthesite:



TVListings

EnteryourZipCodeathttp://tv.yahoo.com/grid,andyou'll

findwhatshowsareoneachofyourchannels,whetheryou

havecable,satellite,orrabbitears.Youcanviewshowsby

timeanddate,limitlistingstocertaincategories,orcreate

acustomlineupofyourfavoritechannels.



PicksfromYahoo!Editors



Yahoo!TVeditorsoffertheirtakeonthebestbetsfor

viewing,aswellasbriefsynopsesoftheshowsat

http://tv.yahoo.com/picks.Youcantakealookateditors'

choicesforthatdayormovebackorforwardafewdays.



TVNewsandGossip

Findoutwhat'shappeninginthetelevisionindustryand

whatTVcelebritiesareupto.Youcanevenreadabout

celebritiesattheirworstfromseveraldifferentsupermarket

tabloidsathttp://tv.yahoo.com/entgossip.



NielsenRatings

Findoutwhichshowshadthehighestnumbersofviewers

fortheweek,ascalculatedbyNielsen.You'llfindtheTop20

athttp://tv.yahoo.com/nielsen.



TVShowDatabase

Youcanlookuptelevisionshowstoreadabriefsynopsis,

seephotographsoftheactors,andreviewdescriptionsof

upcomingepisodes.Browsetohttp://tv.yahoo.com/dband

searchalphabeticallyorbygenre.Thedatabasecontains

listingsforshowsfromthelate1980sthroughtoday.



SoapOperaSynopses

Missanepisodeofyourfavoritesoap?Browseto

http://tv.yahoo.com/soapsandyou'llbecaughtuponwho

wassleepingwithwhomandwhethertheiramnesiahas



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

Hack 43. View Movie Lists on Your Cell Phone

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

×