Fantasy – a Ruby library for scraping Fantasy Premier League

The Fantasy Premier League site has one (quite strange) limitation – the mini league tables aren’t updated live even though the actual team pages are. This makes it a chore to stay updated on how you’re doing compared to your mini league buddies. So I created a small Ruby library to scrape information from the Premier League website and then present it in whichever way is wanted.

The library is available at http://github.com/evenv/fantasy.

It’s released under the MIT license, so feel free to use it for whatever you’d like.

I’ve included the Sinatra app I created along with the library to show updated points for a list of teams. It’s not particularly advanced, but does the trick for me (and works pretty well on the iPhone).

Automatically Unrar Everything In A Folder

This script enters into all subfolders of the given folder, unrars all archives and then deletes the rar files. If the folder name matches HDTV or another filter of your choosing, the script will also move any video files to the root folder and delete the containing folder.

Designed to be run on a regular schedule, the script will skip any folders it has already processed. To run regularly, add to cron.

Here’s the script:

def episode(dir)
  dir.match "HDTV"
end

def unrar_delete(thefile,allfiles)
  if system "/opt/local/bin/unrar e -y %s > /dev/null" % thefile.gsub(' ',' ')
    for file in allfiles
      File.delete(file)
    end
    return true
  end
  return false
end

rootdir = "/Volumes/Filmer/Incoming"

Dir["%s/*" % rootdir].each do |dir|
  if File.directory? dir and not dir.match "UNPACKED"
    ok = false
    Dir.chdir(dir)
    Dir['%s/*.rar' % dir].each do |rarfile|
      puts rarfile
      ok = unrar_delete(rarfile, Dir[rarfile.gsub("part01","part??")]) if rarfile.match "part01.rar"
      ok = unrar_delete(rarfile, Dir[rarfile.gsub(".rar",".r??")]) if not rarfile.match /part[0-9]{2}/
    end

    if ok
      if episode(dir)
        system "mv *.avi %s" % rootdir
        system "mv *.mkv %s" % rootdir
        Dir.chdir(rootdir)
        system "rm -r %s" % dir
      else
        File.rename(dir,"%s UNPACKED" % dir)
      end
    end
  end
end

Export All OmniGraffle Files In A Folder To PDF

So I cooked up this small script that opens all OmniGraffle documents in a folder, and exports them to PDF files. The PDF files are named the same as the Graffle files, and will be saved in the same folder.

To use it, just load up Script Editor, paste, compile, and run. Of course, you could also save it to the AppleScripts folder so you can easily access it.

tell application "Finder"
  set the theFolder to choose folder with
    "Pick a folder containing the OmniGraffle files you want to export to PDF:"
  set theList to every file of the theFolder whose
  name extension is "graffle"
end tell

repeat with theFile in theList
  set theOutFile to ((do shell script "basename \"" & (theFile) & "\"" & " .graffle") & ".pdf")
  set theInFile to theFile as string
  tell application "OmniGraffle Professional 5"
    activate
    open file (theInFile)
    save front window in file theOutFile
    close front window
  end tell
end repeat