User:Smallman12q/Scripts/New York Times Citation

I have realized that the NYT now has an [http://developer.nytimes.com/docs/article_search_api#h3-data-fields article search API], and that it is probably best to use that.

The following is a simple php script that can create a citation by scraping NYT.

/**

* @author Smallman

* @copyright 2010

* @license Public Domain

* @version 1.0.0

*/

$url = 'http://www.nytimes.com/';//the url

$citenewstext;//the variable where the template info will be stored

$tags = get_meta_tags($url);//get the meta tags

//build the citenewstext

$citenewstext = "{{cite news\n";

$citenewstext .= "|title= ".$tags['hdl']."\n";

$citenewstext .= "|author= ".$tags['byl']."\n";//remove the By and correct case later

$citenewstext .= "|url= ".$url."\n";

$citenewstext .= "|newspaper= The New York Times\n";

$citenewstext .= "|publisher = ".$tags['cre']."\n";

$citenewstext .= "|location = ".$tags['geo']."\n";

$citenewstext .= "|id= articleid".$tags['articleid']."\n";

$citenewstext .= "|date= ".$tags['dat']."\n";

$citenewstext .= "|accessdate= ".date('d-m-Y')."\n";//you can change format

$citenewstext .= " }}";

//send it back

echo $citenewstext;

exit;

//resources

//http://www.php.net/manual/en/function.time.php

//http://php.net/manual/en/function.get-meta-tags.php

//https://secure.wikimedia.org/wikipedia/en/wiki/Template:Cite_news

?>

Gives a sample result of ...

{{cite news |title= Paperwork Hinders Airlifts of Ill Haitian Children |author= By IAN URBINA |url= http://www.nytimes.com/2010/02/09/world/americas/09airlift.html |newspaper= The New York Times |publisher = The New York Times |location = Haiti |id= articleid1247466931716 |date= February 9, 2010 |accessdate= 08-01-2010 }}

which looks like...

{{cite news |title= Paperwork Hinders Airlifts of Ill Haitian Children |author= By IAN URBINA |url= http://www.nytimes.com/2010/02/09/world/americas/09airlift.html |newspaper= The New York Times |publisher = The New York Times |location = Haiti |id= articleid1247466931716 |date= February 9, 2010 |accessdate= 08-01-2010 }}

Related Discussions