diff options
author | Alban Gruin | 2018-09-06 21:46:51 +0200 |
---|---|---|
committer | Alban Gruin | 2018-09-06 21:46:51 +0200 |
commit | 676345434415d40363c80960484abf0295ca800a (patch) | |
tree | 76c0f71fd86f19962812a63da109bf79ebd2d43c /management/parsers/abstractparser.py | |
parent | 6b8ea6615de6000ea14396fc2d31eb5c6cb159f9 (diff) | |
parent | b4fde18263de491650c71bd31dffe3c324e97879 (diff) |
Merge branch 'stable/0.14.z' into prod/pa1ch/0.y.zv0.14.0-pa1chprod/pa1ch/0.y.z
Diffstat (limited to 'management/parsers/abstractparser.py')
-rw-r--r-- | management/parsers/abstractparser.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/management/parsers/abstractparser.py b/management/parsers/abstractparser.py new file mode 100644 index 0000000..8d55b6d --- /dev/null +++ b/management/parsers/abstractparser.py @@ -0,0 +1,52 @@ +# Copyright (C) 2018 Alban Gruin +# +# celcatsanitizer is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# celcatsanitizer is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with celcatsanitizer. If not, see <http://www.gnu.org/licenses/>. + +import abc +import requests + +import edt + + +class AbstractParser(metaclass=abc.ABCMeta): + def __init__(self, source): + self.source = source + self.user_agent = "celcatsanitizer/" + edt.VERSION + + def _make_request(self, url, user_agent=None, encoding="utf8", **kwargs): + user_agent = user_agent if user_agent is not None else self.user_agent + + params = kwargs["params"] if "params" in kwargs else {} + headers = kwargs["headers"] if "headers" in kwargs else {} + headers["User-Agent"] = user_agent + + req = requests.get(url, headers=headers, params=params) + req.encoding = encoding + + return req + + @abc.abstractmethod + def get_events(self): + pass + + @abc.abstractmethod + def get_update_date(self): + pass + + @abc.abstractmethod + def get_weeks(self): + pass + + def get_source(self): + return self._make_request(self.source.url) |