Skip to content

Instantly share code, notes, and snippets.

@jpadilla
Created November 13, 2012 11:19
Show Gist options
  • Select an option

  • Save jpadilla/4065288 to your computer and use it in GitHub Desktop.

Select an option

Save jpadilla/4065288 to your computer and use it in GitHub Desktop.

Revisions

  1. jpadilla revised this gist Nov 13, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cee_rob1.py
    Original file line number Diff line number Diff line change
    @@ -3,5 +3,5 @@
    import time
    print '\nGOVERNOR\nISLAND WIDE RESULTS\n'
    while 1:
    print '\n'.join(['%s\n'%E.fromstring(urllib2.urlopen('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml').read()).find('date').text,'\n'.join(map(lambda e:'%s (%s) => %s (%s%%)'%e,[(o.find('name/es').text,o.find('pe/es').text,format(int(o.find('votes').text),',d'),str(float(o.find('votes').text)/sum([int(e.text)for e in E.fromstring(urllib2.urlopen('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml').read()).findall('option/votes')])*100)[0:5])for o in E.fromstring(urllib2.urlopen('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml').read()).findall('option')]))])
    print '\n'.join(['%s\n'%E.fromstring(urllib2.urlopen('http://is.gd/wB6SJq').read()).find('date').text,'\n'.join(map(lambda e:'%s (%s) => %s (%s%%)'%e,[(o.find('name/es').text,o.find('pe/es').text,format(int(o.find('votes').text),',d'),str(float(o.find('votes').text)/sum([int(e.text)for e in E.fromstring(urllib2.urlopen('http://is.gd/wB6SJq').read()).findall('option/votes')])*100)[0:5])for o in E.fromstring(urllib2.urlopen('http://is.gd/wB6SJq').read()).findall('option')]))])
    time.sleep(120)
  2. @siloraptor siloraptor revised this gist Nov 13, 2012. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions cee_rob1.py
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,7 @@
    import urllib2
    from xml.dom.minidom import parseString
    import lxml.etree as E
    import time
    print '\nGOVERNOR\nISLAND WIDE RESULTS\n', '-' * 19
    while True:
    print '\n%s\n' % (parseString(urllib2.urlopen('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml').read()).getElementsByTagName('date')[0].childNodes[0].data)
    print '\n\n'.join(map(lambda entry: '%(name)s (%(party)s) => %(votes)s (%(percent)s%%)' % entry, [{'party': option.getElementsByTagName('pe')[0].getElementsByTagName('es')[0].childNodes[0].data.title(), 'name': option.getElementsByTagName('name')[0].getElementsByTagName('es')[0].childNodes[0].data, 'votes': format(int(option.getElementsByTagName('votes')[0].childNodes[0].data), ',d'), 'percent': format(float(option.getElementsByTagName('votes')[0].childNodes[0].data) / int(sum([int(option.getElementsByTagName('votes')[0].childNodes[0].data) for option in parseString(urllib2.urlopen('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml').read()).getElementsByTagName('option')])) * 100, '.3')} for option in parseString(urllib2.urlopen('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml').read()).getElementsByTagName('option')]))
    print '\nGOVERNOR\nISLAND WIDE RESULTS\n'
    while 1:
    print '\n'.join(['%s\n'%E.fromstring(urllib2.urlopen('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml').read()).find('date').text,'\n'.join(map(lambda e:'%s (%s) => %s (%s%%)'%e,[(o.find('name/es').text,o.find('pe/es').text,format(int(o.find('votes').text),',d'),str(float(o.find('votes').text)/sum([int(e.text)for e in E.fromstring(urllib2.urlopen('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml').read()).findall('option/votes')])*100)[0:5])for o in E.fromstring(urllib2.urlopen('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml').read()).findall('option')]))])
    time.sleep(120)
  3. @siloraptor siloraptor revised this gist Nov 9, 2012. 1 changed file with 3 additions and 10 deletions.
    13 changes: 3 additions & 10 deletions cee_rob1.py
    Original file line number Diff line number Diff line change
    @@ -3,13 +3,6 @@
    import time
    print '\nGOVERNOR\nISLAND WIDE RESULTS\n', '-' * 19
    while True:
    try:
    dom = parseString(urllib2.urlopen('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml').read())
    date = dom.getElementsByTagName('date')[0]
    print '\n%s\n%s' % (date.childNodes[0].data, '=' * len(date.childNodes[0].data))
    total_votes = int(sum([int(option.getElementsByTagName('votes')[0].childNodes[0].data) for option in dom.getElementsByTagName('option')]))
    print '\n\n'.join(map(lambda entry: '%(name)s (%(party)s) => %(votes)s (%(percent)s%%)' % entry, [{'party': option.getElementsByTagName('pe')[0].getElementsByTagName('es')[0].childNodes[0].data.title(), 'name': option.getElementsByTagName('name')[0].getElementsByTagName('es')[0].childNodes[0].data, 'votes': format(int(option.getElementsByTagName('votes')[0].childNodes[0].data), ',d'), 'percent': format(float(option.getElementsByTagName('votes')[0].childNodes[0].data) / total_votes * 100, '.3')} for option in dom.getElementsByTagName('option')]))
    print '\n%s\nTOTAL VOTES: %s\n%s\n' % ('=' * (len(format(total_votes, ',d')) + 13), format(total_votes, ',d'), '=' * (len(format(total_votes, ',d')) + 13))
    time.sleep(120)
    except KeyboardInterrupt:
    exit(0)
    print '\n%s\n' % (parseString(urllib2.urlopen('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml').read()).getElementsByTagName('date')[0].childNodes[0].data)
    print '\n\n'.join(map(lambda entry: '%(name)s (%(party)s) => %(votes)s (%(percent)s%%)' % entry, [{'party': option.getElementsByTagName('pe')[0].getElementsByTagName('es')[0].childNodes[0].data.title(), 'name': option.getElementsByTagName('name')[0].getElementsByTagName('es')[0].childNodes[0].data, 'votes': format(int(option.getElementsByTagName('votes')[0].childNodes[0].data), ',d'), 'percent': format(float(option.getElementsByTagName('votes')[0].childNodes[0].data) / int(sum([int(option.getElementsByTagName('votes')[0].childNodes[0].data) for option in parseString(urllib2.urlopen('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml').read()).getElementsByTagName('option')])) * 100, '.3')} for option in parseString(urllib2.urlopen('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml').read()).getElementsByTagName('option')]))
    time.sleep(120)
  4. @siloraptor siloraptor revised this gist Nov 8, 2012. No changes.
  5. @siloraptor siloraptor revised this gist Nov 8, 2012. No changes.
  6. @siloraptor siloraptor revised this gist Nov 8, 2012. No changes.
  7. @siloraptor siloraptor created this gist Nov 8, 2012.
    15 changes: 15 additions & 0 deletions cee_rob1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    import urllib2
    from xml.dom.minidom import parseString
    import time
    print '\nGOVERNOR\nISLAND WIDE RESULTS\n', '-' * 19
    while True:
    try:
    dom = parseString(urllib2.urlopen('http://div1.ceepur.org/REYDI_NocheDelEvento/data/GOBERNADOR_ISLA.xml').read())
    date = dom.getElementsByTagName('date')[0]
    print '\n%s\n%s' % (date.childNodes[0].data, '=' * len(date.childNodes[0].data))
    total_votes = int(sum([int(option.getElementsByTagName('votes')[0].childNodes[0].data) for option in dom.getElementsByTagName('option')]))
    print '\n\n'.join(map(lambda entry: '%(name)s (%(party)s) => %(votes)s (%(percent)s%%)' % entry, [{'party': option.getElementsByTagName('pe')[0].getElementsByTagName('es')[0].childNodes[0].data.title(), 'name': option.getElementsByTagName('name')[0].getElementsByTagName('es')[0].childNodes[0].data, 'votes': format(int(option.getElementsByTagName('votes')[0].childNodes[0].data), ',d'), 'percent': format(float(option.getElementsByTagName('votes')[0].childNodes[0].data) / total_votes * 100, '.3')} for option in dom.getElementsByTagName('option')]))
    print '\n%s\nTOTAL VOTES: %s\n%s\n' % ('=' * (len(format(total_votes, ',d')) + 13), format(total_votes, ',d'), '=' * (len(format(total_votes, ',d')) + 13))
    time.sleep(120)
    except KeyboardInterrupt:
    exit(0)