Permalink
Browse files

First commit

  • Loading branch information...
0 parents commit 97c43e42e49bc741798ccf2f60ee97c6586575ac ajotwani committed Jun 21, 2012
103 README.md
@@ -0,0 +1,103 @@
+# What is "AlfredFlik"?
+
+"AlfredFlik" is an [Alfred](http://www.alfredapp.com/) extension built using Python, that finds similar movies using Rovi's Metadata and Search API and then allow you to text them to a phone number using Twilio's API.
+
+## What is Alfred?
+[Alfred](http://alfredapp.com) is an award-winning productivity application for Mac OS X, which aims to save you time in searching your local computer and the web. Whether it's maps, Amazon, eBay, Wikipedia, you can feed your web addiction quicker than ever.
+
+The real power of Alfred lies in it's [powerpack](http://www.alfredapp.com/powerpack/) that allows you to create your very own Terminal shell scripts, AppleScripts, workflows, search filters and file groups to extend Alfred.
+
+## Summary
+
+Say, you're a fan of Arnold and you watched Terminator last week with your friend. You can't get enough of the action and you wanna watch more movies along the same lines. You can now use Alfred-Flik - a handy extension that lets you specify a movie name and the name/phone number of the person you'd like to text the list of movies to. Alfred-Flik then queries Rovi's Metadata and Search API, pulls up a list of similar movies. It also finds the ratings of these movies via Rotten Tomatoes. Finally it sends it as an SMS to the phone number you provide using Twilio.
+
+## Requirements
+
+1. [Alfred](http://www.alfredapp.com/) + [Alfred Powerpack](http://www.alfredapp.com/powerpack/)
+2. [Rovi API Key](http://developer.rovicorp.com)
+3. [Twilio API Key](http://twilio.com)
+4. Growl
+5. Nice and shiny Mac - Of course you have one!
+
+
+## How to Use
+
+1. Make sure Alfred is running.
+
+2. Just hit your Alfred keyboard shortcut. In my case I have it configured it as CMD + SPACE. (The default is probably ALT + SPACE)
+
+ ![Alfred Launch Bar](https://github.com/ajotwani/Alfred-Flik/raw/master/images/alfred_launch_bar.png)
+
+3. Type the keyword **movie** followed by the **name of the movie** you want to search by and then the **name/phone number** of the person you'd like to text the results to (You can change the keyword by editing the info.plist file)
+
+ Using the phone number
+
+ ![Alfred Launch Bar](https://github.com/ajotwani/Alfred-Flik/raw/master/images/alfred_launch_bar_fill_1.png)
+
+ Using the address book described in **call_twilio.py** file
+
+ ![Alfred Launch Bar](https://github.com/ajotwani/Alfred-Flik/raw/master/images/alfred_launch_bar_fill_2.png)
+
+4. A text message is sent to your friend
+
+ ![Alfred Text Message](https://github.com/ajotwani/Alfred-Flik/raw/master/images/text_message.png)
+
+5. Also, you get a Growl notification confirming that the text was sent and the list of the movies that were sent.
+
+ ![Alfred Growl Notification](https://github.com/ajotwani/Alfred-Flik/raw/master/images/alfred_growl.png)
+
+
+## Examples ##
+ <pre>movie terminator john</pre>
+ <pre>movie "safety not guaranteed" +1417123456</pre>
+
+## Installation
+
+
+1. Grab the latest source
+ <pre>git clone git://github.com/ajotwani/Alfred-Flik.git</pre>
+
+2. Copy the directory you just downloaded to -
+ <pre>~/Library/Application Support/Alfred/extensions/scripts</pre>
+
+3. Rename this directory to say "AlfredFlik"
+
+4. Open the file "~/Library/Application Support/Alfred/extensions/scripts/AlfredFlik/rovi_auth.py" and type in your type in your Rovi **API key** & **Shared Secret**. Get your Rovi (Metadata and Search) API Key [here](http://developer.rovicorp.com)
+
+ ![Type your Rovi API Key](https://github.com/ajotwani/Alfred-Flik/raw/master/images/rovi_api_key.png)
+5. Open the file "call\_twilio\_.py" and type in your Twilio account id and toke id. Get your Twilio account & token id [here](http://twilio.com)
+
+ ![Type your Twilio API Key](https://github.com/ajotwani/Alfred-Flik/raw/master/images/twilio_api_key.png)
+6. Install all dependencies. Open Terminal and type the following (If you run into permission issues, try with sudo) -
+
+ Twilio's Python module
+
+ <pre>easy_install twilio</pre>
+
+ SimpleJSON
+ <pre>easy_install simplejson</pre>
+
+7. You're done. Just give Alfred a whirl now. Refer [How to Use](#how-to-use) above.
+
+
+## Development
+
+Be sure to follow the configuration steps above and use this step-by-step guide to tweak to your heart's content.
+
+1. Grab the latest source
+ <pre>git clone git://github.com/ajotwani/Alfred-Flik.git</pre>
+
+2. All the Rovi search related action takes place in the file **'rovi\_search\_.py'**
+
+3. All the Rovi auth related action takes place in the file **'rovi_auth.py'**
+
+4. All the Twilio related action takes place in the file **"call_twilio.py"**
+
+5. Tweak away
+
+
+## About
+
+* No warranty expressed or implied. Software is as is.
+* [MIT License](http://www.opensource.org/licenses/mit-license.html)
+* Lovingly created by [Mashery Dev](http://dev.mashery.com)
@@ -0,0 +1,26 @@
+from twilio.rest import TwilioRestClient
+
+def make_the_call(text_message,contact):
+
+# Get your Twilio account & token id at http://twilio.com
+ account = "your_twilo_account_id"
+ token = "your_twilo_token"
+
+ client = TwilioRestClient(account, token)
+
+ address_book = {'name1':'phone1','name2':'phone2'}
+ #Example: {'John':'+1212123456','Ana':'+417123456'}
+
+ for name, number in address_book.iteritems():
+ if name == contact:
+ to = number
+ break
+ else:
+ to = '+17033625298'
+
+ print "Following movies were sent to %s: \r\r" % (name)
+
+ #Truncating the text message
+ text_message = text_message[0:155]
+ message1 = client.sms.messages.create(to=to, from_="+16464616641", body=text_message)
+
BIN icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>action</key>
+ <false/>
+ <key>category</key>
+ <string>SCRIPTS</string>
+ <key>command</key>
+ <string>URL=$(./main.py "{query}")
+echo $URL</string>
+ <key>disabled</key>
+ <false/>
+ <key>escapequery</key>
+ <true/>
+ <key>escapequerybackquotes</key>
+ <true/>
+ <key>escapequerybrackets</key>
+ <true/>
+ <key>escapequeryquotes</key>
+ <true/>
+ <key>escapequerysemicolons</key>
+ <true/>
+ <key>growloutput</key>
+ <true/>
+ <key>growloutputsticky</key>
+ <true/>
+ <key>keyword</key>
+ <string>rovi</string>
+ <key>logging</key>
+ <true/>
+ <key>parameter</key>
+ <integer>0</integer>
+ <key>silent</key>
+ <true/>
+ <key>subtitle</key>
+ <string>Related Movie</string>
+ <key>title</key>
+ <string>Related Movie</string>
+</dict>
+</plist>
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>creator</key>
+ <string>MasheryDev</string>
+ <key>website</key>
+ <string>http://dev.mashery.com</string>
+</dict>
+</plist>
27 main.py
@@ -0,0 +1,27 @@
+#! /usr/bin/python
+
+from encodings import hex_codec
+from encodings import ascii
+import httplib
+import urllib2
+import json
+import sys
+import datetime
+import time
+import rovi_search
+
+# getting user input
+if len(sys.argv) < 2:
+ sys.exit(2)
+
+
+##### Use this when running from the commmand line #####
+# search = sys.argv[1]
+# contact = sys.argv[2]
+
+##### Use this when running from Alfred #####
+search = sys.argv[1].split ('\ ')[0]
+contact = sys.argv[1].split ('\ ')[1]
+
+
+rovi_search.get_relatedMovies(search, contact)
@@ -0,0 +1,24 @@
+import time
+import hashlib
+
+# Get your Rovi API Key from http://developer.rovicorp.com
+APIKEY = 'your_rovi_api_key'
+SECRET = 'your_rovi_shared_secret'
+
+def apikey():
+ return APIKEY
+
+def secret():
+ return SECRET
+
+def sign():
+ my_time = int(time.time())
+ sig = hashlib.md5()
+ sig.update(APIKEY)
+ sig.update(SECRET)
+ sig.update(str(my_time))
+
+ return sig.hexdigest()
+
+if __name__ == '__main__':
+ print sign()
@@ -0,0 +1,69 @@
+import urllib2
+import rovi_auth
+import call_twilio
+import json
+import simplejson
+
+def get_relatedMovies(search,contact):
+
+ contact = contact
+ sig = rovi_auth.sign()
+ try:
+ #Accessing Rovi's Metadata and Search API
+ url ='http://api.rovicorp.com/data/v1/movie/related?movie=%s&country=US&language=en&format=json&apikey=zz746f6m7guwqg2fehsecdah&sig=%s&limit=3' % (search,sig)
+ rovi_json = urllib2.urlopen(url).read()
+
+ # convert to a native python object
+ (true,false,null) = (True,False,None)
+
+ #Parsing the json payload
+ rovi_data = eval(rovi_json)
+
+ #Retrieving movie from the payload
+ movie = rovi_data ['related']['isRelatedTo']
+ related_movies =''
+ movie_review =''
+ reviews_message=''
+
+ for i, m in enumerate(movie):
+
+ movie_title_original = m ['title']
+ movie_title = (movie_title_original.replace(" ", "+")).replace(':','')
+
+ release_year = m ['releaseYear']
+
+ #Getting movie_id from Rotten Tomatoes for each movie returned by Rovi's related API. This code must run multiple times in a loop.
+ rotten_get_movie_id_url ='http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=bhtrz42e3ndmmnu4q62ppm2s&q=%s' % (movie_title)
+ rotten_json = urllib2.urlopen(rotten_get_movie_id_url).read()
+
+ (true,false,null) = (True,False,None)
+ rotten_data = eval(rotten_json)
+
+ try:
+ movie_id = rotten_data ['movies'][i]['id']
+
+ #Getting movie reviews from Rotten Tomatoes for each movie_id returned by Rotten Tomatoes' movies API. This code must run multiple times in a loop.
+ rotten_get_movie_review_url ='http://api.rottentomatoes.com/api/public/v1.0/movies/%s/reviews.json?apikey=bhtrz42e3ndmmnu4q62ppm2s' % (movie_id)
+
+ reviews_json = urllib2.urlopen(rotten_get_movie_review_url).read()
+ reviews_data = simplejson.loads(reviews_json)
+ movie_review = reviews_data ['reviews'][i]['links']['review']
+
+ except IndexError:
+ # print 'Review Not available'
+ print ' '
+
+ except simplejson.decoder.JSONDecodeError:
+ # print 'Review Not available'
+ print ' '
+
+ related_movies = related_movies + str(i+1) + '. ' + movie_title_original + ' \r'
+
+ except urllib2.URLError, e:
+ print e
+ except KeyError, e:
+ print e
+
+ call_twilio.make_the_call(related_movies,contact)
+ print "Message Sent \r"
+ print related_movies

0 comments on commit 97c43e4

Please sign in to comment.