Usuario:Ignacio Icke/tartarazas.py
(Redirigido desde «Usuario:Chabacano/tartarazas.py»)
# -*- coding: utf-8 -*-
"""uso: tartarazas --pu PUEBLO --bl NN --af NN --as NN --is NN --or NN --dr NN
donde NN es un número que indica el porcentaje de cada raza
bl=blancos, af=afroamericanos, as=asiáticos,
is=isleños, or=otras razas, dr=dos o más razas
PUEBLO es el nombre del pueblo
"""
import codecs
import sys
import getopt
import os
PI=3.141592
datos=[0,0,0,0,0,0]
datosex=[0,0,0,0,0,0,0]
pueblo=""
def usage():
print __doc__
try:
opts, args = getopt.getopt(sys.argv[1:], "h", ["help", "pu=", "bl=", "af=","as=","is=","or=","dr="])
except getopt.GetoptError:
usage()
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
exit()
elif opt == '--bl':
datos[0]=float(arg)
datosex[0]=1
elif opt == '--af':
datos[1]=float(arg)
datosex[1]=1
elif opt == '--as':
datos[2]=float(arg)
datosex[2]=1
elif opt == '--is':
datos[3]=float(arg)
datosex[3]=1
elif opt == '--or':
datos[4]=float(arg)
datosex[4]=1
elif opt == '--dr':
datos[5]=float(arg)
datosex[5]=1
elif opt == '--pu':
pueblo=arg
datosex[6]=1
if 0 in datosex:
usage()
datospi=[]
for dato in datos:
datospi.append((dato*2*PI)/100)
datosn=[0,0,0,0,0,0]
datospi2=[0,0,0,0,0,0]
for i in range(0,6):
datospi2[i]=datospi[0]
for j in range(1,i+1):
datospi2[i]=datospi2[i]+datospi[j]
strsvg="""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="1135.7142"
height="1259.1428"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.46"
version="1.0"
inkscape:output_extension="org.inkscape.output.svg.inkscape">
<defs
id="defs4">
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective10" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.35"
inkscape:cx="350"
inkscape:cy="612.32145"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1280"
inkscape:window-height="725"
inkscape:window-x="0"
inkscape:window-y="49"
showguides="true"
inkscape:guide-bbox="true" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Capa 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(264.99999,98.487535)">
<path
d="M 417.14287,323.79074 A 162.85715,162.85715 0 0 1 295.04493,481.46489 L 254.28572,323.79074 z"
sodipodi:ry="162.85715"
sodipodi:rx="162.85715"
sodipodi:cy="323.79074"
sodipodi:cx="254.28572"
id="Blancos"
style="fill:#ffb380;fill-opacity:1;stroke:#000000;stroke-width:0.70356214;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
sodipodi:type="arc"
transform="matrix(2.842677,0,0,2.842677,-421.83242,-537.99887)"
sodipodi:start="0"
sodipodi:end=\""""+repr(datospi2[0])+u"""" />
<path
sodipodi:type="arc"
style="fill:#87decd;fill-opacity:1;stroke:#000000;stroke-width:0.70356214;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="Afroamericanos"
sodipodi:cx="254.28572"
sodipodi:cy="323.79074"
sodipodi:rx="162.85715"
sodipodi:ry="162.85715"
d="M 296.16918,481.16998 A 162.85715,162.85715 0 0 1 180.88033,469.16646 L 254.28572,323.79074 z"
transform="matrix(2.842677,0,0,2.842677,-421.83242,-537.99887)"
sodipodi:start=\""""+repr(datospi2[0])+u""""
sodipodi:end=\""""+repr(datospi2[1])+u"""" />
<path
sodipodi:ry="162.85715"
sodipodi:rx="162.85715"
sodipodi:cy="323.79074"
sodipodi:cx="254.28572"
id="Asiáticos"
style="fill:#ffe680;fill-opacity:1;stroke:#000000;stroke-width:0.70356214;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
sodipodi:type="arc"
transform="matrix(2.842677,0,0,2.842677,-421.83242,-537.99887)"
sodipodi:start=\""""+repr(datospi2[1])+u""""
sodipodi:end=\""""+repr(datospi2[2])+u"""" />
<path
sodipodi:type="arc"
style="fill:#e580ff;fill-opacity:1;stroke:#000000;stroke-width:0.70356214;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="Dos o más razas"
sodipodi:cx="254.28572"
sodipodi:cy="323.79074"
sodipodi:rx="162.85715"
sodipodi:ry="162.85715"
transform="matrix(2.842677,0,0,2.842677,-421.83242,-537.99887)"
sodipodi:start=\""""+repr(datospi2[3])+u""""
sodipodi:end=\""""+repr(datospi2[4])+u"""" />
<path
sodipodi:type="arc"
style="fill:#80ffb3;fill-opacity:1;stroke:#000000;stroke-width:0.70356214;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="Isleños del Pacífico"
sodipodi:cx="254.28572"
sodipodi:cy="323.79074"
sodipodi:rx="162.85715"
sodipodi:ry="162.85715"
transform="matrix(2.842677,0,0,2.842677,-421.83242,-537.99887)"
sodipodi:start=\""""+repr(datospi2[2])+u""""
sodipodi:end=\""""+repr(datospi2[3])+u"""" />
<path
sodipodi:ry="162.85715"
sodipodi:rx="162.85715"
sodipodi:cy="323.79074"
sodipodi:cx="254.28572"
id="Otras razas"
style="fill:#8080ff;fill-opacity:1;stroke:#000000;stroke-width:0.70356214;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
sodipodi:type="arc"
transform="matrix(2.842677,0,0,2.842677,-421.83242,-537.99887)"
sodipodi:start=\""""+repr(datospi2[4])+u""""
sodipodi:end="6.2906425" />
<rect
style="fill:#ffb380;fill-opacity:1;stroke:#000000;stroke-width:1.78239918;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rectBlancos"
width="66.203392"
height="66.203392"
x="-240.25165"
y="872.39624" />
<rect
y="966.60876"
x="-240.25165"
height="66.203392"
width="66.203392"
id="rectAfroamericanos"
style="fill:#87decd;fill-opacity:1;stroke:#000000;stroke-width:1.78239918;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
<rect
style="fill:#ffe680;fill-opacity:1;stroke:#000000;stroke-width:1.78239918;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rectAsiáticos"
width="66.203392"
height="66.203392"
x="-240.25165"
y="1058.275" />
<rect
y="872.39624"
x="277.45782"
height="66.203392"
width="66.203392"
id="rectIsleños del Pacífico"
style="fill:#80ffb3;fill-opacity:1;stroke:#000000;stroke-width:1.78239918;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
<rect
style="fill:#8080ff;fill-opacity:1;stroke:#000000;stroke-width:1.78239918;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
id="rectOtras razas"
width="66.203392"
height="66.203392"
x="277.45782"
y="966.60876" />
<rect
y="1058.275"
x="277.45782"
height="66.203392"
width="66.203392"
id="rectDos o más razas"
style="fill:#e580ff;fill-opacity:1;stroke:#000000;stroke-width:1.78239918;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
<text
xml:space="preserve"
style="font-size:38.0686264px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="-157.94852"
y="919.69"
id="textBlancos"><tspan
sodipodi:role="line"
id="tspan3207"
x="-157.94852"
y="919.69">"""+u"%3.1f"%datos[0]+ u"""% Blancos</tspan></text>
<text
id="textIsleños del Pacífico"
y="920.45215"
x="364.85352"
style="font-size:38.0686264px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
xml:space="preserve"><tspan
y="920.45215"
x="364.85352"
id="tspan3211"
sodipodi:role="line">"""+u"%3.1f"%datos[3]+u"""% Isleños del Pacífico</tspan></text>
<text
id="textAfroamericanos"
y="1013.9025"
x="-157.94852"
style="font-size:38.0686264px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
xml:space="preserve"><tspan
y="1013.9025"
x="-157.94852"
id="tspan3215"
sodipodi:role="line">"""+u"%3.1f"%datos[1]+u"""% Afroamericanos</tspan></text>
<text
xml:space="preserve"
style="font-size:38.0686264px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="-157.94852"
y="1106.3309"
id="textAsiáticos"><tspan
sodipodi:role="line"
id="tspan3219"
x="-157.94852"
y="1106.3309">"""+u"%3.1f"%datos[2]+ u"""% Asiáticos</tspan></text>
<text
xml:space="preserve"
style="font-size:38.0686264px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
x="364.85352"
y="1013.5679"
id="textOtras razas"><tspan
sodipodi:role="line"
id="tspan3223"
x="364.85352"
y="1013.5679">"""+u"%3.1f"%datos[4]+u"""% Otras razas</tspan></text>
<text
id="textDos o más razas"
y="1106.3309"
x="364.85352"
style="font-size:38.0686264px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans"
xml:space="preserve"><tspan
y="1106.3309"
x="364.85352"
id="tspan3227"
sodipodi:role="line">"""+u"%3.1f"%datos[5]+u"""% Dos o más razas</tspan></text>
</g>
</svg>
"""
file=codecs.open(pueblo+"-demografia-temp.svg", mode='wb', errors='strict', encoding='utf-8', buffering=1)
file.write(strsvg)
file.close()
os.popen("inkscape -l "+pueblo+"-demografia.svg "+pueblo+"-demografia-temp.svg")
os.popen("rm "+pueblo+"-demografia-temp.svg")