summaryrefslogtreecommitdiff
path: root/retronews
diff options
context:
space:
mode:
Diffstat (limited to 'retronews')
-rw-r--r--retronews/__init__.py8
-rw-r--r--retronews/retronews.py50
2 files changed, 58 insertions, 0 deletions
diff --git a/retronews/__init__.py b/retronews/__init__.py
new file mode 100644
index 0000000..ae3b518
--- /dev/null
+++ b/retronews/__init__.py
@@ -0,0 +1,8 @@
+from .retronews import (
+ convert_date,
+ parse_url,
+ doc_info,
+ page_info,
+ thumbnail_url,
+ tile_url
+) \ No newline at end of file
diff --git a/retronews/retronews.py b/retronews/retronews.py
new file mode 100644
index 0000000..9e80c58
--- /dev/null
+++ b/retronews/retronews.py
@@ -0,0 +1,50 @@
+import re
+import requests
+
+MONTHS = dict(
+ jan=1,
+ feb=2,
+ mar=3,
+ apr=4,
+ may=5,
+ jun=6,
+ jul=7,
+ juillet=7,
+ aout=8,
+ aug=8,
+ sep=9,
+ oct=10,
+ nov=11,
+ novembre=11, # https://www.retronews.fr/journal/mercure-de-france/15-novembre-1905/118/2617647/1
+ dec=12
+)
+
+
+def convert_date(s: str) -> tuple[str, str, str]:
+ m = re.match(r'^(\d{2})-(.*?)-(\d{4})$', s).groups()
+ year = m[2]
+ month = '%02d' % MONTHS[m[1]]
+ day = m[0]
+ return year, month, day
+
+
+def parse_url(url: str) -> tuple:
+ return re.search(r'/(?:[\-\d\w]+)/([^/]+)/(\d+)/(\d+)/', url).groups()
+
+
+def doc_info(collection_id, doc_id):
+ r = requests.get(f'https://pv5web.retronews.fr/api/document/{collection_id}/{doc_id}')
+ return r.json()
+
+
+def page_info(collection_id, doc_id, page):
+ r = requests.get(f'https://pv5web.retronews.fr/api/document/{collection_id}/{doc_id}/page/{page}/')
+ return r.json()
+
+
+def thumbnail_url(collection_id, doc_id, page) -> str:
+ return f'https://pv5web.retronews.fr/api/document/{collection_id}/{doc_id}/page/{page}/thumbnail'
+
+
+def tile_url(collection_id, doc_id, page, v_tile, h_tile) -> str:
+ return f'https://pv5web.retronews.fr/api/document/{collection_id}/{doc_id}/page/{page}/tile/{h_tile}/{v_tile}/0'