Skip to content

Instantly share code, notes, and snippets.

@ColinTalbert
Last active January 24, 2018 16:59
Show Gist options
  • Save ColinTalbert/57b225f53758299ff1dc5bc16addae84 to your computer and use it in GitHub Desktop.
Save ColinTalbert/57b225f53758299ff1dc5bc16addae84 to your computer and use it in GitHub Desktop.
SB user ID lookup
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Getting the SB person Id, Display name and Organization using pandas:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"email = \"talbertc@usgs.gov\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"url = \"https://www.sciencebase.gov/directory/people/list?format=html&email={}\".format(email.replace('@', '%40'))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Unnamed: 0</th>\n",
" <th>Id</th>\n",
" <th>Display Name</th>\n",
" <th>URL</th>\n",
" <th>Email</th>\n",
" <th>Organization</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>NaN</td>\n",
" <td>10199</td>\n",
" <td>Colin Talbert</td>\n",
" <td>NaN</td>\n",
" <td>talbertc@usgs.gov</td>\n",
" <td>Fort Collins Science Center</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Unnamed: 0 Id Display Name URL Email \\\n",
"0 NaN 10199 Colin Talbert NaN talbertc@usgs.gov \n",
"\n",
" Organization \n",
"0 Fort Collins Science Center "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.read_html(url)[0]\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10199"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.Id[0]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### But if you want the full contact info back you can get json back that contains additional info"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import json"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'_classSimpleName': 'UsgsPerson',\n",
" 'active': True,\n",
" 'description': None,\n",
" 'displayName': 'Colin Talbert',\n",
" 'displayText': 'Colin Talbert',\n",
" 'distinguishedName': 'CN=Colin Talbert,OU=Fort Collins,OU=Users,OU=FortCollinsCO-B,OU=CR,DC=gs,DC=doi,DC=net',\n",
" 'email': 'talbertc@usgs.gov',\n",
" 'extensions': {'personExtension': {'cellPhone': None,\n",
" 'firstName': 'Colin',\n",
" 'generationalQualifier': None,\n",
" 'jobTitle': 'Ecologist',\n",
" 'lastName': 'Talbert',\n",
" 'middleName': None,\n",
" 'orcId': None,\n",
" 'organization': {'_classSimpleName': 'UsgsOrganization',\n",
" 'displayText': 'Fort Collins Science Center',\n",
" 'id': 17368},\n",
" 'organizationDisplayText': 'Fort Collins Science Center',\n",
" 'organizationId': 17368,\n",
" 'personalTitle': None,\n",
" 'professionalQualifier': None,\n",
" 'supervisor': {'_classSimpleName': 'UsgsPerson',\n",
" 'displayText': 'Tim Kern',\n",
" 'id': 5432},\n",
" 'supervisorDisplayText': 'Tim Kern',\n",
" 'supervisorId': 5432,\n",
" 'username': 'talbertc@usgs.gov'},\n",
" 'usgsPersonExtension': {'buildingCode': 'KBA',\n",
" 'employeeId': 59787,\n",
" 'employeeType': 'EMPLOYEE',\n",
" 'endOccupationalSeries': None,\n",
" 'endOrgCode': None,\n",
" 'endYear': None,\n",
" 'orgCode': 'GGCMRB0000',\n",
" 'startOccupationalSeries': None,\n",
" 'startOrgCode': None,\n",
" 'startYear': None}},\n",
" 'firstName': 'Colin',\n",
" 'id': 10199,\n",
" 'jobTitle': 'Ecologist',\n",
" 'lastName': 'Talbert',\n",
" 'link': {'href': 'https://www.sciencebase.gov/directory/person/10199',\n",
" 'rel': 'self'},\n",
" 'links': [{'rel': 'self',\n",
" 'url': 'https://www.sciencebase.gov/directory/person/10199'}],\n",
" 'name': 'Colin Talbert/BRD/USGS/DOI',\n",
" 'note': None,\n",
" 'orcId': '0000-0002-9505-1876',\n",
" 'organization': {'displayText': 'Fort Collins Science Center', 'id': 17368},\n",
" 'permissions': {'read': {'acl': ['ROLE:ScienceBase_DataAdmin',\n",
" 'ROLE:ScienceBase_Directory_DataAdmin']},\n",
" 'write': {'acl': ['ROLE:ScienceBase_DataAdmin',\n",
" 'ROLE:ScienceBase_Directory_DataAdmin']}},\n",
" 'primaryLocation': {'areaCode': '970',\n",
" 'building': 'NRRC Bldg C',\n",
" 'buildingCode': 'KBA',\n",
" 'description': None,\n",
" 'faxPhone': '9702269230',\n",
" 'id': 10872,\n",
" 'mailAddress': {'city': 'Fort Collins',\n",
" 'country': 'USA',\n",
" 'line1': '2150 Centre Avenue, Building C',\n",
" 'line2': None,\n",
" 'mailStopCode': None,\n",
" 'state': 'CO',\n",
" 'zip': '80526-8118'},\n",
" 'name': 'Colin Talbert/BRD/CONT/USGS/DOI - Primary Location',\n",
" 'phone': '9702269425',\n",
" 'shortName': None,\n",
" 'streetAddress': {'city': 'Fort Collins',\n",
" 'country': None,\n",
" 'line1': '2150 Centre Avenue Bldg C',\n",
" 'line2': None,\n",
" 'mailStopCode': None,\n",
" 'state': 'CO',\n",
" 'zip': '80526'}},\n",
" 'richDescriptionHtml': None,\n",
" 'type': 'person',\n",
" 'url': None,\n",
" 'username': 'talbertc@usgs.gov'}"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"person_0 = json.loads(requests.get(url+'&format=json').text)['people'][0]\n",
"person_0"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment