Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pre-interview-test #53

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,22 @@ Whether you've applied to Seevibes through an internship program, or just want t
## Need help?

You can contact François Beausoleil ([email protected]) if you need any help.

## Usage
Coded on python2.7. It needs to download IMDbPY. I recommend using virtualenv. program takes in one required argument and one optional argument. First argument is partial movie title you want to search. Second argument is the number of output with movie title. If second argument is not given, it will have default value of 1.

Install
```bash
pip install IMDbPY
```

Some examples
```bash
./program batman 2
Title: Batman v Superman: Dawn of Justice
Year: 2016

Title: Batman Begins
Year: 2005

```
66 changes: 66 additions & 0 deletions program
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# File Name: program.py
# Author: Akira Kakkar
# Python Version: 2.7

from imdb import IMDb
import sys

def split_title_year(movie):
title_year = movie['long imdb canonical title']
year = title_year.split(' ')[-1][1:-1]
title = ' '.join(title_year.split(' ')[:-1])
if title[0] == '"':
title = title[1:-1]
return title, year

def extract_movies(keyword, nums):
movies_list = []
ia = IMDb()
movies = ia.search_movie(keyword)
updated = nums
if nums >= len(movies):
updated = len(movies)
count = 0
for item in movies:
if count >= updated:
break
title, year = split_title_year(item)
if keyword.lower() in title.lower():
movies_list.append((title, year))
count += 1

return movies_list

def print_movies(list_movies):
for movie in list_movies:
print "Title: " + check_the(movie[0])
print "Year: " + movie[1] + '\n'

def check_the(movie_title):
split = movie_title.split(',')
if len(split) == 2 and split[1] == ' The':
return split[1][1:] + ' ' + split[0]
return movie_title

if __name__ == '__main__':
if (len(sys.argv)) == 3:
nums = sys.argv[2]
if not nums.isdigit():
print "Second argument needs to be a positive integer"
while(not nums.isdigit() and int(nums) <= 0):
nums = raw_input("How many outputs? ")
nums = int(nums)
keyword = sys.argv[1]
elif (len(sys.argv)) == 2:
nums = 1
keyword = sys.argv[1]
else:
nums = 1
keyword = ""
while(not keyword):
keyword = raw_input("Type keyword for search? ")
movie_list = extract_movies(keyword, nums)
print_movies(movie_list)
66 changes: 66 additions & 0 deletions program.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# File Name: program.py
# Author: Akira Kakkar
# Python Version: 2.7

from imdb import IMDb
import sys

def split_title_year(movie):
title_year = movie['long imdb canonical title']
year = title_year.split(' ')[-1][1:-1]
title = ' '.join(title_year.split(' ')[:-1])
if title[0] == '"':
title = title[1:-1]
return title, year

def extract_movies(keyword, nums):
movies_list = []
ia = IMDb()
movies = ia.search_movie(keyword)
updated = nums
if nums >= len(movies):
updated = len(movies)
count = 0
for item in movies:
if count >= updated:
break
title, year = split_title_year(item)
if keyword.lower() in title.lower():
movies_list.append((title, year))
count += 1

return movies_list

def print_movies(list_movies):
for movie in list_movies:
print "Title: " + check_the(movie[0])
print "Year: " + movie[1] + '\n'

def check_the(movie_title):
split = movie_title.split(',')
if len(split) == 2 and split[1] == ' The':
return split[1][1:] + ' ' + split[0]
return movie_title

if __name__ == '__main__':
if (len(sys.argv)) == 3:
nums = sys.argv[2]
if not nums.isdigit():
print "Second argument needs to be a positive integer"
while(not nums.isdigit() and int(nums) <= 0):
nums = raw_input("How many outputs? ")
nums = int(nums)
keyword = sys.argv[1]
elif (len(sys.argv)) == 2:
nums = 1
keyword = sys.argv[1]
else:
nums = 1
keyword = ""
while(not keyword):
keyword = raw_input("Type keyword for search? ")
movie_list = extract_movies(keyword, nums)
print_movies(movie_list)