Skip to content

Automatic publications lists from UKADS

2010 January 8
by Steven

On this site my publications list is created automatically whenever it is viewed. This is possible using a little bit of php and the XML listing ability of the (UK) ADS server. I first developed this method to show the collected publications for all members of the University of Portsmouth’s Institute of Cosmology and Gravitation webpage.

My code, which you are welcome to adapt and use for your own purposes is given below. Note that if you are going to use this on a page that is accessed often then you should probably implement some form of caching.

Update (31 August 2010): the UKADS server was not being very reliable, so I’ve changed the script to now use the main ADS server.

Another update (also 31 August 2010): I discovered that using sort=ENTRY, rather than sort=NDATE gives a better sorting order, preventing recently published items which appeared on the arXiv a while ago from rising back up to the top.

Update (23 September 2010): discovered the code was putting “et al.” on the end of all author lists (and sometimes including an unnecessary ellipsis), fixed now.

Update (26 February 2012): for some reason the code stopped working with WordPress and Exec-PHP, and I could only get it to work again without user-defined functions.

<?php
//$ads_url = 'http://ukads.nottingham.ac.uk/';
$ads_url = 'http://adsabs.harvard.edu/';
$ads_url .= 'cgi-bin/nph-abs_connect?';
$ads_url .= 'db_key=AST&db_key=PRE&qform=AST&';
$ads_url .= 'start_nr=1&arxiv_sel=astro-ph&arxiv_sel=gr-qc&';
$ads_url .= 'start_mon=&start_year=&nr_to_return=100&start_nr=1&';
$ads_url .= 'jou_pick=ALL&article_sel=YES&ref_stems=&ALL&';
$ads_url .= 'sort=ENTRY&data_type=SHORT_XML&author=';

$n = 'Bamford, Steven P';
$names = array(urlencode($n));
$surnames = array('Bamford');

$ads_url .= implode('%0D%0A', $names);

$ads_url_normal = str_replace('SHORT_XML', 'SHORT', $ads_url);
echo 'Automatically retrieved from ADS.'."\n";

//Using normal php method
//$xmlstr = file_get_contents($ads_url);
//Using WordPress method:
$xmlstr = wp_remote_fopen($ads_url);

$xml = new SimpleXMLElement($xmlstr);

foreach ($xml->record as $record) {
    $nmax = 5;
    $n = 0;
    $m = 0;
    $limited = array();
    $showname = array();
    foreach($record->author as $a) {
        $ns = explode(',', $a);
        $surname = $ns[0];
        $showname = false;
        if ($surnames != null) {
            foreach ($surnames as $s) {
                if ($s == $surname) {
                  $surname = '' . $s . '';
                  $showname = true;
                  break;
                }
            }
        }
        if ($n < $nmax) {
            $limited[] = $surname;
            $m = $n;
        } else if ($showname) {
            if ($n > $m + 1) {
                $limited[] = '...';
            }
            $limited[] = $surname;
            $m = $n;
        }
        $n = $n + 1;
    }
    if ($n > $m + 1) {
        $limited[] = 'et al.';
    }
  $authors = implode(', ', $limited);
  $pubdate = explode(' ', $record->pubdate);
  $year = $pubdate[1];
  $link = '';
  foreach ($record->link as $l) {
    if ($l['type'] == 'ABSTRACT') {
      $link = $l->url;
      break;
    }
  }
  echo "\n-----\n";
  echo '[' . $record->title . '](' . $link . ")
\n"; echo $authors, ", ", $year, ",
\n", $record->journal, "\n"; } ?>
5 Responses leave one →
  1. January 9, 2010

    Neat!

    Now I just need to write some papers…

  2. January 10, 2010

    For the dummies: what is wp_remote_fopen() [line 57] and where would you get it?

  3. Steven permalink*
    January 10, 2010

    Thanks for the good question Bo!

    wp_remote_fopen() is a function provided by WordPress. It should ‘just work’ for WordPress users (assuming they have got php in posts working, e.g. using Exec-PHP.)

    For non-Wordpress users, I originally used the file_get_contents PHP function. Note that this will often require some permissions to be set in the PHP configuration.

    I’ve added the relevant line (commented out, which the code prettifier misleadingly capitalises) in the posted code.

  4. August 27, 2010

    Hi,

    thanks for sharing this, but I clcked on your publication list and it didn’t to work… lots of error messages.

    BTW, for the lazy people like me there is a RSS feed option on the arXiv (http://arxiv.org/help/rss). If you registers your “public author identifier” (I guess somewhere in your account settings) then there is a feed associated with your identifyer which you can use inside your website. See e.g. http://www.physi.ch/lukas/Publications.html 😉

    OK, enough for today, cheers, Lukas

  5. Steven permalink*
    August 31, 2010

    Thanks for noticing the problem, Lukas. The errors were because the UKADS server was down (I probably should put some kind of exception handling in one day). UKADS has been unreliable lately, so I’ve changed the code above and on my publications page over to the main ADS server.

    BTW back, the reason I don’t use the arXiv feed is that (as far as I know) it doesn’t provide full publication information (journal, volume, page). Not essential, but useful. That and just in case some papers don’t get put on astro-ph.

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS