Skip to content

Instantly share code, notes, and snippets.

@kputnam
Last active November 4, 2015 06:25
Show Gist options
  • Save kputnam/5af49158d81650374ecb to your computer and use it in GitHub Desktop.
Save kputnam/5af49158d81650374ecb to your computer and use it in GitHub Desktop.
Formats and prints recent StackOverflow careers postings to console
#!/usr/bin/perl
use URI::Escape;
my $url = 'http://careers.stackoverflow.com/jobs/feed?searchTerm=';
# Either use search terms given as command-line arguments, or use default terms
my $q = join('+', map { uri_escape($_); } (@ARGV > 0) ?
@ARGV : ('-.net', '-css', '-c#', '-android', '-php', '-ios', '-vb.net', '-excel' ));
# Read XML from child process
open(INPUT, "-|") || exec "curl -# '$url$q' | xmllint --format -";
# Reopen STDOUT so output is sent to pager
unless (-t STDOUT) {
my $pager = $ENV{PAGER} || '/usr/bin/less';
open(STDOUT, "| $pager");
}
while (<INPUT>) {
s/&lt;/</g;
s/&gt;/>/g;
s/&amp;/&/g;
s/&amp;/&/g;
s/&nbsp;/ /g;
s/&copy;/(C)/g;
s/&trade;/(TM)/g;
s/&pound;/£/g;
s/&euro;/€/g;
s/&rdquo;/"/g;
s/&ldquo;/"/g;
s/&bdquo;/"/g;
s/&rsquo;/'/g;
s/&lsquo;/'/g;
s/&ndash;/-/g;
s/&mdash;/-/g;
s/\xc2\x92/'/g;
s/&hellip;/.../g;
s/&szlig;/ß/g;
s/&(.)uml;/$1/g;
s/&(.)circ;/$1/g;
s/&(.)ring;/$1/g;
s/&(.)slash;/$1/g;
s/&(.)tilde;/$1/g;
s/&(.)acute;/$1/g;
s/&(.)cedil;/$1/g;
s/&(.)grave;/$1/g;
s/<p>/\n/g;
s/<\/p>/\n/g;
s/<br>/\n/g;
s/<br \/>/\n/g;
s/<li>\s*/* /g;
s/<(a|b|em|strong|span|ul|ol)( [^>]*)?>//g;
s/<\/(a|b|em|strong|span|li|ul|ol)>//g;
s/\n\n+/\n\n/g;
s/^<\/description/ <\/description/mg;
print $_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment