Skip to content

Commit

Permalink
Merge branch 'master' of github.com:DocNow/twarc
Browse files Browse the repository at this point in the history
  • Loading branch information
edsu committed Aug 28, 2017
2 parents ce6e1be + 8ea9569 commit ece85a2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
26 changes: 22 additions & 4 deletions utils/json2csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,36 @@
CSV columns. If you'd like it adjusted send a pull request!
"""

import csv
import sys
import json
import codecs
import argparse
import fileinput

if sys.version_info[0] < 3:
sys.exit("Sorry, json2csv.py requires python v3")
try:
import unicodecsv as csv
except ImportError:
sys.exit("unicodecsv is required for python 2")
else:
import csv

def main():
sheet = csv.writer(sys.stdout)
parser = argparse.ArgumentParser()
parser.add_argument('--output', '-o', help='write output to file instead of stdout')
parser.add_argument('files', metavar='FILE', nargs='*', help='files to read, if empty, stdin is used')
args = parser.parse_args()

if args.output:
sheet = csv.writer(codecs.open(args.output, 'wb', 'utf-8'))
else:
sheet = csv.writer(sys.stdout)

sheet.writerow(get_headings())
for line in fileinput.input():

files = args.files if len(args.files) > 0 else ('-',)
for line in fileinput.input(files, openhook=fileinput.hook_encoded("utf-8")):

tweet = json.loads(line)
sheet.writerow(get_row(tweet))

Expand Down
7 changes: 5 additions & 2 deletions utils/wordcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import print_function
import re
import sys
import json
import fileinput

Expand Down Expand Up @@ -48,7 +49,7 @@

wordcloud_js = urlopen('https://raw.githubusercontent.com/jasondavies/d3-cloud/master/build/d3.layout.cloud.js').read()

print(("""<!DOCTYPE html>
output = """<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
Expand Down Expand Up @@ -93,4 +94,6 @@
</script>
</body>
</html>
""" % (wordcloud_js.decode('utf8'), json.dumps(words, indent=2))).encode('utf8'))
""" % (wordcloud_js.decode('utf8'), json.dumps(words, indent=2))

sys.stdout.write(output)

0 comments on commit ece85a2

Please sign in to comment.