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