{ "metadata": { "name": "", "signature": "sha256:dda7644f240714dcf652da6e37bb05150a3ed74ed76f381b76f9c952645a8241" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# The Ushahidi Team Maker\n", "\n", "*Creating esprit de corps through random.shuffle().*\n", "\n", "**Operations:**\n", "- Scrapes Ushahidi team page for names\n", "- Randomly assigns people to groups\n", "- Assigns an uberconference room\n", "- Prints results" ] }, { "cell_type": "code", "collapsed": false, "input": [ "# Import required modules\n", "import requests\n", "from bs4 import BeautifulSoup\n", "import random" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 9 }, { "cell_type": "code", "collapsed": false, "input": [ "# Create a variable with the URL\n", "url_names = 'http://www.ushahidi.com/mission/team/'\n", "\n", "# Scrape the HTML at the url\n", "r_names = requests.get(url_names)\n", "\n", "# Turn the HTML into a Beautiful Soup object\n", "soup_names = BeautifulSoup(r_names.text)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 10 }, { "cell_type": "code", "collapsed": false, "input": [ "# Create a list for the names of the team\n", "team = []" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 11 }, { "cell_type": "code", "collapsed": false, "input": [ "# For each h3 tag (where the names are),\n", "for item in soup_names.find_all({'h3'}):\n", " # strip off the tags and append the name to team[]\n", " team.append(item.string.strip())" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 12 }, { "cell_type": "code", "collapsed": false, "input": [ "# Define a functon called make groups, \n", "# with two inputs: the teams members list and the size of the group\n", "def make_groups(x, n):\n", " # shuttle the list of names\n", " random.shuffle(x)\n", " # if n is less than 1,\n", " if n < 1:\n", " # set n as 1\n", " n = 1\n", " # Calculate the number of groups needed, and assign\n", " # names to each of those groups\n", " return [x[i:i + n] for i in range(0, len(x), n)]" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 13 }, { "cell_type": "code", "collapsed": false, "input": [ "# Run the make_groups function\n", "groups = make_groups(team, 10)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 14 }, { "cell_type": "code", "collapsed": false, "input": [ "# Create a list of UberConference Room\n", "rooms = ['https://www.uberconference.com/ushahidi', \n", " 'https://www.uberconference.com/chrisalbon', \n", " 'https://www.uberconference.com/natmanning',\n", " 'https://www.uberconference.com/juliana',\n", " 'https://www.uberconference.com/woody',\n", " 'https://www.uberconference.com/brian']" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 15 }, { "cell_type": "code", "collapsed": false, "input": [ "# Set y at 0 \n", "y = 0\n", "\n", "# For each group,\n", "for group in groups:\n", " # Print the group number\"\n", " print('Group #', y+1)\n", " # Print the UberConference room url\n", " print('Room:', rooms[y])\n", " # Print a line break\n", " print(sep='\\n')\n", " # Print the names in the group\n", " print(*group, sep='\\n')\n", " # Print a line break\n", " print(sep='\\n')\n", " # Add 1 to y as an loop counter\n", " y = y+1" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Group # 1\n", "Room: https://www.uberconference.com/ushahidi\n", "\n", "Sara-Jayne Terp\n", "Mathias Antonsson\n", "Aurelia Moser\n", "Juliana Rotich\n", "Brian Herbert\n", "Shadrock Roberts\n", "Limo Taboi\n", "Vidya Spandana\n", "Linda Kamau\n", "Henry Addo\n", "\n", "Group # 2\n", "Room: https://www.uberconference.com/chrisalbon\n", "\n", "Sebastian Mitchell\n", "Seth Hall\n", "Gregory Omondi\n", "Zack Halloran\n", "Jepchumba Thomas\n", "Daudi Were\n", "Ben Lieblich\n", "Esther Ondigo\n", "Angela Oduor\n", "David Kobia\n", "\n", "Group # 3\n", "Room: https://www.uberconference.com/natmanning\n", "\n", "Chris Albon, Ph.D.\n", "Sharon Rutto\n", "Jon Shuler\n", "Anarghya Vardhana\n", "Woody Gilk\n", "Nathaniel Manning\n", "Robbie Mackay\n", "Jonathon Morgan\n", "Rob Baker\n", "\n" ] } ], "prompt_number": 16 } ], "metadata": {} } ] }