Skip to content

Instantly share code, notes, and snippets.

@dsager

dsager/get_gists.php

Created Sep 14, 2014
Embed
What would you like to do?
Small script to fetch a list of a user's Gists on GitHub
<?php
/**
* Small script to fetch a list of a user's Gists on GitHub
*
* Copyright (c) 2014 Daniel Sager
* License: MIT, https://gist.github.com/dsager/0edcbf806b5b86e78455#file-2014
*/
date_default_timezone_set('UTC');
$url = 'https://gist.github.com/dsager.atom';
$feed_content = file_get_contents($url);
$feed = new SimpleXMLElement($feed_content);
$links = array();
foreach ($feed->entry as $entry) {
$time = strtotime($entry->updated);
$links[] = array(
'id' => (string) $entry->id,
'title' => (string) $entry->title,
'url' => (string) $entry->link['href'],
'time' => $time,
'date' => date('F jS, Y', $time)
);
}
usort($links, function ($a, $b) { return $b['time'] > $a['time']; });
echo json_encode($links);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment