furmeet_events_htmltable2ics/backend_code/timetable_parser/reader.py
Adler Neves 8a1102d99b
All checks were successful
continuous-integration/drone Build is passing
Initial commit
2022-04-24 12:09:38 -03:00

38 lines
738 B
Python

#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
import sys
from pathlib import Path
import requests
class AbstractReader:
def __init__(self, path: str):
self._path = path
def read(self) -> str:
raise NotImplementedError()
class HttpReader(AbstractReader):
def read(self) -> str:
resp = requests.get(self._path)
resp.raise_for_status()
return resp.text
class KnownReader(AbstractReader):
def read(self) -> str:
return self._path
class StdioReader(AbstractReader):
def read(self) -> str:
return sys.stdin.read()
class FileReader(AbstractReader):
def read(self) -> str:
return Path(self._path).read_text(encoding='utf-8', errors='strict')