-
Notifications
You must be signed in to change notification settings - Fork 2
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 skybristol/dev
Update master
- Loading branch information
Showing
7 changed files
with
175 additions
and
57 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
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
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,11 +6,18 @@ | |
|
||
cmd_sb = pylinkedcmd.pylinkedcmd.Sciencebase() | ||
|
||
usgs_staff = cmd_sb.get_active_usgs_staff() | ||
#usgs_staff = cmd_sb.get_active_usgs_staff() | ||
usgs_staff = cmd_sb.get_staff_by_email(["[email protected]","[email protected]"]) | ||
|
||
sbid_list_for_query = str([i["identifier_sbid"] | ||
for i in usgs_staff]).replace('"', "'").replace("[", "(").replace("]", ")") | ||
|
||
df_people = pd.DataFrame(usgs_staff) | ||
df_people = df_people.drop_duplicates(subset='identifier_sbid', keep="first") | ||
df_people.loc[df_people['identifier_orcid'].duplicated(), 'identifier_orcid'] = np.NaN | ||
try: | ||
df_people.loc[df_people['identifier_orcid'].duplicated(), 'identifier_orcid'] = np.NaN | ||
except: | ||
pass | ||
df_people.loc[df_people['identifier_email'].duplicated(), 'identifier_email'] = np.NaN | ||
|
||
pg_user = os.environ["PG_USER"] | ||
|
@@ -22,7 +29,7 @@ | |
pg_engine = create_engine(f'postgresql://{pg_user}:{pg_pass}@{pg_host}:{pg_port}/{pg_db}') | ||
|
||
with pg_engine.connect() as con: | ||
con.execute("DELETE FROM people") | ||
con.execute(f"DELETE FROM people where identifier_sbid IN {sbid_list_for_query}") | ||
con.close() | ||
|
||
df_people.to_sql( | ||
|
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,45 @@ | ||
import sciencebasepy | ||
import pylinkedcmd | ||
from joblib import Parallel, delayed | ||
import tqdm | ||
from sqlalchemy import create_engine | ||
import pandas as pd | ||
import os | ||
|
||
cmd_sb = pylinkedcmd.pylinkedcmd.Sciencebase() | ||
cmd_isaid = pylinkedcmd.pylinkedcmd.Isaid() | ||
|
||
orgs = cmd_isaid.get_organizations() | ||
print(len(orgs)) | ||
|
||
org_summaries = list() | ||
|
||
def accumulator(identifier): | ||
org_summary = cmd_sb.get_sb_org(identifier) | ||
if org_summary is not None: | ||
org_summaries.append(org_summary) | ||
|
||
|
||
Parallel(n_jobs=4, prefer="threads")( | ||
delayed(accumulator) | ||
( | ||
identifier | ||
) for identifier in tqdm.tqdm([o["organization_uri"] for o in orgs]) | ||
) | ||
|
||
if len(org_summaries) > 0: | ||
pg_user = os.environ["PG_USER"] | ||
pg_pass = os.environ["PG_PASS"] | ||
pg_host = os.environ["PG_HOST"] | ||
pg_port = os.environ["PG_PORT"] | ||
pg_db = os.environ["PG_DB"] | ||
|
||
pg_engine = create_engine(f'postgresql://{pg_user}:{pg_pass}@{pg_host}:{pg_port}/{pg_db}') | ||
|
||
pd.DataFrame(org_summaries).to_sql( | ||
"organizations", | ||
pg_engine, | ||
index=False, | ||
if_exists="replace", | ||
chunksize=1000 | ||
) |
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
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
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 |
---|---|---|
|
@@ -18,7 +18,8 @@ | |
'validators', | ||
'pydash', | ||
'beautifulsoup4', | ||
'nltk' | ||
'nltk', | ||
'jsonbender' | ||
] | ||
|
||
setup_requirements = [ ] | ||
|