示例#1
0
def test(request):
	titles=[]
	img_locations=[]
	movie_locations=[]

	extract_movies(titles, img_locations, movie_locations)

	for i in range(len((titles))):
		# print(titles[i])
		# print(movie_locations[i])
		# print(img_locations[i])
		if (len(Movie.objects.filter(name=titles[i]))==0 and titles[i]!='LOL'):
			if (len(RT(RT_KEY).search(titles[i]))>0 and RT(RT_KEY).search(titles[i])[0]['ratings']['critics_score']!=-1):
					critics_score= RT(RT_KEY).search(titles[i])[0]['ratings']['critics_score']
					audience_score=RT(RT_KEY).search(titles[i])[0]['ratings']['audience_score']
					movie = Movie(name=titles[i], url=movie_locations[i]+'?country='+country, pic_url=img_locations[i], country=country, is_american=False, audience_score=audience_score, critics_score=critics_score)
					movie.save()
					# get_rotten_tomates()
			else:
				movie = Movie(name=titles[i], url=movie_locations[i]+'?country='+country, pic_url=img_locations[i], country=country, is_american=False)
				movie.save()
			# if (len(RT('bt7f4pcbku6m9mqzuhhncc9e').search(titles[i]))>0 and RT('bt7f4pcbku6m9mqzuhhncc9e').search(titles[i])[0]['ratings']['critics_score']!=-1):
			# 		critics_score= RT('bt7f4pcbku6m9mqzuhhncc9e').search(titles[i])[0]['ratings']['critics_score']
			# 		audience_score=RT('bt7f4pcbku6m9mqzuhhncc9e').search(titles[i])[0]['ratings']['audience_score']
			# 		movie = Movie(name=titles[i], url=movie_locations[i]+'?country='+country, pic_url=img_locations[i], country=country, is_american=False, audience_score=audience_score, critics_score=critics_score)
			# 		movie.save()
			# else:
		get_rotten_tomates()
	t = get_template('index.html')
	html = t.render(Context({}))
	return HttpResponse(html)
示例#2
0
def get_rotten_tomates(request):
	for movie in Movie.objects.all():
		print("got here")
		if len(RT('bt7f4pcbku6m9mqzuhhncc9e').search(movie.name))==0:
			break
		movie_id=RT('bt7f4pcbku6m9mqzuhhncc9e').search(movie.name)[0]['id']
		if (len(RT('bt7f4pcbku6m9mqzuhhncc9e').info(movie_id, 'reviews')['reviews'])>2):

							reviewblob = RT('bt7f4pcbku6m9mqzuhhncc9e').info(movie_id, 'reviews')['reviews']
							quote1=reviewblob[0]['quote']
							fresh_bool1='fresh' in reviewblob[0]['freshness']
							name1= reviewblob[0]['critic']
							quote2=reviewblob[1]['quote']
							fresh_bool2='fresh' in reviewblob[1]['freshness']
							name2= reviewblob[1]['critic']
							quote3=reviewblob[2]['quote']
							fresh_bool3='fresh' in reviewblob[2]['freshness']
							name3= reviewblob[2]['critic']
							movie.quote1=quote1
							print(movie.name)
							print (movie.quote1)
							movie.quote2=quote2
							movie.quote3=quote3
							movie.critic1=name1
							movie.critic2=name2
							movie.critic3=name3
							movie.fresh1=fresh_bool1
							movie.fresh2=fresh_bool2
							movie.fresh3=fresh_bool3
							movie.save()
	t = get_template('index.html')
	html = t.render(Context({}))
	return HttpResponse(html)
示例#3
0
def rottenTomatoes(search_string, channel):
    '''Takes a string and outputs details from rotten tomatoes'''

    # Look up the json data from rotten tomatoes
    movie = RT().search(search_string, page_limit=1)

    # Respond if you don't find a match
    if not movie:
        ircMessage("no u", channel)
        return

    movie = movie[0]
    ratings = movie['ratings']

    # Not all movies have a synopsis
    summary = ""
    if movie['synopsis'] != "":
        summary = "Summary: " + movie['synopsis'][:200] + "..."

    # Movies without critics scores are replaced with N/A
    critics = "N/A"
    if ratings['critics_score'] > 0:
        critics = ratings['critics_score']

    message = "{0} ({1}): Critics: {2} Audience: {3} URL: http://rottentomatoes.com/m/{4} {5}".format(
        movie['title'], movie['year'], critics, ratings['audience_score'],
        movie['id'], summary)
    ircMessage(message, channel)
def synopsis_fetcher(movies):
    print movies
    client = MongoClient()
    db = client.recommender_db
    movies_db = db.movies
    synopsis = []
    for movie in movies:
        print movie['m_title']
        synopse = {}
        movie_in_db = movies_db.find_one({'m_id':movie['m_id']})
        if not movie_in_db.has_key('sin'):
            print movie['m_title']
            s_rotten = RT().search(movie['m_title'])
            sy_from_rotten = check_in_rotten(movie)
            if sy_from_rotten:
                synopse = sy_from_rotten
            else:
                search_imdb = search_title_imdb(movie['m_title'])
                if search_imdb:
                    synopse = {'m_id': movie['m_id'], 'sin':search_imdb}
        else:
            synopsis.append(movie_in_db)
            print "synopse append----------------------------"
        if synopse:
            synopsis.append(synopse)
            print "----------------fetched synopse--------------"
            print synopse
            print "---------------------------------------------"
            movies_db.update({"m_id":synopse['m_id']}, {'$set':{"sin":synopse['sin'] }})
    return synopsis
def get_rottentomatoes_ratings(title, year, result=None):
    print "Processing {} - {}".format(title, year)
    result = result or defaultdict(lambda: "N/A", {
        'title': title,
        'year': year
    })
    notes = []
    try:
        rt = RT(RT_API_KEY)
        movie_list = rt.search(process_title(title))
        if year:
            movie_list = filter_year(movie_list, year)
        if not movie_list:
            raise Exception("No results found.")
        try:
            movie = movie_list[0]
            result['rt_matched_title'] = movie['title']
            result['rt_audience_score'] = movie['ratings']['audience_score']
            result['rt_critics_score'] = movie['ratings']['critics_score']
        except KeyError:
            notes.append("Results not found: {}".format(title))

    except Exception as e:
        notes.append("Exception encountered: {}".format(e))
        traceback.print_exc()
    finally:
        # result['Title'] = title
        # result['Year'] = year
        result['rt_notes'] = '|'.join(notes)
        return result
示例#6
0
 def __init__(self,
              movie,
              rotten_tomatoe_api_key,
              tmdb_api_key,
              aws_access_key,
              aws_secret_key,
              affiliate_key,
              rt_id=None,
              tmdb_id=None):
     self._movie = movie
     # amazon
     self._amazon_product_search = AmazonProductSearch(
         aws_access_key, aws_secret_key, affiliate_key)
     # rotten tomatoes
     self._rt = RT(rotten_tomatoe_api_key)
     if rt_id:
         self._rt_data = self._rt.info(rt_id)
     else:
         self._rt_data = self._rt.search(movie)[0]
     # tmdb
     self._tmdb = tmdb
     self._tmdb.configure(tmdb_api_key)
     movie = self._tmdb.Movies(
         movie,
         limit=True,
         expected_release_date=self._rt_data['release_dates']
         ['theater']).get_best_match()
     self._tmdb_data = self._tmdb.Movie(movie[1]['id'])
     # youtube
     self._yt_service = gdata.youtube.service.YouTubeService()
示例#7
0
def get_rotten_tomates():
    for movie in Movie.objects.all():
        if len(RT('bt7f4pcbku6m9mqzuhhncc9e').search(movie.name)) == 0:
            break
        movie_id = RT('bt7f4pcbku6m9mqzuhhncc9e').search(movie.name)[0]['id']
        for j in range(
                len(
                    RT('bt7f4pcbku6m9mqzuhhncc9e').info(
                        movie_id, 'reviews')['reviews'])):
            reviewblob = RT('bt7f4pcbku6m9mqzuhhncc9e').info(
                movie_id, 'reviews')['reviews']
            quote = reviewblob[j]['quote']
            fresh_bool = 'fresh' in reviewblob[j]['freshness']
            name = reviewblob[j]['critic']
            print(quote)
            print(name)
            review = Review(name=name,
                            body=quote,
                            fresh=fresh_bool,
                            movie=movie)
            review.save()
示例#8
0
def movie_rat(f):
    movie=f[2]
    if len(f)>3:
        for i in range(3,len(f)):
            movie+=' '+f[i]
    rt = RT('53uhmdfpu5sybbb5y529skkh') #amitbj96
    title=rt.search(movie)[0]['title']       
    D1=rt.search(title,page_limit=1)[0]['ratings']
    D=rt.search(title)[0]['synopsis']
    D=str(D);
    if D=='':
        D="No Synopsis Found."
    # [movie name , ratings 5/5 , synopsis
    LL= [title,str(D1['audience_score'])+"/100",str(D)]
    return LL
def check_in_rotten(movie):
    s_rotten = RT().search(movie['m_title'])
    synopse = {}
    if s_rotten:
        m_rotten = s_rotten[0]
        r_synopse = m_rotten['synopsis']
        if r_synopse:
            synopse = {'m_id': movie['m_id'], 'sin':r_synopse}
        elif m_rotten.has_key('alternate_ids'):
            i_id = m_rotten['alternate_ids']['imdb']
            imdb_request_plot = get_imdb_plot(i_id)
            if imdb_request_plot:
                print imdb_request_plot
                synopse = {'m_id': movie['m_id'], 'sin':imdb_request_plot}
            else:
                print "no movie plot or synopse "
    return synopse
示例#10
0
文件: test.py 项目: rkp2916/SODM
 def test_search_results_for_standard_datatype(self):
     results = RT().search('some movie')
     self.assertEqual(results, ['first_result', 'second_result'])
示例#11
0
文件: test.py 项目: rkp2916/SODM
 def test_search_url_keys_for_lion_king(self):
     RT().search('the lion king')
     movie = call_args()
     assert 'my_api_key' in movie['apikey']
     assert 'the lion king' in movie['q']
示例#12
0
文件: test.py 项目: rkp2916/SODM
 def test_search_url_keys_with_page_arg(self):
     RT().search('some movie', page=2)
     movie = call_args()
     self.assertEqual(movie.keys(), ['q', 'apikey', 'page'])
示例#13
0
文件: test.py 项目: rkp2916/SODM
 def test_empty_search_url_keys(self):
     RT().search('')
     movie = call_args()
     self.assertEqual(movie.keys(), ['apikey'])
示例#14
0
文件: test.py 项目: rkp2916/SODM
 def test_version_argument_with_string(self):
     self.assertEqual(RT(version='2.5').version, '2.5')
示例#15
0
文件: test.py 项目: rkp2916/SODM
 def test_initialized_api_key(self):
     self.assertEqual(RT('called_api_key').api_key, 'called_api_key')
示例#16
0
文件: test.py 项目: rkp2916/SODM
 def test_first_json_loads_movies_result_is_returned(self):
     data = RT().feeling_lucky('some movie')
     self.assertEqual(data, 'first_result')
示例#17
0
文件: test.py 项目: rkp2916/SODM
 def test_uninitialized_api_key(self):
     self.assertEqual(RT().api_key, 'my_api_key')
示例#18
0
文件: test.py 项目: rkp2916/SODM
 def test_new_url_path_for_movies(self):
     RT().new('movies')
     path = call_args('path')
     self.assertEqual(path, '/api/public/v1.0/lists/movies/opening.json')
示例#19
0
文件: test.py 项目: rkp2916/SODM
 def test_version_argument_with_float(self):
     self.assertEqual(RT(version=2.5).version, '2.5')
示例#20
0
文件: test.py 项目: rkp2916/SODM
 def test_new_url_keys_for_movies_with_kwargs(self):
     RT().new('movies', page_limit=5)
     parsed_query = call_args()
     assert '5' in parsed_query['page_limit']
示例#21
0
文件: test.py 项目: rkp2916/SODM
 def test_nonempty_search_url_path(self):
     RT().search('some movie')
     path = call_args('path')
     self.assertEqual(path, '/api/public/v1.0/movies')
示例#22
0
文件: test.py 项目: rkp2916/SODM
 def test_movies_in_theaters(self):
     RT().movies('in_theaters')
     path = call_args('path')
     expected_path = '/api/public/v1.0/lists/movies/in_theaters.json'
     self.assertEqual(path, expected_path)
示例#23
0
文件: test.py 项目: rkp2916/SODM
 def test_nonempty_search_url_keys(self):
     RT().search('some movie')
     movie = call_args()
     self.assertEqual(movie.keys(), ['q', 'apikey'])
示例#24
0
文件: test.py 项目: rkp2916/SODM
 def test_movies_opening(self):
     RT().movies('opening')
     path = call_args('path')
     expected_path = '/api/public/v1.0/lists/movies/opening.json'
     self.assertEqual(path, expected_path)
示例#25
0
文件: test.py 项目: rkp2916/SODM
 def test_search_url_keys_with_multiple_kwargs(self):
     RT().search('some movie', page=2, page_limit=5)
     movie = call_args()
     self.assertEqual(movie.keys(), ['q', 'apikey', 'page', 'page_limit'])
示例#26
0
文件: test.py 项目: rkp2916/SODM
 def test_movies_box_office(self):
     RT().movies('box_office')
     path = call_args('path')
     expected_path = '/api/public/v1.0/lists/movies/box_office.json'
     self.assertEqual(path, expected_path)
示例#27
0
文件: test.py 项目: rkp2916/SODM
 def test_search_url_keys_for_ronin(self):
     RT().search('ronin')
     movie = call_args()
     assert 'my_api_key' in movie['apikey']
     assert 'ronin' in movie['q']
示例#28
0
文件: test.py 项目: rkp2916/SODM
 def test_dvds_new_releases(self):
     RT().dvds('new_releases')
     path = call_args('path')
     expected_path = '/api/public/v1.0/lists/dvds/new_releases.json'
     self.assertEqual(path, expected_path)
示例#29
0
#!/usr/bin/env python

from rottentomatoes import RT
import json, csv

rt = RT()

#movies = ['toy story 3', 'the lion king', 'the matrix', 'the dark knight', 'inception', 'titanic', 'the godfather', 'the little mermaid', 'the shining', 'avatar']
movies = ['pocahontas', 'shawshank redemption']

json = []
for movie in movies:
    json = json + rt.search(movie)

with open('test2.csv', 'wb+') as f:
    dict_writer = csv.DictWriter(
        f,
        fieldnames=[
            'ratings', 'abridged_directors', 'links', 'title',
            'critics_consensus', 'release_dates', 'abridged_cast', 'synopsis',
            'mpaa_rating', 'year', 'alternate_ids', 'posters', 'runtime', 'id'
        ])
    dict_writer.writeheader()
    dict_writer.writerows(json)
示例#30
0
文件: test.py 项目: rkp2916/SODM
 def test_empty_feeling_lucky_method_fails(self):
     self.assertRaises(TypeError, RT().feeling_lucky)