Created
April 25, 2016 18:25
-
-
Save chuckadams/90a675a7804c6f0d9ea8787797422d6d to your computer and use it in GitHub Desktop.
Slurp npm registry into a plain text format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import urllib | |
import ijson | |
if len(sys.argv) < 2: | |
url = 'http://registry.npmjs.org/-/all' | |
else: | |
url = sys.argv[1] | |
input = urllib.urlopen(url) | |
parser = ijson.parse(input) | |
ignored_events = ['start_map', 'end_map', 'start_array', 'end_array', | |
'map_key'] | |
for prefix, event, value in parser: | |
if event in ignored_events: | |
continue | |
if event == 'string': | |
value = value.encode('utf-8') | |
print "{} {}".format(prefix, value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment