def handle(self, url, to_try=postfixes, ori=None): if not self._is_exists(url): if not ori: ori = url prefix, postfix = url.rsplit('.', 1) return self.handle(prefix[:-1] + to_try[0] + '.' + postfix, to_try[1:], ori) fr = URL(url).path fr = fr[1:] if fr.startswith('/') else fr if not ori: return True to = URL(ori).path to = to[1:] if to.startswith('/') else to try: copy = self.bucket.copy_object('weegotr-statics', fr, to) if copy.status > 299: return self.handle(url, to_try, ori=None) logger.debug('Copy %s to %s %s', fr, to, copy.status) delete = self.bucket.delete_object(fr) logger.debug('Delete %s %s', fr, delete.status) logger.debug( 'Set expires to None %s %s', to, self.bucket.update_object_meta(to, { 'Expires': None }).status) except oss2.exceptions.NotFound as e: logger.exception(e) return False return True
def extract_facebook(): facebook, = (extract_other_item('FACEBOOK:', link=True) or [extract_other_item('FACEBOOK:')]) if not facebook: return facebook = URL('https://' + facebook.lstrip('/') if not facebook.startswith('http') else facebook) return str(URL('https://www.facebook.com/').with_path(facebook.path))
def _process_tags(elements: list, attr: str = "href", collect=True, edit=True) -> list[str]: result = [] for el in elements: link = el[attr] if link.startswith("data:"): continue link_rel = URL(link).path if link.startswith("http") else link link_rel = link_rel if link_rel.startswith("/") else f"/{link}" if collect: result.append(link_rel) if edit: el[attr] = "." + link_rel return result