diff --git a/lib/WPMenu.py b/lib/WPMenu.py index cfa2f28..d2bb997 100644 --- a/lib/WPMenu.py +++ b/lib/WPMenu.py @@ -8,17 +8,21 @@ from requests.packages.urllib3.util.retry import Retry class WPMenu: # Constructor - def __init__(self, name="Thread-0", basic=None, wordpress="", logger=None, parser="html.parser", ssl_wordpress=True): + def __init__(self, name="Thread-0", basic=None, canalblog="", wordpress="", logger=None, parser="html.parser", ssl_canalblog=True, ssl_wordpress=True): self._name = name self._basic = basic + self._canalblog = canalblog self._wordpress = wordpress self._logger = logger self._parser = parser self._headers_json = {'Content-Type': 'application/json; charset=utf-8', 'Accept':'application/json'} - self._protocol = "https" + self._protocol_wordpress, self._protocol_canalblog = "https" self._directory = "backup" + if ssl_wordpress is False: - self._protocol = "http" + self._protocol_wordpress = "http" + if ssl_canalblog is False: + self._protocol_canalblog = "http" self._request = requests.Session() retries = Retry(connect=10, read=10, redirect=5, @@ -28,4 +32,25 @@ class WPMenu: # Destructor def __del__(self): - print("{0} : Import finished for {1}".format(self._name, self._wordpress)) \ No newline at end of file + print("{0} : Import finished for {1}".format(self._name, self._wordpress)) + + # Public method + + ## Get from URL + + def fromUrl(self): + try: + o = urlparse(self._canalblog) + o = o._replace(scheme=self._protocol_canalblog) + i = o.geturl().replace(":///", "://") + page = self._request.get(i) + if page.status_code == 200: + soup = BeautifulSoup(page.text, self._parser) + else: + self._logger.error("{0} : index didn't get due status code : {1}".format(self._name, page.status_code)) + self._logger.debug("{0} : {1}".format(self._name, page.content)) + except ConnectionError as err: + self._logger.error("{0} : Connection error for get url {1} : {2}".format(self._name, webpage[i], err)) + exit(1) + except Exception as err: + self._logger.error("{0} : Exception error for get url {1} : {2}".format(self._name, webpage[i], err)) \ No newline at end of file