-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaviary_api_get_by_id.py
55 lines (39 loc) · 1.68 KB
/
aviary_api_get_by_id.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
51
52
53
54
55
##############################################################################################
# desc: connect to the Aviary API and get item (collection resource, resource, media) metadata
# exploritory / proof-of-concept code
# usage: python3 aviary_api_get_by_id.py --server ${aviary_server_name} --id ${resource_id} --type r
# license: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
# date: June 15, 2022
##############################################################################################
# Proof-of-concept only
from getpass import getpass
import argparse
import logging
from aviary import api as aviaryApi
#
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('--server', required=True, help='Servername.')
parser.add_argument('--id', required=True, help='id.')
parser.add_argument('--type', required=True, help='One letter character for type [c]ollection resources, [r]esource, [m]edia.')
parser.add_argument('--logging_level', required=False, help='Logging level.', default=logging.DEBUG)
return parser.parse_args()
#
def process(args, session):
if args.type == 'c':
item = aviaryApi.get_collection_resources(args, session, args.id)
elif args.type == 'r':
item = aviaryApi.get_resource_item(args, session, args.id)
elif args.type == 'm':
item = aviaryApi.get_media_item(args, session, args.id)
print(item)
#
def main():
args = parse_args()
logging.basicConfig(level=args.logging_level)
username = input('Username:')
password = getpass('Password:')
session = aviaryApi.init_session(args, username, password)
process(args, session)
if __name__ == "__main__":
main()