]> jfr.im git - z_archive/twitter.git/commitdiff
Added a json format option
authorChristan Grant <redacted>
Fri, 18 Oct 2013 22:44:49 +0000 (18:44 -0400)
committerChristan Grant <redacted>
Fri, 18 Oct 2013 22:44:49 +0000 (18:44 -0400)
This addition allows the user to get the raw json tweet information from each row. This is helpful when the twitter json format is needed by another process.

Example usage: `twitter --format=json -r friends`

twitter/cmdline.py

index f238d6c297821e5a3fd3248e16ceb1b3d9622944..102ac5654fde9dbc2299cc0c8efe11b43eba8e7b 100644 (file)
@@ -43,6 +43,7 @@ FORMATS for the --format option
 
  default         one line per status
  verbose         multiple lines per status, more verbose status info
+ json            raw json data from the api on each line
  urls            nothing but URLs
  ansi            ansi colour (rainbow mode)
 
@@ -228,6 +229,11 @@ class VerboseStatusFormatter(object):
             status['created_at'],
             gHtmlParser.unescape(status['text'])))
 
+class JSONStatusFormatter(object):
+    def __call__(self, status, options):
+         status['text'] = gHtmlParser.unescape(status['text'])
+         return json.dumps(status)
+
 class URLStatusFormatter(object):
     urlmatch = re.compile(r'https?://\S+')
     def __call__(self, status, options):
@@ -316,6 +322,7 @@ formatters = {}
 status_formatters = {
     'default': StatusFormatter,
     'verbose': VerboseStatusFormatter,
+    'json': JSONStatusFormatter,
     'urls': URLStatusFormatter,
     'ansi': AnsiStatusFormatter
 }