Skip to content

Instantly share code, notes, and snippets.

@copyninja
Created October 20, 2011 11:47
Show Gist options
  • Save copyninja/1300951 to your computer and use it in GitHub Desktop.
Save copyninja/1300951 to your computer and use it in GitHub Desktop.
Generate report from MiniDebconf 2011 MangaloreEdition Register page
#!/usr/bin/python
############################################################################
# @file: generate_report.Py #
# #
# Copyright (c) 2011, Vasudeva Kamath <kamathvasudev at gmail dot com> #
# #
# Permission to use, copy, modify, and/or distribute this software for any #
# purpose with or without fee is hereby granted, provided that the above #
# copyright notice and this permission notice appear in all copies. #
# #
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES #
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF #
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR #
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES #
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN #
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF #
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #
############################################################################
import urllib2
from BeautifulSoup import BeautifulSoup
DEBIAN_WIKIPAGE_URL = "http://wiki.debian.org/DebianIndia/MiniDebConf2011/MangaloreEdition/Register"
if __name__ == "__main__":
proxy_support = urllib2.ProxyHandler({})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
page = urllib2.urlopen(DEBIAN_WIKIPAGE_URL)
soup = BeautifulSoup(page)
# soup = BeautifulSoup(open("Register.htm"))
table = soup.find('table')
# Number of participants
# Get first tr got to its and find all tr's reduce one since first row
# is table header
number_of_participants = len(table.findAll('tr')) - 1
accomodation_needed = 0
with_laptop = 0
small_tshirt = 0
medium_tshirt = 0
large_tshirt = 0
xl_tshirt = 0
for tr in table.findAll('tr'):
td = tr.findAll('td')
if td[6].find('p').contents[0].strip().lower() == "yes":
with_laptop += 1
if td[7].find('p').contents[0].strip().lower() == "yes":
accomodation_needed += 1
sizestr = td[8].find('p').contents[0].strip().lower()
if sizestr.find("yes") != -1:
try:
size = sizestr.split("(")[1].split(")")[0].strip()
except:
pass
if size == "s":
small_tshirt += 1
elif size == "m":
medium_tshirt += 1
elif size == "l":
large_tshirt += 1
elif size == "xl":
xl_tshirt += 1
print("##########################################################################")
print("")
print(" Number of Attendees: {0}".format((number_of_participants)))
print(" People requiring Accomodation: {0}".format((accomodation_needed)))
print(" People with Laptops: {0}".format((with_laptop)))
print("")
print("__________________________________________________________________________")
print("")
print(" Small T-Shirts: {0}".format((small_tshirt)))
print(" Medium T-Shirts: {0}".format((medium_tshirt)))
print(" Large T-Shirts: {0}".format((large_tshirt)))
print(" XL T-Shirts: {0}".format((xl_tshirt)))
print("")
print("##########################################################################")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment