From f100b105881a98c60de1f4ef8b0fd6f8efa982f1 Mon Sep 17 00:00:00 2001 From: "theo.bernard" Date: Fri, 25 Apr 2025 15:18:01 +0200 Subject: [PATCH] first commit --- data.json | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 17 ++++++++ script.js | 88 +++++++++++++++++++++++++++++++++++++++++ styles.css | 71 +++++++++++++++++++++++++++++++++ themet.py | 55 ++++++++++++++++++++++++++ 5 files changed, 343 insertions(+) create mode 100644 data.json create mode 100644 index.html create mode 100644 script.js create mode 100644 styles.css create mode 100644 themet.py diff --git a/data.json b/data.json new file mode 100644 index 0000000..9df3ca6 --- /dev/null +++ b/data.json @@ -0,0 +1,112 @@ +[ + { + "source": "The Met", + "id": 572126, + "title": "Water Clock Decorated with a Baboon", + "date": "664–30 B.C.", + "parsed_year": 664, + "culture": "", + "description": "Gift of J. Pierpont Morgan, 1917", + "image_url": "https://images.metmuseum.org/CRDImages/eg/web-large/LC-17_194_2341_EGDP023756.jpg", + "image_url_hd": "https://images.metmuseum.org/CRDImages/eg/original/LC-17_194_2341_EGDP023756.jpg" + }, + { + "source": "The Met", + "id": 21971, + "title": "Wheellock Pistol", + "date": "ca. 1560–70", + "parsed_year": 1560, + "culture": "German, Augsburg", + "description": "Rogers Fund, 1904", + "image_url": "https://images.metmuseum.org/CRDImages/aa/web-large/LC-04_3_189-005.jpg", + "image_url_hd": "https://images.metmuseum.org/CRDImages/aa/original/LC-04_3_189-005.jpg" + }, + { + "source": "The Met", + "id": 4751, + "title": "Lantern clock", + "date": "ca. 1685", + "parsed_year": 1685, + "culture": "", + "description": "Gift of Mrs. J. Insley Blair, 1942", + "image_url": "https://images.metmuseum.org/CRDImages/ad/web-large/130080.jpg", + "image_url_hd": "https://images.metmuseum.org/CRDImages/ad/original/130080.jpg" + }, + { + "source": "The Met", + "id": 895523, + "title": "", + "date": "1691–1702", + "parsed_year": 1691, + "culture": "American", + "description": "Sansbury-Mills and Richard Hampton Jenrette American Funds, 2023", + "image_url": "https://images.metmuseum.org/CRDImages/ad/web-large/DP-29313-001.jpg", + "image_url_hd": "https://images.metmuseum.org/CRDImages/ad/original/DP-29313-001.jpg" + }, + { + "source": "The Met", + "id": 197652, + "title": "Wall clock (cartel) with movement of later date", + "date": "case ca. 1745–49; movement ca. 1756", + "parsed_year": 1745, + "culture": "", + "description": "Harris Brisbane Dick Fund, 1936", + "image_url": "https://images.metmuseum.org/CRDImages/es/web-large/DP-20003-001.jpg", + "image_url_hd": "https://images.metmuseum.org/CRDImages/es/original/DP-20003-001.jpg" + }, + { + "source": "The Met", + "id": 189954, + "title": "Bather", + "date": "ca. 1775–85", + "parsed_year": 1775, + "culture": "", + "description": "Gift of J. Pierpont Morgan, 1906", + "image_url": "https://images.metmuseum.org/CRDImages/es/web-large/5187.jpg", + "image_url_hd": "https://images.metmuseum.org/CRDImages/es/original/5187.jpg" + }, + { + "source": "The Met", + "id": 200662, + "title": "Seated girl", + "date": "ca. 1788", + "parsed_year": 1788, + "culture": "", + "description": "Bequest of Mary Stillman Harkness, 1950", + "image_url": "https://images.metmuseum.org/CRDImages/es/web-large/148037.jpg", + "image_url_hd": "https://images.metmuseum.org/CRDImages/es/original/148037.jpg" + }, + { + "source": "The Met", + "id": 5633, + "title": "Pier table", + "date": "1815–19", + "parsed_year": 1815, + "culture": "American", + "description": "Rogers Fund, 1953", + "image_url": "https://images.metmuseum.org/CRDImages/ad/web-large/DP109805.jpg", + "image_url_hd": "https://images.metmuseum.org/CRDImages/ad/original/DP109805.jpg" + }, + { + "source": "The Met", + "id": 14696, + "title": "Clock", + "date": "ca. 1882–85", + "parsed_year": 1882, + "culture": "American", + "description": "Purchase, William Cullen Bryant Fellows Gift, 1993", + "image_url": "https://images.metmuseum.org/CRDImages/ad/web-large/ADA6141.jpg", + "image_url_hd": "https://images.metmuseum.org/CRDImages/ad/original/ADA6141.jpg" + }, + { + "source": "The Met", + "id": 549190, + "title": "Clepsydra or water clock with squatting babooon", + "date": "4th century B.C.", + "parsed_year": null, + "culture": "", + "description": "Funds from various donors, 1886", + "image_url": "https://images.metmuseum.org/CRDImages/eg/web-large/86.1.93_EGDP015559.jpg", + "image_url_hd": "https://images.metmuseum.org/CRDImages/eg/original/86.1.93_EGDP015559.jpg" + } +] \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..1d73ef4 --- /dev/null +++ b/index.html @@ -0,0 +1,17 @@ + + + + + + Catalogue d'Horloges + + + + +
+ + + + + + \ No newline at end of file diff --git a/script.js b/script.js new file mode 100644 index 0000000..0ff114d --- /dev/null +++ b/script.js @@ -0,0 +1,88 @@ +const loadingDiv = document.getElementById('loading'); +const contentDiv = document.getElementById('content'); + +console.log(contentDiv); + +fetch('data.json') + .then(response => response.json()) + .then(data => { + console.log(data); + + // Masquer l'indicateur de chargement + if (loadingDiv) { + loadingDiv.style.display = 'none'; + } + + // Créez les pages + data.forEach(clock => { + const page = document.createElement('div'); + page.className = 'page'; + + // Conteneur principal pour l'horloge + const container = document.createElement('div'); + container.className = 'clock-container'; + + // titre + const title = document.createElement('h1'); + title.className = 'clock-title'; + title.textContent = clock.title || 'Horloge sans titre'; + + // DIV Image + const img = document.createElement('img'); + img.className = 'clock-image'; + img.src = clock.image_url_hd || clock.image_url || 'placeholder.jpg'; + img.alt = clock.title || 'Image d\'horloge'; + + // Détails + const details = document.createElement('div'); + details.className = 'clock-details'; + + // Date + const dateRow = document.createElement('div'); + dateRow.className = 'detail-row'; + dateRow.innerHTML = ` + Date: + ${clock.date || 'Non spécifiée'} + `; + + // Culture + const cultureRow = document.createElement('div'); + cultureRow.className = 'detail-row'; + cultureRow.innerHTML = ` + Culture: + ${clock.culture || 'Non spécifiée'} + `; + + // Description + const descRow = document.createElement('div'); + descRow.className = 'detail-row'; + descRow.innerHTML = ` + Description: + ${clock.description || 'Aucune description disponible'} + `; + + // Ajoutez les détails au conteneur + details.appendChild(dateRow); + details.appendChild(cultureRow); + details.appendChild(descRow); + + // Ajoutez le titre, l'image et les détails au conteneur principal + container.appendChild(title); + container.appendChild(img); + container.appendChild(details); + + // Ajoutez le conteneur principal à la page + page.appendChild(container); + + // Ajoutez la page au conteneur principal + contentDiv.appendChild(page); + }); + + // Appeler Paged.js pour générer les pages + PagedPolyfill.preview().catch(error => { + console.error('Erreur avec Paged.js :', error); + }); + }) + .catch(error => { + console.error('Erreur lors du chargement des données :', error); + }); \ No newline at end of file diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..d18ac0d --- /dev/null +++ b/styles.css @@ -0,0 +1,71 @@ +@page { + size: A4; /* Taille de la page */ + margin: 2cm; /* Marges de la page */ +} + +body { + font-family: 'Roboto', sans-serif; + line-height: 1.6; + color: #333; +} + +#loading { + text-align: center; + font-size: 1.2rem; + color: #666; + margin-top: 2rem; +} + +.page { + page-break-after: always; /* Force un saut de page après chaque élément */ + break-after: page; /* Compatibilité avec les navigateurs modernes */ +} + +.clock-container { + page-break-inside: avoid; /* Empêche les sauts de page à l'intérieur d'une horloge */ + break-inside: avoid; /* Compatibilité avec les navigateurs modernes */ +} + +.clock-image { + max-width: 80%; + max-height: 60vh; + object-fit: contain; + margin-bottom: 1.5rem; +} + +.clock-title { + font-family: 'Playfair Display', serif; + font-size: 1.8rem; + font-weight: 700; + margin-bottom: 0.5rem; + text-align: center; +} + +.clock-details { + width: 80%; + border-top: 1px solid #ddd; + padding-top: 1rem; +} + +.detail-row { + display: flex; + margin-bottom: 0.5rem; +} + +.detail-label { + font-weight: bold; + min-width: 120px; +} + +.detail-value { + flex-grow: 1; +} + +footer { + position: fixed; + bottom: 0; + width: 100%; + text-align: center; + font-size: 0.8rem; + color: #666; +} \ No newline at end of file diff --git a/themet.py b/themet.py new file mode 100644 index 0000000..8e7802b --- /dev/null +++ b/themet.py @@ -0,0 +1,55 @@ +import requests +import json +import time +import re + +query = "yes" +tags = "Clocks" +object_type = "Clock" +search_url = f"https://collectionapi.metmuseum.org/public/collection/v1/search?hasImages=true&q={query}&tags={tags}&objectType={object_type}" + +response = requests.get(search_url) +data = response.json() + +# Liste des IDs d'objets +object_ids = data['objectIDs'][:10] # Limitez à 10 objets pour éviter une surcharge + +objects = [] + +def extract_year(date_str): + if not date_str or date_str == "Unknown": + return None + match = re.search(r'\b(\d{3,4})\b', date_str) + if match: + return int(match.group(1)) + return None + +for obj_id in object_ids: + obj_url = f"https://collectionapi.metmuseum.org/public/collection/v1/objects/{obj_id}" + obj_data = requests.get(obj_url).json() + + if obj_data.get("primaryImageSmall"): + date_str = obj_data.get("objectDate", "") + parsed_year = extract_year(date_str) + + obj_entry = { + "source": "The Met", + "id": obj_data.get("objectID"), + "title": obj_data.get("title"), + "date": date_str, + "parsed_year": parsed_year, + "culture": obj_data.get("culture"), + "description": obj_data.get("creditLine"), + "image_url": obj_data.get("primaryImageSmall"), + "image_url_hd": obj_data.get("primaryImage") + } + objects.append(obj_entry) + + time.sleep(0.1) + +objects.sort(key=lambda x: x["parsed_year"] if x["parsed_year"] is not None else 9999) + +with open("data2.json", "w", encoding="utf-8") as f: + json.dump(objects, f, ensure_ascii=False, indent=2) + +print(f"{len(objects)} ✅")