-
Notifications
You must be signed in to change notification settings - Fork 6
/
write.py
97 lines (89 loc) · 3.06 KB
/
write.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import click,sys
import textwrap
from movies.get_data import get_final_list
def colors():
"""Creates an enum for colors"""
enums = dict(
#TIME_LEFT="red",
name="yellow",
title="magenta",
genre="green",
synopsis="cyan",
duration="blue",
dimension="red"
)
return type('Enum', (), enums)
def write_movie_list_header():
sys.stdout.write("\x1b[8;{rows};{cols}t".format(rows=40, cols=110))
click.secho("\n %-3s %-40s %-30s %-10s %-15s" %
("ID", "NAME", "GENRE", "3D","DURATION"))
def write_movie_list(location):
write_movie_list_header()
movie_list=get_final_list(location)
for index,movie in enumerate(movie_list):
name=movie['Title'].encode('utf-8')
if len(name) > 20:
name = name[:20]
genres=movie['Genre'].split("|")
for i in range(len(genres)):
if len(genres[i]) > 10:
genres[i] = genres[i][:10]
extra=movie['Extra']
duration=format(float(float(movie['Duration'])/60),'.2f')+' Hrs'
click.echo()
click.secho(" %-3s"%str(index+1),nl=False,bold=False)
click.secho(" %-40s" %
name,nl=False,fg=colors().name,bold=False)
gs=""
for genre in genres:
genre=genre.title()
# print genre
gs=gs+genre+" "
# print gs
click.secho(" %-30s"%gs,nl=False,fg=colors().genre,bold=False)
for i,child in enumerate(extra):
td=False
if extra[i]['Dimension']=='3D':
td=True
if td==True:
click.secho(" %-10s"%'Yes',nl=False,bold=False)
else:
click.secho(" %-10s"%'No',fg=colors().dimension,nl=False,bold=False)
click.secho(" %-5s"%duration,nl=False,bold=False)
click.echo()
return movie_list
def write_movie(movie):
click.echo()
name=movie['name']
if len(name) > 20:
name = name[:20]
critic_rating=movie['critic_rating']
cast=movie['lead_cast']
synopsis="\033[35m"+movie['synopsis']
trailer=movie['trailer-url']
click.secho(" Name : ",nl=False,fg=colors().synopsis)
click.secho(" %-30s"%name,bold=True,fg=colors().duration)
prefix=" Synopsis : "
preferredWidth=70
wrapper = textwrap.TextWrapper(initial_indent=prefix, width=preferredWidth,subsequent_indent=' '*len(prefix))
click.secho(wrapper.fill(synopsis),fg=colors().synopsis)
click.secho(" Cast : ",nl=False,fg=colors().synopsis)
cast_names=", ".join(cast)
click.secho(cast_names,fg=colors().genre)
click.secho(" Rating : ",nl=False,fg=colors().synopsis)
click.secho(critic_rating)
click.secho(" Trailer : ",nl=False,fg=colors().synopsis)
click.secho(trailer,fg=colors().name)
click.echo()
if __name__ == '__main__':
# Just an Example
location="kota"
movie={'critic_rating': u'2.5',
'lead_cast': [u'Riteish Deshmukh',
u'Vivek Oberoi',
u'Aftab Shivdasani',
u'Urvashi Rautela'],
'name': u'Great Grand Masti',
'synopsis': 'Great Grand Masti is the third film in the Masti trilogy. The Adult Comedy stars the terrific trio of - Riteish Deshmukh, Aftab Shivdasani and Vivek Oberoi. They meet Ragini (Urvashi Rautela) in a village. The movie revolves around how the trio find out that Ragini is not the hot girl she appears at first.',
'trailer-url': u'www.youtube.com/watch?v=ZojV0FC-KdI'}
write_movie(movie)