11#!/usr/bin/env python
2+ from __future__ import print_function
23import urllib2
3- import json
4+ try :
5+ import json
6+ except ImportError :
7+ #Older versions of Python (i.e. 2.4) require simplejson instead of json
8+ import simplejson as json
9+
410
511if __name__ == '__main__' :
612 """
2228 f = open ('api_key.txt' ,'w' )
2329 f .write (sys .argv [1 ])
2430 f .close ()
25- print 'Key: ' + sys .argv [1 ] + ' was written to api_key.txt'
26- print 'You are now ready to start using AlchemyAPI. For an example, run: python example.py'
31+ print ( 'Key: ' + sys .argv [1 ] + ' was written to api_key.txt' )
32+ print ( 'You are now ready to start using AlchemyAPI. For an example, run: python example.py' )
2733 else :
28- print 'The key appears to invalid. Please make sure to use the 40 character key assigned by AlchemyAPI'
34+ print ( 'The key appears to invalid. Please make sure to use the 40 character key assigned by AlchemyAPI' )
2935
3036
3137
@@ -99,12 +105,12 @@ def __init__(self):
99105
100106 if key == '' :
101107 #The key file should't be blank
102- print 'The api_key.txt file appears to be blank, please run: python alchemyapi.py YOUR_KEY_HERE'
103- print 'If you do not have an API Key from AlchemyAPI, please register for one at: http://www.alchemyapi.com/api/register.html'
108+ print ( 'The api_key.txt file appears to be blank, please run: python alchemyapi.py YOUR_KEY_HERE' )
109+ print ( 'If you do not have an API Key from AlchemyAPI, please register for one at: http://www.alchemyapi.com/api/register.html' )
104110 sys .exit (0 )
105111 elif len (key ) != 40 :
106112 #Keys should be exactly 40 characters long
107- print 'It appears that the key in api_key.txt is invalid. Please make sure the file only includes the API key, and it is the correct one.'
113+ print ( 'It appears that the key in api_key.txt is invalid. Please make sure the file only includes the API key, and it is the correct one.' )
108114 sys .exit (0 )
109115 else :
110116 #setup the key
@@ -114,14 +120,14 @@ def __init__(self):
114120 f .close ()
115121 except IOError :
116122 #The file doesn't exist, so show the message and create the file.
117- print 'API Key not found! Please run: python alchemyapi.py YOUR_KEY_HERE'
118- print 'If you do not have an API Key from AlchemyAPI, please register for one at: http://www.alchemyapi.com/api/register.html'
123+ print ( 'API Key not found! Please run: python alchemyapi.py YOUR_KEY_HERE' )
124+ print ( 'If you do not have an API Key from AlchemyAPI, please register for one at: http://www.alchemyapi.com/api/register.html' )
119125
120126 #create a blank key file
121127 open ('api_key.txt' , 'a' ).close ()
122128 sys .exit (0 )
123129 except Exception as e :
124- print e
130+ print ( e )
125131
126132
127133
@@ -560,7 +566,7 @@ def __analyze(self, url, options):
560566 f = urllib2 .urlopen (req )
561567 return json .load (f )
562568 except Exception as e :
563- print " error for url: " , url
564- print e
569+ print ( ' error for url: ' , url )
570+ print ( e )
565571 return { u'status' :'ERROR' , u'statusInfo' :u'network-error' }
566572
0 commit comments