Skip to content

Commit

Permalink
Created new modules
Browse files Browse the repository at this point in the history
  • Loading branch information
viktoriia-yuzkiv committed May 13, 2017
1 parent a0c4843 commit c83b42a
Show file tree
Hide file tree
Showing 9 changed files with 440 additions and 0 deletions.
Binary file modified doc/Proposal for the research.docx
Binary file not shown.
Binary file added doc/SeriesResearch ADT.docx
Binary file not shown.
4 changes: 4 additions & 0 deletions examples/Example of usage of the API.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pytvdbapi import api

db = api.TVDB("1D6897F57A08B0BA")


Expand Down Expand Up @@ -103,3 +104,6 @@ def banner():
banner = show.banner_objects[0]
print(banner.banner_url)
print(banner.Language)


actors()
Empty file.
49 changes: 49 additions & 0 deletions modules/an_array.py
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
23 changes: 23 additions & 0 deletions modules/my_research.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from modules.work_with_a_file import WorkWithAFile
from modules.series_research import SeriesResearch
from modules.an_array import AnArray

# a = WorkWithAFile("ratings.txt")
# a1 = a.open_file()
# print(a.make_list(a1))


def popular_actors():
pass


def the_earliest_series():
pass


def series_names():
pass


def main():
pass
250 changes: 250 additions & 0 deletions modules/ratings.txt

Large diffs are not rendered by default.

67 changes: 67 additions & 0 deletions modules/series_research.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from pytvdbapi import api
from modules.an_array import AnArray

db = api.TVDB("1D6897F57A08B0BA")


class SeriesResearch:
"""
Implements the SeriesResearch ADT for doing
research based of the information about series.
"""

def __init__(self, length):
"""
Creates an array.
:param length: the length of a created array.
"""
self.allseries = AnArray(length)

def get_item(self, index):
"""
Gets the value of the element.
:param index: the index of the element.
:return: value of the element.
"""
return self.allseries.__getitem__(index)

def set_item(self, index, value):
"""
Puts the value in the array element at index position.
:param index: the index the element.
:param value: the value of the element.
"""
self.allseries.__setitem__(index, value)

def get_actors(self, index):
"""
Gets actors from series (the value of the element is
the name of series).
:param index: the index of the element.
:return: the list of actors.
"""
series = self.get_item(index)
actors = []
result = db.search(str(series), "en")
show = result[0]
show.load_actors()
for actor in range(len(show.actor_objects)):
actors.append(show.actor_objects[actor].Name)
return actors

def seasons_number(self, index):
"""
Gets the number of seasons in the given series
(the value of the element is the name of series).
:param index: the index of the element.
:return: the number of seasons.
"""
series = self.get_item(index)
result = db.search(str(series), "en")
show = result[0]
return len(show)
47 changes: 47 additions & 0 deletions modules/work_with_a_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Class WorkWithAFile is created to read information from a file
# ratings.txt and to convert it into a list of series names.


class WorkWithAFile:
"""
Contains functions open_file() and make_list().
To work with this class you should specify a filename.
"""

def __init__(self, filename):
"""
Creates an empty list.
:param filename: the name of a file.
"""
self.series = []
self.filename = filename

def open_file(self):
"""
Opens a file and saves all the information in a list
(split by newlines).
:return: a list with all the information from the file.
"""
all_series = []
openfile = open(self.filename, encoding="utf-8")
whole_file = openfile.readline()
while not whole_file.endswith("Forgotten Lady (Season 5, Episode 1)"):
whole_file = openfile.readline()
all_series.append(whole_file)
return all_series

def make_list(self, lst):
"""
Creates a list of series names.
:param lst: a list with all the information from the file.
:return: a list of series names.
"""
for i in range(0, len(lst), 5):
if i < 45:
self.series.append(lst[i][3:-1])
else:
self.series.append(lst[i][4:-1])
for name in range(len(self.series)):
if "(" in self.series[name]:
self.series[name] = self.series[name][:self.series[name].index("(") - 1]
return self.series

0 comments on commit c83b42a

Please sign in to comment.