diff --git a/utils/Url.py b/utils/Url.py new file mode 100644 index 0000000..9e12613 --- /dev/null +++ b/utils/Url.py @@ -0,0 +1,53 @@ +class Url: + """ + Class to build the python challenge url with the solution string and an + optional slug. + """ + + def __init__(self): + self._url = '' + self._slug = 'html' + self._solution = '' + + BASE_URL = 'http://www.pythonchallenge.com/pc/def' + + @property + def url(self): + """ + Gets the url string of the builder. + :return: url string + """ + return f'{self.BASE_URL}/{self.solution}.{self.slug}' + + @property + def solution(self): + """ + Returns the solution string + :return: solution string + """ + return self._solution + + @solution.setter + def solution(self, solution): + """ + Sets the solution string + :param solution: str + """ + self._solution = solution + + @property + def slug(self): + """ + Returns the slug string + :return: slug string + """ + return self._slug + + @slug.setter + def slug(self, slug): + """ + Sets the slug string + :param slug: str + :return: slug string + """ + self._slug = slug diff --git a/utils/__init__.py b/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/utils/read.py b/utils/read.py new file mode 100644 index 0000000..0183fd7 --- /dev/null +++ b/utils/read.py @@ -0,0 +1,14 @@ +""" +Sone utility functions that can be reused for the python challenge. +""" + + +def read_string(path): + """ + Read a string from a file provided by a path string. + :param path: A path string + :return: file content as a string + """ + with open(path) as file: + string = file.read() + return string