Permalink
Browse files

ward-colorize.py takes 1 command line argument: a URL or file to pick…

… up data from
  • Loading branch information...
1 parent 94ca02f commit 734416bd85d36e062ee62a60eb6346519c29b629 @sanand0 sanand0 committed Dec 5, 2010
Showing with 17 additions and 6 deletions.
  1. +1 −0 .gitignore
  2. +16 −6 ward-colorize.py
View
@@ -0,0 +1 @@
+*.pyc
View
@@ -1,10 +1,20 @@
-#---------------------------------------------------#
-# By Thejesh GN <i@thejeshgn.com>
-#
-#---------------------------------------------------#
-import csv
+'''Usage: ward-colorize.py <csv-file or csv-url>
+
+By Thejesh GN <i@thejeshgn.com>'''
+
+import csv, sys, urllib, re
from lxml import etree
+# Load data from the URL passed
+if len(sys.argv) < 2:
+ print __doc__
+ sys.exit(0)
+
+if re.match( "[a-z+]+://", sys.argv[1], re.IGNORECASE):
+ source = urllib.urlopen(sys.argv[1])
+else:
+ source = open(sys.argv[1])
+
# Load the SVG map
svg = etree.parse('bbmp-ward.svg')
@@ -15,7 +25,7 @@
colors = ["#F1EEF6", "#D4B9DA", "#C994C7", "#DF65B0", "#DD1C77", "#980043"]
# Color the counties based on unemployment rate
-for ward_id, ward_value in csv.reader(open('ward.csv')):
+for ward_id, ward_value in csv.reader(source):
for element in svg.xpath('//svg:path[@id=%s]' % ward_id, namespaces=ns):
element.set('fill', colors[int(ward_value)])

1 comment on commit 734416b

@Kratant

i want to map population of each ward
how to do that kindly help , i am having a csv file with the information.

plss its urgent.

-kratant adhaulia
adhauliak@gmail.com

Please sign in to comment.