diff --git a/bin/hy b/bin/hy index 8a06387..4a3b095 100755 --- a/bin/hy +++ b/bin/hy @@ -6,7 +6,8 @@ import sys if len(sys.argv) > 1: from hy.importer import import_file_to_module - import_file_to_module("__main__", sys.argv[1]) + sys.argv.pop(0) + import_file_to_module("__main__", sys.argv[0]) sys.exit(0) # right? diff --git a/eg/sunlight/party-count.hy b/eg/sunlight/party-count.hy new file mode 100755 index 0000000..b26a65b --- /dev/null +++ b/eg/sunlight/party-count.hy @@ -0,0 +1,22 @@ +#!/usr/bin/env hy +; let's check out the party breakdown for a state + +(import sys) +(import-from sunlight openstates) +(import-from collections Counter) + + +(def *state* (get sys.argv 1)) + + +(defn get-legislators [state] + (kwapply (.legislators openstates) {"state" state})) + + +(defn get-party-breakdown [state] + (Counter (map + (lambda [x](get x "party")) + (get-legislators state)))) + + +(print *state* "-" (get-party-breakdown *state*))