From 7af6522140b5043bebdb73611d2616b7916a52eb Mon Sep 17 00:00:00 2001 From: Stephan Porada Date: Sun, 31 Oct 2021 00:03:22 +0200 Subject: [PATCH] Add utils module. --- utils/Url.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++ utils/__init__.py | 0 utils/read.py | 14 +++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 utils/Url.py create mode 100644 utils/__init__.py create mode 100644 utils/read.py 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