本文整理汇总了Python中movie.Movie.path方法的典型用法代码示例。如果您正苦于以下问题:Python Movie.path方法的具体用法?Python Movie.path怎么用?Python Movie.path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类movie.Movie
的用法示例。
在下文中一共展示了Movie.path方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from movie import Movie [as 别名]
# 或者: from movie.Movie import path [as 别名]
def main():
args = process_arguments()
movies_list = []
os.path.dirname(os.path.realpath(__file__))
# Single file should be checked
if args.path[0] == "single":
movies_list = get_list_of_files(args.path[1], "single")
# Folder should be scanned recusrivly
elif args.path[0] == "folder" and args.recursive:
movies_list = get_list_of_files(args.path[1], "recursive")
# Folder
else:
movies_list = get_list_of_files(args.path[1], "folder")
print "Working..."
# Obtain imdb id for each movie file
movie_dict = {}
movie_dict = OpenSubtitles.get_movie_data(movies_list)
del movies_list
# Create movies database which contains movie objects
movies_database = []
for element in movie_dict.items():
movie_obj = Movie()
movie_obj.imdb_id = element[1]
movie_obj.path = element[0]
movies_database.append(movie_obj)
del movie_dict
# For movies which has not imdb id detected try to obtain title
# from the file name
# File name must be in such format: mobie_title_year(4 digits)_extension
for movie in movies_database:
if movie.imdb_id == None:
obtain_title_and_year(movie)
print "obtained! %s" % (movie.title)
# Obtain movie details from imdb.
unique_movies_dict = {}
for movie in movies_database:
# imdb id detected - take movie data from imdb.com
if movie.imdb_id != None:
movie.imdb_object = ImdbCom.get_movie_data_from_imdbcom(movie.imdb_id)
movie.prepare_data_from_imdb()
if movie.imdb_id not in unique_movies_dict.keys():
print '"%s" processed.' % movie.title
unique_movies_dict[movie.imdb_id] = movie
# imdb id is not known but title has been obtained from file name
elif movie.title != None:
movie.imdb_object, movie.imdb_id = ImdbCom.search_movie_by_title(movie)
if movie.imdb_object:
movie.prepare_data_from_imdb()
if movie.imdb_id not in unique_movies_dict.keys():
print '"%s" processed.' % movie.title
unique_movies_dict[movie.imdb_id] = movie
else:
print '"%s" not processed.' % movie.path
# Preapre list of not duplicated movies
# Each movie objact on this list contains data from imdb.com
unique_movies_list = unique_movies_dict.values()
# Finally render index.html file
# Prepare environment for jinja2
execution_path = os.path.dirname(os.path.realpath(__file__))
templates_path = os.path.join(execution_path, "templates")
static_path = os.path.join(execution_path, "static")
# Prepare path for copying static files to cwd
templates_cwd_path = os.path.join(os.getcwd(), "moview/templates")
static_cwd_path = os.path.join(os.getcwd(), "moview/static")
# Remove moview tmp files if already exists in cwd
try:
shutil.rmtree(os.path.join(os.getcwd(), "moview"))
except:
pass
# Copy static files to cwd under moview direcotry
shutil.copytree(templates_path, templates_cwd_path)
shutil.copytree(static_path, static_cwd_path)
# Prepare environment for jinja2
env = Environment(loader=FileSystemLoader(templates_path))
# Select template
template = env.get_template("index.html")
# Render results to index.html file
rendered_file = open("index.html", "w")
rendered_file.write(template.render(movielist=unique_movies_list).encode("utf-8"))
rendered_file.close()
# That's it!
print "index.html with movie list has been " + "generated in the current directory."
print "Thanks for using MoView!"
return sys.exit(0)