#! /usr/bin/env python

import datetime

import sys

import urllib2

from datetime import date

def vars ( ) :

global verbose

verbose = False

global vn

vn = "0.1"

global ansiReset

ansiReset = " \0 33[0m"

global ansiYellow

ansiYellow = " \0 33[0;33m"

global ansiBBlue

ansiBBlue = " \0 33[1;34m"

def parseArgs ( argc ) :

argc. pop ( 0 )

for arg in argc:

if arg == "-h" or arg == "-help" or arg == "--help" :

printUsage ( ) ;

return 1

elif arg == "-version" or arg == "--version" :

printVersion ( ) ;

return 1

elif arg == "-v" or arg == "--verbose" :

global verbose

verbose = True

else :

print ( "unknown argument \" " + arg + " \" " )

print ( "run wotd --help for more information" )

return 1

def printUsage ( ) :

print ( ansiBBlue + "wotd v" + vn + ansiReset )

print

print ( ansiBBlue + "usage" + ansiReset )

print ( ansiYellow + "wotd" + ansiReset + " [args]" )

print

print ( ansiBBlue + "arguments" + ansiReset )

print ( "-h, -help, --help -> print usage and exit" )

print ( "-version, --version -> print version information and exit" )

print ( "-v, --verbose -> enable verbose output" )

def printVersion ( ) :

print ( ansiBBlue + "wotd v" + vn )

print ( "(C) renstenk 2015" + ansiReset )

vars ( )

if parseArgs ( sys . argv ) :

sys . exit ( )

today = date. today ( )

url = "http://dictionary.reference.com/wordoftheday"

url = url + "/" + str ( today. year )

url = url + "/" + str ( today. month )

url = url + "/" + str ( today. day )

if verbose:

print ( "requesting..." )

print ( "request URL: " + url )

req = urllib2 . Request ( url )

res = urllib2 . urlopen ( req )

word = res. geturl ( )

word = word. split ( "/" ) [ - 1 ]

print ( ansiBBlue + "word of the day for " + today. isoformat ( ) + ansiReset )