-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adfb591
commit 4a3ec67
Showing
11 changed files
with
585 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
from pytvdbapi import api | ||
|
||
db = api.TVDB("1D6897F57A08B0BA") | ||
|
||
|
||
def actors(): | ||
""" | ||
Prints the information about actors, their roles and their photos (from "Sherlock"). | ||
""" | ||
result = db.search("Sherlock", "en") | ||
show = result[0] | ||
show.load_actors() | ||
for actor in range(len(show.actor_objects)): | ||
print(u"{0} - {1} - {2}".format(show.actor_objects[actor].Name, show.actor_objects[actor].Role, | ||
show.actor_objects[actor].image_url)) | ||
|
||
|
||
def seasons_and_episodes(): | ||
""" | ||
Prints the number of seasons in "Sherlock" and then prints the | ||
title of every episode. | ||
""" | ||
result = db.search("Sherlock", "en") | ||
show = result[0] | ||
print("\n") | ||
print("The number of seasons: ", len(show)) | ||
for episode in show[2]: | ||
print(episode.EpisodeName) | ||
|
||
|
||
def show(): | ||
""" | ||
Prints the set of basic attributes and | ||
the full data set from the server. | ||
""" | ||
result = db.search("dexter", "en") | ||
show = result[0] | ||
print(dir(show)) # List the set of basic attributes | ||
show.update() # Load the full data set from the server | ||
print(dir(show)) | ||
|
||
|
||
def episode(): | ||
""" | ||
Prints information about 1 episode from 1 season in "Sherlock". | ||
""" | ||
result = db.search("Sherlock", "en") | ||
show = result[0] | ||
episode = show[1][2] # Get episode S01E02 | ||
print(episode.season) | ||
print(episode.EpisodeNumber) | ||
print(episode.EpisodeName) | ||
print(episode.FirstAired) | ||
|
||
|
||
def languages(): | ||
""" | ||
Prints the list of available languages. | ||
""" | ||
for language in api.languages(): | ||
print(language) | ||
|
||
|
||
def search(): | ||
""" | ||
Searches episodes which have in their titles word | ||
"Sherlock". Prints it. | ||
""" | ||
result = db.search("Sherlock", "en") | ||
print(result[0], "\n") | ||
for show in result: | ||
print(show) | ||
|
||
|
||
def get_series(): | ||
""" | ||
Finds a series by its ID. | ||
""" | ||
a = 79349 | ||
show = db.get_series(a, "en") # Load Dexter | ||
print("ID:", a, "\n", show.SeriesName) | ||
|
||
|
||
def get_episode(): | ||
""" | ||
Finds episods by diven parameters. | ||
""" | ||
ep = db.get_episode("en", episodeid=308834) # id is the default method | ||
print(ep.EpisodeName, "\n") | ||
ep1 = db.get_episode("en", "dvd", seasonnumber=2, episodenumber=5, seriesid=79349) | ||
print(ep1.EpisodeName, "\n") | ||
ep2 = db.get_episode("en", "default", seasonnumber=2, episodenumber=6, seriesid=79349) | ||
print(ep2.EpisodeName, "\n") | ||
|
||
|
||
def banner(): | ||
""" | ||
Prints the url link to banner of a certain series. | ||
""" | ||
db = api.TVDB('B43FF87DE395DF56', banners=True) | ||
show = db.get_series(79349, "en") # Dexter | ||
show.update() | ||
assert len(show.banner_objects) > 0 | ||
banner = show.banner_objects[0] | ||
print(banner.banner_url) | ||
print(banner.Language) | ||
|
||
|
||
actors() |
35 changes: 35 additions & 0 deletions
35
build/lib/examples/Example of usage of the SeriesResearch ADT.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from modules.series_research import SeriesResearch | ||
|
||
|
||
def example(): | ||
""" | ||
The example of usage of the SeriesResearch ADT. | ||
""" | ||
# Creates a new array (length = 2) | ||
new_array = SeriesResearch(2) | ||
|
||
# Sets values to each element of the array. | ||
new_array.set_item(0, "Sherlock") | ||
new_array.set_item(1, "Doctor Who") | ||
|
||
# Gets values and prints it. | ||
print("Item 0 = ", new_array.get_item(0)) | ||
print("Item 1 = ", new_array.get_item(1)) | ||
|
||
# Gets lists of actors. | ||
actors0 = new_array.get_actors(0) | ||
actors1 = new_array.get_actors(1) | ||
|
||
# Prints these lists. | ||
print(actors0) | ||
print(actors1) | ||
|
||
# Finds the number of seasons in series. | ||
seasons0 = new_array.seasons_number(0) | ||
seasons1 = new_array.seasons_number(1) | ||
|
||
# Prints the number of seasons. | ||
print("The number of seasons in", new_array.get_item(0), ":", seasons0) | ||
print("The number of seasons in", new_array.get_item(1), ":", seasons1) | ||
|
||
example() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import ctypes | ||
|
||
|
||
class AnArray: | ||
""" | ||
Creates an array and gives some tools to work with it. | ||
""" | ||
def __init__(self, size): | ||
""" | ||
Creates an array with the length size. | ||
:param size: the size of the array. | ||
""" | ||
assert size > 0, "Array size must be > 0" | ||
self._size = size | ||
pyarraytype = ctypes.py_object * size | ||
self._elements = pyarraytype() | ||
for i in range(len(self)): | ||
self._elements[i] = None | ||
|
||
def __len__(self): | ||
""" | ||
Returns the length of the array. | ||
:return: the size of the array. | ||
""" | ||
return self._size | ||
|
||
def __getitem__(self, index): | ||
""" | ||
Gets the value of the element. | ||
:param index: the index of element. | ||
:return: value of the element. | ||
""" | ||
if not 0 <= index < self._size: | ||
raise IndexError('Invalid index') | ||
return self._elements[index] | ||
|
||
def __setitem__(self, index, value): | ||
""" | ||
Puts the value in the array element at index position. | ||
:param index: the index element. | ||
:param value: the value of element. | ||
""" | ||
if not 0 <= index < self._size: | ||
raise IndexError('Invalid index') | ||
self._elements[index] = value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
from modules.work_with_a_file import WorkWithAFile | ||
from modules.series_research import SeriesResearch | ||
|
||
|
||
class MainResearch: | ||
""" | ||
This class represents methods which help to do some research. | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
Reads the information from a file. | ||
Makes an array which contains that information. | ||
""" | ||
file = WorkWithAFile("ratings.txt") | ||
file1 = file.open_file() | ||
my_lst = file.make_list(file1) | ||
self.series = SeriesResearch(len(my_lst)) | ||
for i in range(self.series.find_len()): | ||
self.series.set_item(i, my_lst[i]) | ||
|
||
def __str__(self): | ||
""" | ||
Creates a string with series titles. | ||
:return: a string with series titles | ||
""" | ||
series = '' | ||
for i in range(self.series.find_len()): | ||
series += self.series.get_item(i) + ' , ' | ||
return series | ||
|
||
def popular_actors(self): | ||
""" | ||
Creates a dictionary. Gets the information about all | ||
actors from given series and adds it to the dictionary | ||
(key - the name of an actor/actress, value - the number of series | ||
in which that actor/actress performed). | ||
:return: a dictionary (key - the name of an actor/actress, value - | ||
the number of series in which that actor/actress performed) | ||
""" | ||
actors = {} | ||
for i in range(self.series.find_len()): | ||
try: | ||
actors_from_series = self.series.get_actors(i) | ||
for actor in actors_from_series: | ||
if actor not in actors: | ||
actors[actor] = 1 | ||
else: | ||
actors[actor] += 1 | ||
except IndexError: | ||
continue | ||
return actors | ||
|
||
def series_seasons(self): | ||
""" | ||
Creates a dictionary. Gets the information about number of seasons | ||
in series adds it to the dictionary (key - series title, value - the number | ||
of seasons). | ||
:return: a dictionary (key - series title, value - the number of seasons). | ||
""" | ||
seasons = {} | ||
for i in range(self.series.find_len()): | ||
try: | ||
seasons[self.series.get_item(i)] = self.series.seasons_number(i) | ||
except IndexError: | ||
continue | ||
return seasons | ||
|
||
def series_titles(self): | ||
""" | ||
Creates a dictionary. Gets every word from series titles and adds it | ||
to the dictionary(key - word, value - the number of repetition in | ||
series titles). | ||
:return: the dictionary(key - word, value - the number of | ||
repetition in series titles). | ||
""" | ||
words = {} | ||
for i in range(self.series.find_len()): | ||
word = self.series.get_item(i).split() | ||
for k in word: | ||
if k not in words: | ||
words[k] = 1 | ||
else: | ||
words[k] += 1 | ||
return words | ||
|
||
|
||
def save_info(info, filename): | ||
""" | ||
Creates a new file with a name filename. | ||
Writes the information from info into this file. | ||
:param info: a list of tuples with the information | ||
that should be saved. | ||
:param filename: a name of a created file. | ||
""" | ||
thefile = open(filename, 'w') | ||
for item in info: | ||
thefile.write(str(item[1]) + " - " + str(item[0]) + '\n') | ||
|
||
|
||
def main(): | ||
""" | ||
Makes the main research. | ||
""" | ||
series = MainResearch() | ||
|
||
# actors | ||
actors_list = [] | ||
allactors = series.popular_actors() | ||
for key, val in allactors.items(): | ||
if val > 1: | ||
actors_list.append((key, val)) | ||
save_info(sorted(actors_list, key=lambda x: x[1], reverse=True), "popular_actors.txt") | ||
|
||
# seasons | ||
average = 0 | ||
allseasons = series.series_seasons() | ||
save_info(sorted(allseasons.items(), key=lambda x: x[1], reverse=True), "series_seasons.txt") | ||
for key, val in allseasons.items(): | ||
average += val | ||
|
||
# titles | ||
alltitles = series.series_titles() | ||
save_info(sorted(alltitles.items(), key=lambda x: x[1], reverse=True), "series_titles.txt") | ||
return int(average / 47) | ||
|
||
|
||
print(main()) |
Oops, something went wrong.