-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen_source_dois.py
More file actions
36 lines (32 loc) · 1.11 KB
/
open_source_dois.py
File metadata and controls
36 lines (32 loc) · 1.11 KB
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
#!/usr/bin/env python3
import os
import json
import webbrowser
def main():
# Path to the bioindustrial_park JSON files
base_dir = os.path.join(os.path.dirname(__file__), 'exported_flowsheets', 'bioindustrial_park')
if not os.path.isdir(base_dir):
print(f"Directory not found: {base_dir}")
return
# Iterate over all JSON files in directory
for entry in os.listdir(base_dir):
if not entry.lower().endswith('.json'):
continue
file_path = os.path.join(base_dir, entry)
try:
with open(file_path, 'r', encoding='utf-8') as f:
data = json.load(f)
except Exception as e:
print(f"Failed to read {file_path}: {e}")
continue
# Extract source_doi from metadata
metadata = data.get('metadata', {})
doi = metadata.get('source_doi')
if doi:
url = f"https://doi.org/{doi}"
print(f"Opening {url} for {entry}")
webbrowser.open_new_tab(url)
else:
print(f"No source_doi field found in {entry}")
if __name__ == "__main__":
main()