A Little Off Code, Computers, Photography and Guns

4May/090

GitHub Repositories Feed

I noticed at the bottom of the page on GitHub that there was an API link. I took a look at it and found it to be pretty interesting, it's actually really simple to use. You can export in xml, json and yaml. I thought to myself: "Hey it'd be great if I could put a repositories feed in the sidebar of my blog here!".

So I took a look at the JSON output since it's small and really easy to deserialize in php, so I wrote up a quick little php script on the server I'm hosting my blog at that will spit out an RSS feed of the repositories I've created on GitHub. The code is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?="<?xml version=\"1.0\"?>"?>
<rss version="2.0">
  <channel>
    <title>BeMasher's GitHub Repositories</title>
    <link>http://github.com/bemasher</link>
    <description>BeMasher's GitHub Repositories</description>
    <language>en-us</language>
    <pubDate><?=date("D, d M Y G:i:s e")?></pubDate>
    <lastBuildDate><?=date("D, d M Y G:i:s e")?></lastBuildDate>
    <webMaster>bemasher@bemasher.net</webMaster>
    <ttl>5</ttl>

<?php
    $data = file_get_contents("http://github.com/api/v2/json/repos/show/bemasher");
    $data = json_decode($data, true);
   
    $today = date("D, d M Y G:i:s e");
   
    foreach($data["repositories"] as $repository) {
echo <<<ITEM
    <item>
        <title>{$repository["name"]}</title>
        <link>{$repository["url"]}</link>
        <description>{$repository["description"]}</description>
        <pubDate>$today</pubDate>
        <guid>{$repository["url"]}</guid>
    </item>

ITEM
;
    }
?>
    </channel>
</rss>

And if you look to the right you can see the RSS Widget in action displaying the output of the script. Cool huh?

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

(required)

No trackbacks yet.