diff --git a/etc/circle.py b/etc/circle.py new file mode 100644 index 0000000..9a9102b --- /dev/null +++ b/etc/circle.py @@ -0,0 +1,45 @@ +class Shape: + def __init__(self, x, y): + self.x = x + self.y = y + + def move(self, delta_x, delta_y): + self.x = self.x + delta_x + self.y = self.y + delta_y + + +class Square(Shape): + def __init__(self, side=1, x=0, y=0): + super().__init__(x, y) + self.side = side + + +class Circle(Shape): + pi = 3.14159 + all_circles = [] + + def __init__(self, radius=1, x=0, y=0): + super().__init__(x, y) + self.radius = radius + self.all_circles.append(self) + + @property + def radius(self): + return self._radius + + @radius.setter + def radius(self, value): + if value < 0: + raise ValueError("Radius cannot be negative") + self._radius = value + + @classmethod + def total_area(cls): + area = 0 + for circle in cls.all_circles: + area += cls.circle_area(circle.radius) + return area + + @staticmethod + def circle_area(radius): + return __class__.pi * radius * radius diff --git a/etc/decorators.py b/etc/decorators.py new file mode 100644 index 0000000..fb605b8 --- /dev/null +++ b/etc/decorators.py @@ -0,0 +1,12 @@ +def wrap_with_html(fn): + def wrapper_func(*args): + print('') + fn(*args) + print('') + return wrapper_func + +@wrap_with_html +def echo(param): + print(param) + +echo('Hello') \ No newline at end of file diff --git a/etc/kindahtml.py b/etc/kindahtml.py new file mode 100644 index 0000000..b7c88ce --- /dev/null +++ b/etc/kindahtml.py @@ -0,0 +1,33 @@ +class HtmlElement: + tag = "html" + indent = " " + def __init__(self, content=None, **kwargs): + if content is None: + self.contents = [] + else: + self.contents = [content] + self.attributes = kwargs + def append(self, new_content): + self.contents.append(new_content) + def render(self, cur_ind=""): + print(cur_ind + f"<{self.tag}>") + for content in self.contents: + try: + content.render(cur_ind + self.indent) + except AttributeError: + print(cur_ind + self.indent + content) + print(cur_ind + f"") + +class Body(HtmlElement): + tag = "body" + +class Paragraph(HtmlElement): + tag = "p" + + + +para = Paragraph("hello") +body = Body(para) +body.append("world") +doc = HtmlElement(body) +doc.render() diff --git a/etc/nasa.py b/etc/nasa.py new file mode 100644 index 0000000..b8bedd0 --- /dev/null +++ b/etc/nasa.py @@ -0,0 +1,11 @@ +import requests +import json + +api_key = "DEMO_KEY" + +def get_weather(): + url = f"https://api.nasa.gov/insight_weather/?api_key={api_key}&feedtype=json&ver=1.0" + response = requests.get(url) + return json.loads(response.text) + +print(get_weather())