Tải bản đầy đủ - 0 (trang)
Hack 42. Subscribe to Movie Showtimes

Hack 42. Subscribe to Movie Showtimes

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

internalIDnumber.Butit'sfairlyeasytofindthisnumber,

becauseit'sexposedintheURL.SimplybrowsetoYahoo!

Movies(http://movies.yahoo.com)andenteryourZipCodeinto

theformlabeledGetShowtimesandTickets.

Youshouldseealistoftheatersinyourarea,alongwithmovie

showtimes.UndereachtheatertitleislinkforTheaterInfo.

ClickthelinkandnotetheURLinyourbrowseraddressbar,

whichwillincludethetheaterID.Asyou'dexpect,thefour-to

five-digitnumberfollowingthevariablenamedidintheURLis

thetheaterIDforthattheater.JotdowntheIDsofyourfavorite

theaters,becauseyou'llneedthemtogenerateRSSfeedslater.

OnceyouknowtheinternalIDofaspecifictheater,youcanlink

directlytothetheaterdetailpageonYahoo!Movieswiththe

followingURLformat:





http://movies.yahoo.com/showtimes/theater?id=inserttheate



Thetheaterdetailpagecontainsthetheater'saddressand

phonenumber,alistofservicesavailable,andthecurrent

scheduleofmovies.Forthishack,theonlyrelevantpiecesof

dataarethetheatertitleandthelistofmovies.SomePerlcan

isolatethoseelementsandturnthemintoanRSSfeedyoucan

subscribeto.



2.21.2.TheCode

ThiscodereliesonasinglePerlmodule:XML::RSS::SimpleGenby

SeanBurke.ThismodulemakesiteasytocreateanRSSfeed

withscreenscraping,anditkeepsthetoughworkofformatting

thefeedproperlyinthebackground.

Savethefollowingcodetoafilecalledtheater_rss.pl:





















#!/usr/bin/perl

#theater_rss.pl

#AcceptsaYahoo!MoviestheaterIDandprints

#anRSSfeedofcurrentlyplayingmovies.

#Usage:theater_rss.pl

#

#YoucanfindtheaterIDsatYahoo!Movies

#athttp://movies.yahoo.com/









usestrict;

useXML::RSS::SimpleGen;











#GrabtheincomingtheaterID

my$tid=join('',@ARGV)ordie"Usage:theater_rss.p

my$theater_title="Myfavoritetheater";









#SetthetheaterscheduleURL

my$url="http://acid1.oa.yahoo.com/mbl/mov/tdet?tid=$









#Downloadtheschedulepage

my$content=get_url($url);













#Findthetheatername

if($content=~m!
(.*?)
!sg){



$theater_title=$1;

}













#StarttheRSSFeed

rss_new($url,"$theater_titleSchedule");

rss_language('en');

rss_webmaster('insertyouremailaddress');







rss_daily();











#Settheregularexpressiontofinddata

my$regex='.*?mid=(.*?)">(.*?).*?'

$regex.='(.*?).*?';

















#LoopthroughtheHTML,grabbingelements

while($content=~m!$regex!sg){

#rss_itemacceptsurl,title,description.

my$url="http://movies.yahoo.com/shop?d=hv&cf=info&

rss_item($url,$2,$3);

}











#Warnifnothingwasfound

die"Noitemsinthiscontent?!{{\n$_\n}}\nAborting"

unlessrss_item_count();











#Savetherssfileas.rss

rss_save("$tid.rss");

exit;



ThiscodeacceptsatheaterID,buildstheappropriateYahoo!

MoviesURL,downloadstheHTML,andpicksthroughtheHTML

withsomeregularexpressionstofindtheaterandmovie

information.Thecodeusesthefunctionsthatareapartof

XML::RSS::SimpleGentocreateandsaveanRSSfilebasedonthe

movieinformation.

ThenameoftheRSSfilethisscriptgeneratesisbasedonthe

incomingIDandwillbetheater_ID.rss.Ifyou'drathersavethe

filetoanotherlocation,justappendthepathtothefilename

wherethescriptcallstherss_savefunction.Besurethatthefile

thisscriptcreatesisinalocationthat'saccessibleviatheWeb.



2.21.3.RunningtheHack

YoucanrunthescriptoncebypassinginatheaterIDonthe

commandline,likethis:







perltheater_rss.plinserttheaterID



Buttherealvalueofthescriptisthatyoucanrunitona

regularscheduleonawebservertokeepupwithchangesto

thetheater'sschedule.Onceperdayshouldbeenoughtokeep

upwithchanges,andyoucansetthescripttorunregularly

withWindowsSchedulerortheUnixcroncommand.

OnWindowsservers,youcanfindthescheduleratStart

Settings ControlPanel ScheduledTasks.ClickAdd

ScheduledTaskatthetopofthelisttostartthetaskwizardand

settheprogramtorunlikethis:





C:\perl\bin\perl.exe"C:\path\to\theater_rss.pl



YoumightneedtoadjustthelocationofthePerlexecutable,

dependingonwhereit'sinstalledonyourserver.You'llalso

needtoincludethefullpathtotheater_rss.pl.

OnUnix-basedsystems,youcanrunthescriptonceperdayby

addinganentrylikethefollowingtoyourcrontabfile:





5223***~/theater_rss.plinserttheaterID



Ifyouwanttosubscribetomorethanonetheaterinyourarea,

setupaseparaterecurringtaskforeachtheater,usingits

uniquetheaterID.

Finally,addthenewRSSfeedtoyourfavoritenewsreaderand

you'llfindoutaboutanynewmoviesplayingatthattheater.

Figure2-64showsasubscriptiontotheater8193Carmike

Cinema12inCorvallis,OregoninthelatestversionoftheSafari



browser(whichdoublesnicelyasanRSSnewsreader).



Figure2-64.AtheaterscheduleRSSfeedinSafari



Clicking"Readmore…"orthemovietitleinsome

newsreaderswilltakeyoutothemoviedetailpageatYahoo!

Movies,whereyoucanfindoutmoreaboutthatparticular

movie.Andbysubscribingtoyourfavoritelocaltheaters'

schedules,you'llalwaysbeontopofnewadditionstotheir

lineups.



Hack43.ViewMovieListsonYourCellPhone



Nexttimeyougotothevideostore,takeaYahoo!

Movieslistwithyouonyourcellphone.

Imagineyoufindyourselfinavideostore,searchingforthe

perfectmovieamongthethousandsofchoicesanddrawinga

blank.Eventhoughyoumighthaveamentallistofseveral

moviesyou'vebeenmeaningtosee,italwaysseemsthose

crucialbitsofinformationaren'tavailablewhenyouneedthem.

Ifyouhaveacellphonewithwebaccess,Yahoo!Moviesand

somePerlscriptingcangetyououtofthisjam.

ThishacktakesadvantageoftheListsfeatureatYahoo!Movies

[Hack#41],whichisdesignedtoputmoviestogetherintoa

group.Bycreatingalistofmoviesyou'dliketosee,you'llhave

themoviesinaconvenientformatforscripting.Fromthere,the

hackusessomePerltoconverttheYahoo!Movieslistinto

WirelessMarkupLanguage(WML)thatyoucanviewonyour

phone.



2.22.1.CreatingYourList

Togetstarted,youneedtoturnyourmentallistofmovies

you'dliketoseeintosomethingmoretangible.Browseto

http://movies.yahoo.com/profilesandclickCreateNewList.If

youdon'talreadyhaveaYahoo!ID[Hack#3],you'llneedto

createoneinordertousethemovielistfeature.Choose

"MoviesIWanttoSee"fromthesuggestionslistorcreateyour

owntitle.Nowyou'llhaveablanklistwaitingforsomeentries.

Atthetopofthepage,youshouldseeaformtitledSearch



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



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

Hack 42. Subscribe to Movie Showtimes

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

×