Nix warning on edit collision since we do that now
[mw] / src / mw / api.py
index 334c25edb79c33b94ef73f2aa681e3c958305984..6aec91c7b36a72353b328c2872e9da0b4882865b 100644 (file)
@@ -19,6 +19,7 @@
 import cookielib
 import gzip
 import json
+import mw
 import mw.metadir
 import os
 from StringIO import StringIO
@@ -32,8 +33,7 @@ class API(object):
         self.api_url = api_url
         self.metadir = metadir
         self.cookiejar = cookielib.MozillaCookieJar(os.path.join(
-                self.metadir.location, 'cookies'
-        ))
+                self.metadir.location, 'cookies'))
         try:
             self.cookiejar.load()
         except IOError:
@@ -45,7 +45,9 @@ class API(object):
 
     def call(self, data):
         data['format'] = 'json'
-        request = urllib2.Request(self.api_url, urllib.urlencode(data))
+        user_agent = 'mw/%s +http://github.com/ianweller/mw' % mw.version
+        request = urllib2.Request(self.api_url, urllib.urlencode(data),
+                                  {'User-Agent': user_agent})
         request.add_header('Accept-encoding', 'gzip')
         response = self.opener.open(request)
         self.cookiejar.save()

Benjamin Mako Hill || Want to submit a patch?