github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

fishy / scripts

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 1
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (2)
  • Wiki (2)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

various scripts wrote by me — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

 * v0.3 of projtags, can add commands now 
Yuxuan 'fishy' Wang (author)
Fri Jul 31 02:36:48 -0700 2009
commit  2b86184edfad6baae7a0eb259aae8eaaa15d9482
tree    8fde714383daead4d44c83b7b0e24f20e327aa4b
parent  08bd4d75fa8e086dc53af0a3cadcce2605706d7f
scripts / ga-rss.php ga-rss.php
100644 96 lines (89 sloc) 2.568 kb
edit raw blame history
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/*
* Garfield comic by Jim Davis
* RSS wrapper by fishy ( http://yhsif.com )
* RSS wrapper source (what you are reading now) released under GPL v3
*/
 
function shift_days($date, $days) {
return mktime(0, 0, 0, date("m", $date), date("d", $date) + $days, date("Y", $date));
}
 
function date2url($date) {
return 'http://images.ucomics.com/comics/ga/' . date("Y", $date) . '/ga' . date("ymd", $date) . '.gif';
}
 
function find_next_available_date($date, $cachedate) {
$day = $date;
$fp = fopen("/dev/null", "w");
$i = 0;
while(1) {
if($day <= $cachedate)
break;
$i++;
if($i > 3) {
$i--;
break;
}
$ch = curl_init(date2url($day));
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($code == 200)
break;
$day = shift_days($day, -1);
}
fclose($fp);
print("<!-- fetched $i url(s) -->\n");
return $day;
}
 
header("Content-Type: application/xml");
header('Content-Disposition: inline; filename="rss2.xml"');
print("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
 
$cache_file = ".rss-cache";
$count = intval($_REQUEST['n']);
if($count == 0)
$count = 10;
$lastcheck = 0;
$cacheday = 0;
if(file_exists($cache_file)) {
$handle = fopen($cache_file, "r");
list($lastcheck, $cacheday) = fscanf($handle, "%u\t%u\n");
fclose($handle);
}
$lastday = $cacheday;
if($cacheday == 0 || $lastcheck == 0 || (time() - $lastcheck) > 60*30) {
$lastday = mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"));
$lastday = find_next_available_date($lastday, $cacheday);
$handle = fopen($cache_file, "w");
fwrite($handle, sprintf("%u\t%u\n", time(), $lastday));
fclose($handle);
} else
print("<!-- cache hit -->\n");
?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Garfield daily comic</title>
<link>http://www.garfield.com/comics/comics_todays.html</link>
<description>The daily comic of Garfield, from ucomics.com</description>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<atom:link href="http://selif.yhsif.com/ga-rss.php" rel="self" type="application/rss+xml" />
<?php
for($i = 0; $i < $count; $i++) {
$url = date2url($lastday);
$title = "Garfield comic " . date("Y-m-d", $lastday);
$date = date("r", $lastday);
$desc = "<![CDATA[<img src=\"$url\" />]]>";
print <<<EOLAST
<item>
<title>$title</title>
<link>$url</link>
<guid>$url</guid>
<pubDate>$date</pubDate>
<description>$desc</description>
</item>
 
EOLAST;
$lastday = shift_days($lastday, -1);
}
?>
</channel>
</rss>
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server