Add utils module.

This commit is contained in:
Stephan Porada 2021-10-31 00:03:22 +02:00
parent b7642ffd36
commit 7af6522140
3 changed files with 67 additions and 0 deletions

53
utils/Url.py Normal file
View File

@ -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

0
utils/__init__.py Normal file
View File

14
utils/read.py Normal file
View File

@ -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