-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsearch_hydrus.py
49 lines (40 loc) · 1.6 KB
/
search_hydrus.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
#!/usr/bin/env python3
# Copyright (C) 2021 cryzed
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pprint
import sys
import os
import time
import dotenv
import hydrus_api
import hydrus_api.utils
ERROR_EXIT_CODE = 1
REQUIRED_PERMISSIONS = {
hydrus_api.Permission.IMPORT_URLS,
hydrus_api.Permission.IMPORT_FILES,
hydrus_api.Permission.ADD_TAGS,
hydrus_api.Permission.SEARCH_FILES,
hydrus_api.Permission.MANAGE_PAGES,
}
dotenv.load_dotenv()
api_key = os.getenv("HYDRUS_ACCESS_KEY")
client = hydrus_api.Client(api_key)
print(f"Client API version: v{client.VERSION} | Endpoint API version: v{client.get_api_version()['version']}")
if not hydrus_api.utils.verify_permissions(client, REQUIRED_PERMISSIONS):
print("The API key does not grant all required permissions:", REQUIRED_PERMISSIONS)
sys.exit(ERROR_EXIT_CODE)
all_file_ids = client.search_files([sys.argv[1:]])
for file_ids in hydrus_api.utils.yield_chunks(all_file_ids, 100):
print(client.get_file_metadata(file_ids=file_ids))