Skip to content

Instantly share code, notes, and snippets.

@offbyone
Created November 7, 2015 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save offbyone/d871116acf17f3cf44f5 to your computer and use it in GitHub Desktop.
Save offbyone/d871116acf17f3cf44f5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
import json
total = err = 0
for line_no, line in enumerate(sys.stdin):
try:
d = eval(line.rstrip())
except Exception as e:
sys.stderr.write("Line {} was malformed: {}\n".format(line_no, e))
err += 1
else:
json.dump(d, sys.stdout)
sys.stdout.write('\n')
finally:
total += 1
sys.stderr.write("""\
Total tweets: {}
Fixed tweets: {}
Unsalvageable: {}
Proportion: {:%}
""".format(total, total - err, err, err / total))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment