def ripen_all_players():
	'''
	Populate db table 'all_players' in nhl.db with tombstone details by going
	to individual player pages using already stored playerids
	Table MUST have been seeded using grow_all_players previously
	Top level function
	'''

	# Tracking time it takes function to run/num of players grabbed
	start_time = time.time()
	num_players = 0
	player_counter = 0

	conn = sqlite3.connect ('nhl.db')
	c = conn.cursor ()

	c.execute('SELECT * FROM all_players')

	rows = c.fetchall()

	# Grabing player ids from all players ever
	checked_players = []
	num_rows = len(rows)
	max_index = len (rows) - 1

	 # (380 pages/18196 rows as of 05/01/15)	
	while len (checked_players) < num_rows:
		index_num = random.randint(0, max_index)
		while index_num in checked_players:
			if index_num == max_index:
				index_num = random.randint(0, max_index)
			else:
				index_num += 1
		checked_players.append (index_num)
		print (str(len(checked_players)) + "/" + str(num_rows)).ljust(15),
		
		player_counter += 1				
		playerid = rows[index_num][0]
		position_table = rows[index_num][3]
		print ('RIPENED ' + str(playerid)).ljust(30)
		assert position_table in ['G', 'D', 'LW', 'C', 'RW'],\
			'ERROR: position_table invalid (=%s)'%(position_table)
		player = PlayerPage.harvest(playerid, position_table)
		ripen_player(c, player)
		num_players += 1
		conn.commit ()
	
	conn.close()

	total_time = time.time() - start_time
	print "%0.2fs - total time taken" %total_time
	print str(num_players), " - records imported"
	print str(total_time/num_players) + 'secs/player'
			'ERROR: position_table invalid (=%s)'%(position_table)
		player = PlayerPage.harvest(playerid, position_table)
		ripen_player(c, player)
		num_players += 1
		conn.commit ()
	
	conn.close()

	total_time = time.time() - start_time
	print "%0.2fs - total time taken" %total_time
	print str(num_players), " - records imported"
	print str(total_time/num_players) + 'secs/player'


if __name__ == '__main__':
	germinate_all_players_table()
	germinate_seasons_table()
	grow_all_players()

	player = PlayerPage.harvest(8449783, 'G')
	
	conn = sqlite3.connect ('nhl.db')
	c = conn.cursor ()
	c.execute('SELECT * FROM all_players WHERE playerid = ?',(8449783,))

	row = c.fetchone()
	playerid = row[0]
	position = row[3]
	player = PlayerPage.harvest(playerid, position)
	ripen_player (c, player)