From 0412e812d30792908af2cc218db7a3ed330c629c Mon Sep 17 00:00:00 2001 From: Raymond Lin Date: Thu, 9 Mar 2017 23:34:37 -0500 Subject: [PATCH 1/4] Updates. --- app.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 78c7b8f..10e99e1 100644 --- a/app.py +++ b/app.py @@ -18,12 +18,14 @@ def eval(cmd, input=None): return shuttle.eval(cmd['args']) elif cmd['service'] == 'W': ## Weather return weather.eval(input) + elif cmd['service'] == 'M': + return movies.eval(input) else: return "ERROR 42: service not recognized" ## list of services that need the user's input to work, not a command def needsInput(cmd): - return cmd['service'] in ['W'] + return cmd['service'] in ['W'] or cmd['service'] in ['M'] def special(incoming): body = '' @@ -33,6 +35,8 @@ def special(incoming): body = laundry.special elif incoming.upper() == "WEATHER": body = weather.special + elif incoming.upper() == "MOVIES": + body = movies.special elif incoming.upper() == "DEMO": ## welcome/instructions body = 'Thanks for using Harvard Now!\n' From 734130e59b8056ca49ceff02bb9a5a37c500b3e6 Mon Sep 17 00:00:00 2001 From: Larry Gu Date: Thu, 9 Mar 2017 23:58:31 -0500 Subject: [PATCH 2/4] a --- .DS_Store | Bin 0 -> 6148 bytes services/.DS_Store | Bin 0 -> 8196 bytes services/movies/__init__.py | 0 services/movies/__init__.pyc | Bin 0 -> 115 bytes services/movies/movies.py | 50 ++++++++++++++++++++++++++++++++++ services/movies/movies.pyc | Bin 0 -> 1977 bytes ~$Scraping and API Calls.pptx | Bin 0 -> 165 bytes 7 files changed, 50 insertions(+) create mode 100644 .DS_Store create mode 100644 services/.DS_Store create mode 100644 services/movies/__init__.py create mode 100644 services/movies/__init__.pyc create mode 100644 services/movies/movies.py create mode 100644 services/movies/movies.pyc create mode 100644 ~$Scraping and API Calls.pptx diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..fa3034d001a27608dc1cfffc28b0e7517053a19e GIT binary patch literal 6148 zcmeHK%}(Pm5VlK!v|NG!3286BuGB;Mt+<849+4_#1ws^+ghbR*lvGLD3RRVI*wa47 z?gINBtKE0lN7>uX*e+^SxFSF^*7zHbXYAy2WXFs#-s}fkjMLn0yf?y z5QRaXI#w;L>RpPs+}&n8ie7$64T6$89{>>fAamCV^X_i}jF3eYQ16pSl0KBj=7j$(+# eqj(ck3HSvXfR4dJBX~gQM?ld)6*2Il4EzV|+h%A0 literal 0 HcmV?d00001 diff --git a/services/.DS_Store b/services/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..6e38820117b7aadaddbf7f4f11f849b54bf62624 GIT binary patch literal 8196 zcmeI1%Wl&^6o${Vp>bOlMt~HFjkicyB$N`d3n46#A{n(p6a~As>X95z>Y5g-EVKmecFvRD^9_jQz7B0vQG zO9Jx#;9!;7HagR)ZXMXD6ack?!>V8(^8n>>jJA!=v??pEsj~-WtjwesOxrQ;$mytU zqcg4A4ousDnQvw$Lt*OM(dVe?z}i}=B?3fXm4M9Ms}O?+1tg34yYMmc!ym>x%Nvca zY-6)>Wvgm!@9fIMzP9t+jl|f^y}ZaeUiwUZ;z8(}e$UIJdH;zJ@p<3#4|q84+czGH zB=>j{rVG}iL!Ja;+z~|*WJj)E?~n(1)VFW;(r|>C^ ze%-lqzd5ZtlUA!yckb@pn@;VQmUZj){)5L)htpTD-<-XD_x{7jPnrZXcN4f?BJ+6_ z%g9ZWSR^MHk*+NmfPfKj2qDw2JP6qml=!6S9*e zrSV~O`TC^`R)q{A+~qkQF@$u<0Q4?j!mPQnaQce`sJyK mB^jwj`tk9Zd6^~g@p=W7B^*EnHo5sJr8%i~AY+Pwm;nIhm=wkU literal 0 HcmV?d00001 diff --git a/services/movies/movies.py b/services/movies/movies.py new file mode 100644 index 0000000..11e642c --- /dev/null +++ b/services/movies/movies.py @@ -0,0 +1,50 @@ +import urllib2, urllib +import re +from bs4 import BeautifulSoup + +############################# +## Weather Function ## +############################# + +def getWeatherData(input): + url = 'http://www.google.com/search?q=' + url += '+'.join(input) + hdr = {'User-Agent': 'Chrome'} + req = urllib2.Request(url,headers=hdr) + website = urllib2.urlopen(req) + soup = BeautifulSoup(website.read(), 'html.parser') + + try: + card = soup.find(id='ires').find_all(class_='g')[0] + + label = card.h3.text + '\n' if card.h3 is not None else '' + + overview = card.img.attrs['title'] + '\n' if card.img is not None and card.img.has_attr('title') else '' + tempInFarenheit = 'Temp: ' + card.find_all(class_='wob_t')[0].text.encode('unicode-escape').replace(r'\xb0','') + '\n' if len(card.find_all(class_='wob_t')) > 0 else '' + humidity = card.find_all(text=re.compile('Humidity'))[0] + '\n' if len(card.find_all(text=re.compile('Humidity'))) > 0 else '' + wind = card.find_all(text=re.compile('Wind'))[0].parent.text if len(card.find_all(text=re.compile('Wind'))) > 0 else '' + + body = label + body += overview + body += tempInFarenheit + body += humidity + body += wind + except Exception, e: + print str(e) + return "Could not find weather data. Are you sure you gave a proper city name?" + + return body + +############################ +## Top-Level ## +############################ + +def makeSpecial(): + s = 'To get the weather for a particular city, use the format \'weather city\'.' + return s + +## return proper format to use for getting weather +special = makeSpecial() + +def eval(input): + return getWeatherData(input) diff --git a/services/movies/movies.pyc b/services/movies/movies.pyc new file mode 100644 index 0000000000000000000000000000000000000000..62a8a6111c8497e87c92e57b875add152dce9beb GIT binary patch literal 1977 zcmb7FOK%)S5U!qmcprWxjxiBZ7(gg1;j9BefFd9SLliC++6^+YB3ZrD?cE;F%iTR* zTiU%44%|8LHxNIE184610H~_*8iSF5+3oIcs_R|VJ+07(tfIvmtNs2Y5W0u4}g22IdSc!889Pz|QENa?WGL<8n` zeD-<*p=@1mqkQmqBd~s;&6A+JCvOZn4uE^!~ipZ7Xsc#l0j09tiCr7 zzzc{2=4!w!Ko&8tF|h`-8cEFS;Oj7}L);+m6#5vzyaDGwidh5VCMfi`gbA#$8a$u$7@pD==ST>N3PDpjOGg{bfN} zCCcq9ye;r+yjdAuBf}_xwvX#zKM-pD@4Ms{+Kbmg-5}-h4Ny19F2=NVMRWU#<_+*S zA>IIWizNPH;yXbRq4jG#Wax^%&Ohnfyr%ExYx)*E?D#D}-!Jmih1n9!mtltg7M8U_ z?Mu|TL|sPvSqp>^>LnO{jWWaD7WT=Wdll!2_r=4Vo#}MiALscv(fue-cbt|snmjuB z2s;GeEl*vzJF$7HT?gS;PTPBr$2#+ViF9bGv~{ja*r!RqkQO;Sof4z4fpD?fv6d*2 z&K+WTE2;dTL>Be4-gm^U198BY;|~^m!T^!z*wH@ zP=|%bZ?WxgIJf^4{EBHnBgp5tJsj4)&TBRvvgsM5p)p-wB;K{v$2z%+&MB43K zlx(r~i*rvsG1h*+D&}WcOUk6{;{>89HpGh96l-ELsEOBurf3Im2HWC5d?^O_*5Ti( zsEI}pu>?us*u}w}PWLEZpTiz?^PYQ(^RqlelOcA`WfL9cmYPLcZ=y1hRl{tDrPIuY z+o|;7-9^t)JKgP9VUj&Q5AJ`2O%0LCV?8W%WMs09uY49L=7==XAdfF2!4p<}1%~_~ zsXiwI$`ij2UL%C#KjxiErB7w@09QwbK=df{1Fkl8R&^={cMx*_jNH3?64>V8K9TA2 qa8(3@w-NtopV7Y-zlAa%rnxE;{V@gXmT`JnEQ|GK`;B&^9sB`67Mc_Q literal 0 HcmV?d00001 diff --git a/~$Scraping and API Calls.pptx b/~$Scraping and API Calls.pptx new file mode 100644 index 0000000000000000000000000000000000000000..ad5f3c4b19056e69e6f107d566c08d0c905317f1 GIT binary patch literal 165 pcmd;dFV#`-Nh~U=WKbXha5A_vlrrcrC@}aiBr+5MAy7ZfAOQc)5mx{J literal 0 HcmV?d00001 From fee8a32ff0d70b06867c79ccee65e2bcce4957a0 Mon Sep 17 00:00:00 2001 From: Larry Gu Date: Fri, 10 Mar 2017 00:44:14 -0500 Subject: [PATCH 3/4] a --- services/movies/movies.py | 35 ++++++++++++++-------------------- services/weather/weather.py | 3 ++- ~$Scraping and API Calls.pptx | Bin 165 -> 0 bytes 3 files changed, 16 insertions(+), 22 deletions(-) delete mode 100644 ~$Scraping and API Calls.pptx diff --git a/services/movies/movies.py b/services/movies/movies.py index 11e642c..74c6136 100644 --- a/services/movies/movies.py +++ b/services/movies/movies.py @@ -6,32 +6,23 @@ ## Weather Function ## ############################# -def getWeatherData(input): - url = 'http://www.google.com/search?q=' - url += '+'.join(input) +def getMovieData(input): + url = 'http://www.google.com/search?q=movies' + url += '+'+input hdr = {'User-Agent': 'Chrome'} req = urllib2.Request(url,headers=hdr) website = urllib2.urlopen(req) soup = BeautifulSoup(website.read(), 'html.parser') - + try: - card = soup.find(id='ires').find_all(class_='g')[0] - - label = card.h3.text + '\n' if card.h3 is not None else '' - - overview = card.img.attrs['title'] + '\n' if card.img is not None and card.img.has_attr('title') else '' - tempInFarenheit = 'Temp: ' + card.find_all(class_='wob_t')[0].text.encode('unicode-escape').replace(r'\xb0','') + '\n' if len(card.find_all(class_='wob_t')) > 0 else '' - humidity = card.find_all(text=re.compile('Humidity'))[0] + '\n' if len(card.find_all(text=re.compile('Humidity'))) > 0 else '' - wind = card.find_all(text=re.compile('Wind'))[0].parent.text if len(card.find_all(text=re.compile('Wind'))) > 0 else '' - - body = label - body += overview - body += tempInFarenheit - body += humidity - body += wind + card = soup.find_all(class_ = 'fl _yxj') + print card + body = "" + for i in card: + body += i.contents[0] + "\n" except Exception, e: print str(e) - return "Could not find weather data. Are you sure you gave a proper city name?" + return "Could not find movies data. Are you sure you gave a proper zipcode?" return body @@ -40,11 +31,13 @@ def getWeatherData(input): ############################ def makeSpecial(): - s = 'To get the weather for a particular city, use the format \'weather city\'.' + s = 'To get the movies for a particular zipcode, use the format \'movies zipcode\'.' return s ## return proper format to use for getting weather special = makeSpecial() def eval(input): - return getWeatherData(input) + return getMovieData(input) + +print getMovieData("75008") diff --git a/services/weather/weather.py b/services/weather/weather.py index 11e642c..878c7b1 100644 --- a/services/weather/weather.py +++ b/services/weather/weather.py @@ -32,7 +32,6 @@ def getWeatherData(input): except Exception, e: print str(e) return "Could not find weather data. Are you sure you gave a proper city name?" - return body ############################ @@ -48,3 +47,5 @@ def makeSpecial(): def eval(input): return getWeatherData(input) + +print eval("Boston") diff --git a/~$Scraping and API Calls.pptx b/~$Scraping and API Calls.pptx deleted file mode 100644 index ad5f3c4b19056e69e6f107d566c08d0c905317f1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 165 pcmd;dFV#`-Nh~U=WKbXha5A_vlrrcrC@}aiBr+5MAy7ZfAOQc)5mx{J From e21a49bffb3d91ca58495fb3ef6681a82f9274d6 Mon Sep 17 00:00:00 2001 From: Raymond Lin Date: Fri, 10 Mar 2017 00:48:59 -0500 Subject: [PATCH 4/4] Done? --- .DS_Store | Bin 6148 -> 6148 bytes services/.DS_Store | Bin 8196 -> 8196 bytes services/movies/movies.py | 5 +---- services/weather/weather.py | 1 - 4 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.DS_Store b/.DS_Store index fa3034d001a27608dc1cfffc28b0e7517053a19e..a6711fb10713006875631612ffcc4d192443aaad 100644 GIT binary patch delta 426 zcmZoMXfc=|#>B!ku~2NHo}wr#0|Nsi1A_oVaY0f}eiD#(JgH!FAoFr&J&+VLLncEm zLwZswRO{h_5lGS&^chh52az$ z3?KvQp0ePgyqx^Jbf5@GH3vg6Ln=cNLmAMulckviB!GSxKu01wCmHCl;*{d#oTU8x q9FR}IlACpz|1fT5=iui6#so05zcWwf7jfhO`h^LkW^;td8fE|=A6IVx delta 259 zcmZoMXfc=|#>B)qu~2NHo}wrd0|Nsi1A_nqLncEqLn=dYQh9N~#=_-{lMO^zCNr_h z$oxzy$jK}&F)+Bv$i&RT%Er#Y$;AzV0)kwVEm`DQ0uoCyCI_(C*T)2Brlck%7KLY~ zlw`yUhz1m;mSv`v2PEdDhGiCKCS~SimQ-?Zf?&LWM0K^Xxv7qVk)>g+jzYD$xq*&? ziLqI2tw0M0hqR`tqi3pcNJphS9qExML8T^i;d0Bqphyj>v_GW z-q*=gRg*F(XT>NnT|7?V3qghNJ^+9zG+$Q)D?#2~ANmUD(#q5_9kU9bOlMt~HFjkicyB$N`d3n46#A{n(p6a~As>X95z>Y5g-EVKmecFvRD^9_jQz7B0vQG zO9Jx#;9!;7HagR)ZXMXD6ack?!>V8(^8n>>jJA!=v??pEsj~-WtjwesOxrQ;$mytU zqcg4A4ousDnQvw$Lt*OM(dVe?z}i}=B?3fXm4M9Ms}O?+1tg34yYMmc!ym>x%Nvca zY-6)>Wvgm!@9fIMzP9t+jl|f^y}ZaeUiwUZ;z8(}e$UIJdH;zJ@p<3#4|q84+czGH zB=>j{rVG}iL!Ja;+z~|*WJj)E?~n(1)VFW;(r|>C^ ze%-lqzd5ZtlUA!yckb@pn@;VQmUZj){)5L)htpTD-<-XD_x{7jPnrZXcN4f?BJ+6_ z%g9ZWSR^MHk*+NmfPfKj2qDw2JP6qml=!6S9*e zrSV~O`TC^`R)q{A+~qkQF@$u<0Q4?j!m