-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_from_museumplus.py
50 lines (41 loc) · 1.25 KB
/
export_from_museumplus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import museumpy
import requests
from dotenv import load_dotenv, find_dotenv
import os
load_dotenv(find_dotenv())
user = os.getenv('MP_USER')
pw = os.getenv('MP_PASS')
s = requests.Session()
s.auth = (user, pw)
client = museumpy.MuseumPlusClient(
base_url='https://mpzurichrietberg.zetcom.com/MpWeb-mpZurichRietberg',
session=s
)
exports = client.exports(module='ObjectGroup')
# find a csv export
csv_export_id = None
for export in exports:
if export['extension'] == 'csv':
csv_export_id = export['id']
break
print(f"CSV-Export ID: {csv_export_id}")
# export all
all_csv_path = client.module_export(csv_export_id, module='ObjectGroup')
print(f"Full CSV export: {all_csv_path}")
# export with filter
filtered_module_export_path = client.module_export(
csv_export_id,
field='OgrNameTxt',
value='Himmelheber-Fotoarchiv (Furbo)',
module='ObjectGroup'
)
print(f"Filtered CSV: {filtered_module_export_path}")
# export single item
result = client.search(
field='OgrNameTxt',
value='Himmelheber-Fotoarchiv (Furbo)',
module='ObjectGroup'
)[0]
item_id = result['raw']['moduleItem']['id']
single_item_path = client.module_item_export(item_id, csv_export_id, module='ObjectGroup')
print(f"Single item export: {single_item_path}")