-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from OKN-CollabNext/institution-nodes
Use real data from OpenAlex for Institutions
- Loading branch information
Showing
8 changed files
with
248 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,7 @@ __pycache__/ | |
.venv/ | ||
|
||
# Ignore vscode settings | ||
.vscode/ | ||
.vscode/ | ||
|
||
# Ignore dot env files | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,14 @@ You can then install project dependencies as follows: | |
poetry install | ||
``` | ||
|
||
You need a `.env` file to store secrets as follows: | ||
|
||
``` | ||
[email protected] | ||
``` | ||
|
||
The OPENALEX_EMAIL secret is used to [speed up calls](https://docs.openalex.org/how-to-use-the-api/api-overview) to the OpenAlex REST API. | ||
|
||
## Running | ||
|
||
This project uses [Observable Framework](https://observablehq.com/framework/). You can run the site locally as follows | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import json | ||
import os | ||
|
||
import pyalex | ||
from dotenv import load_dotenv | ||
from pyalex import Institutions | ||
|
||
# Load Secrets | ||
load_dotenv() | ||
|
||
# Initialize the pyalex client | ||
pyalex.config.email = os.getenv("OPENALEX_EMAIL") | ||
|
||
# Get 5 random institutions | ||
institutions = [Institutions().random() for _ in range(5)] | ||
|
||
# Gather associated institutions | ||
associated_institutions = [ | ||
y for x in institutions for y in x["associated_institutions"] | ||
] | ||
|
||
# Combine all institutions | ||
all_institutions = [*institutions, *associated_institutions] | ||
|
||
# Create nodes | ||
nodes = [{"id": x["id"], "label": x["display_name"]} for x in all_institutions] | ||
|
||
# Create associated institution edges | ||
edges = [ | ||
{"id": x["id"], "start": x["id"], "end": y["id"], "label": "ASSOCIATED"} | ||
for x in institutions | ||
for y in x["associated_institutions"] | ||
] | ||
|
||
|
||
print(json.dumps({"nodes": nodes, "edges": edges})) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters