2021-03-16 03:24:29 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2023-09-11 16:30:55 +02:00
|
|
|
# Copyright 2021-2023 Mike Fährmann
|
2021-03-16 03:24:29 +01:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
|
|
|
|
"""Extractors for https://architizer.com/"""
|
|
|
|
|
2021-03-19 01:31:34 +01:00
|
|
|
from .common import GalleryExtractor, Extractor, Message
|
2021-03-16 03:24:29 +01:00
|
|
|
from .. import text
|
|
|
|
|
|
|
|
|
|
|
|
class ArchitizerProjectExtractor(GalleryExtractor):
|
|
|
|
"""Extractor for project pages on architizer.com"""
|
|
|
|
category = "architizer"
|
|
|
|
subcategory = "project"
|
|
|
|
root = "https://architizer.com"
|
|
|
|
directory_fmt = ("{category}", "{firm}", "{title}")
|
|
|
|
filename_fmt = "{filename}.{extension}"
|
|
|
|
archive_fmt = "{gid}_{num}"
|
|
|
|
pattern = r"(?:https?://)?architizer\.com/projects/([^/?#]+)"
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://architizer.com/projects/NAME/"
|
2021-03-16 03:24:29 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
url = "{}/projects/{}/".format(self.root, match.group(1))
|
|
|
|
GalleryExtractor.__init__(self, match, url)
|
|
|
|
|
|
|
|
def metadata(self, page):
|
|
|
|
extr = text.extract_from(page)
|
2023-09-17 15:19:19 +02:00
|
|
|
extr('id="Pages"', "")
|
|
|
|
|
2021-03-16 03:24:29 +01:00
|
|
|
return {
|
2023-09-17 15:19:19 +02:00
|
|
|
"title" : extr('data-name="', '"'),
|
|
|
|
"slug" : extr('data-slug="', '"'),
|
|
|
|
"gid" : extr('data-gid="', '"').rpartition(".")[2],
|
|
|
|
"firm" : extr('data-firm-leaders-str="', '"'),
|
2021-03-16 03:24:29 +01:00
|
|
|
"location" : extr("<h2>", "<").strip(),
|
|
|
|
"type" : text.unescape(text.remove_html(extr(
|
|
|
|
'<div class="title">Type</div>', '<br'))),
|
|
|
|
"status" : text.remove_html(extr(
|
|
|
|
'<div class="title">STATUS</div>', '</')),
|
|
|
|
"year" : text.remove_html(extr(
|
|
|
|
'<div class="title">YEAR</div>', '</')),
|
|
|
|
"size" : text.remove_html(extr(
|
|
|
|
'<div class="title">SIZE</div>', '</')),
|
|
|
|
"description": text.unescape(extr(
|
|
|
|
'<span class="copy js-copy">', '</span></div>')
|
|
|
|
.replace("<br />", "\n")),
|
|
|
|
}
|
|
|
|
|
|
|
|
def images(self, page):
|
|
|
|
return [
|
|
|
|
(url, None)
|
|
|
|
for url in text.extract_iter(
|
2023-09-17 15:19:19 +02:00
|
|
|
page, 'property="og:image:secure_url" content="', "?")
|
2021-03-16 03:24:29 +01:00
|
|
|
]
|
2021-03-19 01:31:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
class ArchitizerFirmExtractor(Extractor):
|
|
|
|
"""Extractor for all projects of a firm"""
|
|
|
|
category = "architizer"
|
|
|
|
subcategory = "firm"
|
|
|
|
root = "https://architizer.com"
|
|
|
|
pattern = r"(?:https?://)?architizer\.com/firms/([^/?#]+)"
|
2023-09-11 16:30:55 +02:00
|
|
|
example = "https://architizer.com/firms/NAME/"
|
2021-03-19 01:31:34 +01:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
Extractor.__init__(self, match)
|
|
|
|
self.firm = match.group(1)
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
url = url = "{}/firms/{}/?requesting_merlin=pages".format(
|
|
|
|
self.root, self.firm)
|
|
|
|
page = self.request(url).text
|
|
|
|
data = {"_extractor": ArchitizerProjectExtractor}
|
|
|
|
|
|
|
|
for project in text.extract_iter(page, '<a href="/projects/', '"'):
|
|
|
|
if not project.startswith("q/"):
|
|
|
|
url = "{}/projects/{}".format(self.root, project)
|
|
|
|
yield Message.Queue, url, data
|