import urllib2 as url
import os
import sys
from datetime import date
import gzip

def run(hide=False):
    '''
    Update local game data
    '''
    year = date.today().year
    month = date.today().month
    day = date.today().day
    for i in range(2012, year+1):
        for x in range(1, 13):
            monthstr = str(x).zfill(2)
            loading = False
            if i == year and x > month:
                break
            for y in range(1, 31):
                if i == year and x >= month and y >= day:
                    break
                daystr = str(y).zfill(2)
                filename = "gameday-data/year_"+str(i)+"/month_"+monthstr+"/day_"+daystr+"/scoreboard.xml.gz"
                f = os.path.join(os.path.dirname(__file__), filename)
                dirn = "gameday-data/year_"+str(i)+"/month_"+monthstr+"/day_"+daystr
                dirname = os.path.join(os.path.dirname(__file__), dirn)
                if not os.path.isfile(f):
                    try:
                        data = url.urlopen("http://gd2.mlb.com/components/game/mlb/year_"+str(i)+"/month_"+monthstr+"/day_"+daystr+"/scoreboard.xml")
                        if not hide:
                            sys.stdout.write('Loading games for %s-%d (%00.2f%%) \r' % (monthstr, i, y/31.0*100))
                            sys.stdout.flush()
                        loading = True
                        response = data.read()
                        if not os.path.exists(dirname):
                            os.makedirs(dirname)
                        try:
                            with gzip.open(f, "w") as f:
                                f.write(response)
                        except PermissionError:
                            if not os.access(dirname, os.W_OK):
                                print 'I do not have write access to "%s".' % dirname
                                print 'Without write access, I cannot update the game database.'
                    except url.HTTPError:
                        pass
            if loading and not hide:
                sys.stdout.write('Loading games for %s-%d (100.00%%)\n' % (monthstr, i))
                sys.stdout.flush()
    if not hide:
        print "Complete"

if __name__ == "__main__":
    run()
@@ -1470,24 +1470,61 @@
 s(dirname):%0A
+                            try:%0A    
             
@@ -1576,35 +1576,50 @@
                 
-try
+    except OSError
 :%0A              
@@ -1636,213 +1636,423 @@
     
+ 
-with gzip.open(f, %22w%22) as f:%0A                                f.write(response)%0A                        except PermissionError:%0A                            if not os.access(dirname, os.W_OK):%0A              
+   print 'I do not have write access to %22%25s/%25s%22.' %25 (os.path.dirname(__file__), 'gameday-data/')%0A                                print 'Without write access, I cannot update the game database.'%0A                                sys.exit(1)%0A                        try:%0A                            with gzip.open(f, %22w%22) as f:%0A                                f.write(response)%0A                        except OSError:%0A
     
@@ -2057,32 +2057,42 @@
                 
+          
 print 'I do not 
@@ -2129,20 +2129,16 @@
 dirname%0A
-    
         
@@ -2214,32 +2214,72 @@
 game database.'%0A
+                            sys.exit(1)%0A
                 

Fix error message