Created
October 30, 2011 11:08
-
-
Save astrofrog/1325794 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import string | |
| import urllib | |
| from xml.etree.ElementTree import ElementTree | |
| from StringIO import StringIO | |
| search_author = "Goodman, A." | |
| base_url = '''http://adsabs.harvard.edu/cgi-bin/nph-abs_connect?db_key=AST&''' | |
| parameters = {} | |
| parameters['author'] = search_author.replace(',', '%2C') | |
| parameters['data_type'] = "SHORT_XML" | |
| parameters['jou_pick'] = "NO" | |
| parameters['start_month'] = "10" | |
| parameters['start_year'] = "2007" | |
| parameters['end_month'] = "10" | |
| parameters['end_year'] = "2011" | |
| query = string.join(["%s=%s" % (key, parameters[key]) | |
| for key in parameters], "&") | |
| f = urllib.urlopen(base_url + query) | |
| # Parse XML | |
| e = ElementTree() | |
| root = e.parse(StringIO(f.read())) | |
| count = {} | |
| # Loop over articles | |
| for record in root.getchildren(): | |
| # Loop over fields | |
| for field in record.getchildren(): | |
| # Look only at author tags | |
| if 'author' in field.tag: | |
| # Split into first and last name | |
| lastname, firstname = field.text.split(',')[0:2] | |
| # Keep only first initial of first name | |
| firstname = firstname.strip()[0] | |
| # Make author name into the form "Robitaille, T." | |
| fullname = lastname + ", " + firstname + "." | |
| # Add author to counter | |
| if fullname in count: | |
| count[fullname] += 1 | |
| else: | |
| count[fullname] = 1 | |
| # Print out final list | |
| for author in count: | |
| if search_author not in author: | |
| print author + ": " + str(count[author]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment