diff --git a/grab.py b/grab.py index dd3c1f0..43e8f81 100755 --- a/grab.py +++ b/grab.py @@ -1,14 +1,14 @@ #!/usr/bin/env python2 +from __future__ import with_statement import sys try: import json except ImportError: import simplejson as json from urllib2 import urlopen, HTTPError from time import sleep -f = open('user.json', 'r') -user = json.load(f)['user'] -f.close() +with open('user.json', 'r') as f: + user = json.load(f)['user'] sub_section = 'comments' after = '' diff --git a/kill.py b/kill.py index c3d272a..ee6e9bc 100755 --- a/kill.py +++ b/kill.py @@ -8,9 +8,8 @@ from datetime import datetime, timedelta from time import sleep ## Get the data we need to log into the API -f = open('user.json', 'r') -data = json.load(f) -f.close() +with open('user.json', 'r') as f: + data = json.load(f) days = data['days'] user = data['user']