Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Expose space open/closed status for RSS feed #4

Merged
merged 2 commits into from
Jun 3, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
%# vim: filetype=mason
<%doc>
Sat May 19 12:21:30 EDT 2012 - warewolf

Make space open/closed file persistent

</%doc>
<%attr>
breadcrumb => 'Home'
no_breadcrumbs => 1
</%attr>
<%once>
use File::Slurp qw( slurp );
my $status_flag_file = "/tmp/space-is-open";
</%once>

<%init>
open(my $status_fh,"<",$status_flag_file);
my $status = <$status_fh>;
chomp $status;
close $status_fh;
</%init>
<div class="hero-unit">
<img src="/images/NOVALabs-big.png" />
</div>
Expand Down Expand Up @@ -35,8 +49,10 @@ <h3><a href="/donate/" class="btn btn-large btn-inverse">Donate Now!</a></h3>
<div class="span5">
<h2>Current Status</h2>
<p style="font-size: 200%">Nova Labs is
% if ( -f "/tmp/space-is-open" ) {
% if ( $status eq "open" ) {
<span class="btn btn-success btn-large">OPEN</span>
% } elsif ( $status eq "closed") {
<span class="btn btn-danger btn-large">CLOSED</span>
% } else {
<span class="btn btn-danger btn-large">CLOSED</span>
% }
Expand Down
35 changes: 30 additions & 5 deletions status.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
%# vim: filetype=mason
<%doc>
Sat May 19 12:21:30 EDT 2012 - warewolf

Make space open/closed file persistent

</%doc>
<%args>
$status => ''
</%args>

<%once>
my $status_flag_file = "/tmp/space-is-open";
</%once>
<%init>
if ( $status ) {
# writing status
if ( defined($status)) && ( $status eq 'open' || $status eq 'closed' ) ) {
# params validated, safe to overwrite state file
open(my $status_fh,">",$status_flag_file);

if ( $status eq 'open' ) {
system( 'touch', '/tmp/space-is-open' );
} else {
system( 'rm', '-f', '/tmp/space-is-open' );
print $status_fh "open\n";
} elsif ($status eq 'closed'){
print $status_fh "closed\n";
} else { # catchall, default to closed
print $status_fh "closed\n";
}
close $status_fh;
} else {
# reading status, or status value was invalid.
open(my $status_fh,"<",$status_flag_file);
my $status = <$status_fh>;
close $status_fh;
chomp $status;
}
</%init>

<div class="hero-unit">
<p style="font-size: 500%">Current Status is
% if ( -f "/tmp/space-is-open" ) {
% if ( $status eq 'open') {
OPEN
% } elsif ($status eq 'closed'){
CLOSED
% } else {
CLOSED
% }
Expand Down
32 changes: 32 additions & 0 deletions status.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
%# vim: filetype=mason
<%init>
# set XML content type to make RSS feed readers happy
$r->content_type('application/xml');

# check presense of stauts flag file
my $status_flag_file = "/tmp/space-is-open";
open(my $status_fh,"<",$status_flag_file);
my $status = <$status_fh>;
chomp $status;

# we're under mod_perl, so adjusting the timezone can get hairy. Save and restore it.
my ($mtime) = (stat($status_flag_file))[9];
my @gmtime = gmtime($mtime);
my $date_change = strftime("%a, %d %b %Y %T GMT",@gmtime);
</%init><%once>
use POSIX qw(strftime);
</%once><?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>Nova-Labs open/closed status feed</title>
<link>http://www.nova-labs.org/</link>
<description>Real-time status feed of nova-labs open/closed status</description>
<language>en</language>
<docs>http://www.nova-labs.org/</docs>
<item>
<pubDate><%$date_change%></pubDate>
<title>Nova-Labs is now <%$status%>!</title>
<link>http://www.nova-labs.org</link>
</item>
</channel>
</rss>