From 6f116ca59eef1fac8e16535cce3fad6c3b63ff69 Mon Sep 17 00:00:00 2001 From: Nick White Date: Sat, 7 Aug 2010 12:45:13 +0100 Subject: Reorganise software section --- software/scripts/encrypt-if-possible.sh | 26 +++++++++ software/scripts/fetchdnow.sh | 93 +++++++++++++++++++++++++++++++++ software/scripts/filenonpersonalmail.rc | 21 ++++++++ software/scripts/gatherflaggedmail.sh | 32 ++++++++++++ software/scripts/getlwn.py | 63 ++++++++++++++++++++++ software/scripts/index.txt | 82 +++++++++++++++++++++++++++++ software/scripts/remove-links.js | 31 +++++++++++ 7 files changed, 348 insertions(+) create mode 100644 software/scripts/encrypt-if-possible.sh create mode 100644 software/scripts/fetchdnow.sh create mode 100644 software/scripts/filenonpersonalmail.rc create mode 100644 software/scripts/gatherflaggedmail.sh create mode 100644 software/scripts/getlwn.py create mode 100644 software/scripts/index.txt create mode 100644 software/scripts/remove-links.js (limited to 'software/scripts') diff --git a/software/scripts/encrypt-if-possible.sh b/software/scripts/encrypt-if-possible.sh new file mode 100644 index 0000000..36e15cb --- /dev/null +++ b/software/scripts/encrypt-if-possible.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# Copyright 2009 Nick White +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# See for a copy of the GNU General +# Public License. +# +# This script creates a list of commands for mutt, to autoencrypt +# every email for which we have a key +# +# To use this in mutt, add the following to your ~/.muttrc: +# source encrypt-if-possible.sh| + +gpg --list-keys | sed \ + -e '/@/!d' \ + -e 's/\(.*\)<\(.*\)>/\2/g' \ + -e 's/\(.*\)/send-hook \1 "set crypt_autoencrypt = yes"/g' diff --git a/software/scripts/fetchdnow.sh b/software/scripts/fetchdnow.sh new file mode 100644 index 0000000..990a2dc --- /dev/null +++ b/software/scripts/fetchdnow.sh @@ -0,0 +1,93 @@ +#!/bin/bash +# Copyright 2008 Nick White +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# See for a copy of the GNU General +# Public License. + +function usage +{ + echo "Usage: dnow [-c codec] [-f outfile]" + echo " codec may be ogg, flac or mp3" +} + +# Get Dates # +year=$(date +%Y) +month=$(date +%m) +monthname=$(date +%B) +day=$(date +%d) +dayunpadded=$(date +%-e) + +# Set Defaults # +title="Democracy Now!" +titleshort="Democracy_Now" +codec="ogg" +podcastdir=~/feeds + +while [ "$1" != "" ]; do + case $1 in + -c | --codec ) shift + codec=$1 + ;; + -f | --file ) shift + outfile=$1 + ;; + -h | --help ) usage + exit + ;; + * ) usage + exit + ;; + esac + shift +done + +downfile=dn$year-$month$day-1.$codec + +url=http://www.archive.org/download/dn$year-$month$day/$downfile + +downdir=$podcastdir/$year-$month-$dayunpadded + +# if the file already exists, exit +if [ -f "$downdir/$downfile" ]; then + echo "download file already exists" + exit 1 +fi + +echo "url is $url" + +mkdir -p "$downdir" +wget --quiet --directory-prefix="$downdir" $url + +# check that it's audio data, not a 404, & if necessary delete +if [ -f "$downdir/404.php" ]; then + find "$downdir" -iname "404.php*" -type f -exec rm -f {} \; + echo "404, sorry" + exit 1 +elif [ -z "$(file $downdir/$downfile|grep audio)" ]; then + rm "$downdir/$downfile" + echo "download wasn't audio" + exit 1 +fi + +# tag the newly downloaded file +vorbiscomment -w "$downdir/$downfile" -t "ARTIST=$title" -t "TITLE=$day $monthname $year" -t "GENRE=News" -t "DATE=$year" + +# create directories and links to integrate with GoldenPod's directory structure +catdir=$podcastdir/catalogue/$titleshort + +mkdir -p "$catdir" + +ln -s "$downdir/$downfile" "$podcastdir/catalogue/All/" +ln -s $downdir/$downfile "$catdir/" +ln -sf $downdir/$downfile "$catdir/latest.$codec" +ln -sfn $downdir "$podcastdir/latest" diff --git a/software/scripts/filenonpersonalmail.rc b/software/scripts/filenonpersonalmail.rc new file mode 100644 index 0000000..a446177 --- /dev/null +++ b/software/scripts/filenonpersonalmail.rc @@ -0,0 +1,21 @@ +# Copyright 2009 Nick White +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ALIASFILE=$HOME/.mutt/aliases/personal + +:0 +* ^FROM* +* ? test -s $ALIASFILE +* ! ? grep -qi $(formail -x "From:"| cut -d '<' -f 2- | cut -d '>' -f 1) $ALIASFILE +impersonal/ diff --git a/software/scripts/gatherflaggedmail.sh b/software/scripts/gatherflaggedmail.sh new file mode 100644 index 0000000..4333ee5 --- /dev/null +++ b/software/scripts/gatherflaggedmail.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# Copyright 2009 Nick White +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# See for a copy of the GNU General +# Public License. +# +# To use this in mutt, add something like the following to your ~/.muttrc: +# macro index \eF "gatherflaggedmail.sh\n +# =flagged" "Gather flagged mail" + +MAILDIR=$HOME/.mail +FLAGGEDDIR=$MAILDIR/flagged + +# exclude transitory directories +searchpaths=$(ls $MAILDIR|sed -e '/search/d'|sed -e '/flagged/d') + +# clear old directory +rm -f $FLAGGEDDIR/cur/* + +for path in $searchpaths; do + find "$MAILDIR/$path" -regex '.*,*F[^\,]+*$' -exec ln -sf {} "$FLAGGEDDIR/cur" \; +done diff --git a/software/scripts/getlwn.py b/software/scripts/getlwn.py new file mode 100644 index 0000000..0cfde2e --- /dev/null +++ b/software/scripts/getlwn.py @@ -0,0 +1,63 @@ +#!/usr/bin/python2 +# Copyright 2009 Nick White +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# See for a copy of the GNU General +# Public License. + +import urllib2 +from cookielib import CookieJar +from urllib import urlencode +from optparse import OptionParser +from os import getenv + +# defaults +username = '' +password = '' +filename = 'lwn.html' +login_url = 'https://lwn.net/login' +bigpage_url = 'https://lwn.net/current/bigpage?format=printable' + +# parse arguments +parser = OptionParser() +parser.add_option("-u", "--user", dest="username", default=username, + help="lwn username") +parser.add_option("-p", "--pass", dest="password", default=password, + help="lwn password") +parser.add_option("-f", "--file", dest="filename", default=filename, + help="name of file to save to", metavar="FILE") +parser.add_option("-d", "--direct", dest="direct", default=False, + help="connect directly, bypassing any proxies", + action="store_true") +(options, args) = parser.parse_args() + +# set up cookiejar to use +credentials=urlencode({'Username': options.username, 'Password': options.password}) +cookiejar = CookieJar() +cookie_handler = urllib2.HTTPCookieProcessor(cookiejar) + +# set up proxy +proxyaddr = getenv('HTTP_PROXY') +if options.direct == True or not proxyaddr: + opener = urllib2.build_opener(cookie_handler) +else: + proxy_handler = urllib2.ProxyHandler({'http': proxyaddr, 'https': proxyaddr}) + opener = urllib2.build_opener(proxy_handler, cookie_handler) + +# login, then retrieve page +opener.open(login_url, credentials) +f = opener.open(bigpage_url) + +# save to a file +savefile = open(options.filename, 'w') +savefile.write(f.read()) +savefile.close diff --git a/software/scripts/index.txt b/software/scripts/index.txt new file mode 100644 index 0000000..93a53cf --- /dev/null +++ b/software/scripts/index.txt @@ -0,0 +1,82 @@ +Scripts +======================================================================= + +"Spending 2 hours to accomplish in 2 seconds what could otherwise be +done in 2 minutes." + + +## [Readability simple](http://git.njw.me.uk/cgit/cgit.cgi/readability-simple/) and [remove links](remove-links.js) + +"The ever-present awareness of possibility to either make or refuse +choice, was to preempt my creating any meditative space for myself" + - *Sean Birketts, The Gutenberg Elegies*. + +[Readability](http://code.google.com/p/arc90labs-readability/) is a +program which decides which parts of a web page make up the core text, +and rewrites the page to remove anything else. Unfortunately it was +designed as a 'bookmarklet,' meaning that one must rely on external +servers for its operation, with the speed, connectivity and privacy +implications which that entails. I lightly reworked the code to remove +some unnecessary functionality and ensure it can be easily used +locally. + +I also created a simple companion script which removes all links from a +page. I currently use these in [uzbl](http://www.uzbl.org), with the +command: `chain 'script @scripts_dir/readability/js/readability.js' +'script @scripts_dir/remove-links.js'` + +[Democracy Now! fetcher](fetchdnow.sh) +----------------------------------------------------------------------- + +The wonderful news programme +[Democracy Now!](http://www.democracynow.org) provide FLAC, Ogg Vorbis +and MP3 files of all of their episodes, but only a RSS feed for the +MP3s. This script downloads the latest episode, in FLAC, Ogg Vorbis +or MP3 format. I use this from a cron job to automatically fetch new +episodes in my prefered format. + +[LWN fetcher](getlwn.py) +----------------------------------------------------------------------- + +The online publication [LWN](http://lwn.net/) provides excellent news +on free software each week. However to access the latest issue one +needs to log in to a subscriber account. This script just automates +the login and download of the latest issue. + +[Encrypt email if possible](encrypt-if-possible.sh) +----------------------------------------------------------------------- + +One feature I really wanted with the [mutt](http://www.mutt.org/) mail +reader was to automatically encrypt email to anyone I have an OpenPGP +public key for. This simple script accomplishes just that, and can be +easily included in any mutt configuration. + +[Gather flagged email](gatherflaggedmail.sh) +----------------------------------------------------------------------- + +I store my email in Maildir format, in a variety of folders, and read +it using the mutt mail reader. This setup worked well for me, except +that there was no way for me to easily see all flagged messages in any +folder. This script enables this, by creating a dynamic folder with +links to all flagged email. + +[File non-personal email](filenonpersonalmail.rc) +----------------------------------------------------------------------- + +I find it useful to keep personal email separate from everything else I +receive. This is a simple procmail rule which moves email from anyone +not in my personal +[alias](http://www.mutt.org/doc/manual/manual-3.html#ss3.2) +file into a different folder. This could be done more neatly with awk, +but it has always worked perfectly so I'm leaving it be. + +[osCommerce Easy SEO URLs](http://addons.oscommerce.com/info/5901) +----------------------------------------------------------------------- + +osCommerce doesn't have a robust plugin system, so it's particularly +important to me that any modifications I make to osCommerce +installations are as simple and maintainable as possible. I found this +contribution to rewrite urls, which nearly did what I needed. I fixed +some serious bugs, added a few little features, and generally made it +a little more robust. I am currently maintaining the releases, and +(time-permitting) handling bug and feature requests. diff --git a/software/scripts/remove-links.js b/software/scripts/remove-links.js new file mode 100644 index 0000000..1defd2b --- /dev/null +++ b/software/scripts/remove-links.js @@ -0,0 +1,31 @@ +/* + * Copyright 2009 Nick White + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Use something like the following to use this in uzbl: + * script @scripts_dir/remove-links.js */ + +function removeNode(n){ + if(n.hasChildNodes()){ + for (var i=0; i 0) { + removeNode(a[a.length-1]); +} -- cgit v1.2.3