def make_html_peek_rows( self, dataset, skipchars=[] ): out = [""] comments = [] if not dataset.peek: dataset.set_peek() data = dataset.peek lines = data.splitlines() for line in lines: line = line.rstrip( '\r\n' ) if not line: continue comment = False for skipchar in skipchars: if line.startswith( skipchar ): comments.append( line ) comment = True break if comment: continue elems = line.split( '\t' ) if len( elems ) != dataset.metadata.columns: # We may have an invalid comment line or invalid data comments.append( line ) comment = True continue while len( comments ) > 0: # Keep comments try: out.append( '<tr><td colspan="100%">' ) except: out.append( '<tr><td>' ) out.append( '%s</td></tr>' % escape( comments.pop(0) ) ) out.append( '<tr>' ) for elem in elems: # valid data elem = escape( elem ) out.append( '<td>%s</td>' % elem ) out.append( '</tr>' ) # Peek may consist only of comments while len( comments ) > 0: try: out.append( '<tr><td colspan="100%">' ) except: out.append( '<tr><td>' ) out.append( '%s</td></tr>' % escape( comments.pop(0) ) ) return "".join( out )
def make_html_table(self, dataset, skipchars=[]): """Create HTML table, used for displaying peek""" out = ['<table cellspacing="0" cellpadding="3">'] try: out.append('<tr><th>Species: ') for species in dataset.metadata.species: out.append('%s ' % species) out.append('</th></tr>') if not dataset.peek: dataset.set_peek() data = dataset.peek lines = data.splitlines() for line in lines: line = line.strip() if not line: continue out.append('<tr><td>%s</td></tr>' % escape(line)) out.append('</table>') out = "".join(out) except Exception, exc: out = "Can't create peek %s" % exc
def make_html_table( self, dataset, skipchars=[] ): """Create HTML table, used for displaying peek""" out = ['<table cellspacing="0" cellpadding="3">'] try: out.append('<tr><th>Species: ') for species in dataset.metadata.species: out.append( '%s ' % species ) out.append( '</th></tr>' ) if not dataset.peek: dataset.set_peek() data = dataset.peek lines = data.splitlines() for line in lines: line = line.strip() if not line: continue out.append( '<tr><td>%s</td></tr>' % escape( line ) ) out.append( '</table>' ) out = "".join( out ) except Exception, exc: out = "Can't create peek %s" % exc
def create_players_list(filename): data = open(filename, 'r').read() lines = data.splitlines() players = [] player_info = [] # appends each line of file (which corresponds to a single player) to list of players for info in lines: if info == 'View More': players.append(player_info) player_info = [] else: player_info.append(info) ## first pass of cleanup of list of players -specificaly on Club and Age columns, ## to align properties of players for player in players: for club in clubs: if club in player[0]: #print('team found:', club) team = club player[0] = player[0].replace(club,'') player.insert(1, team) # removes and aligns column of 'Age:' where applicable for meta in player: if meta == 'Age:': continue else: if 'Age:' in meta: meta_indx = meta.index('Age:') player_indx = player.index(meta) age = 'Age:' player.insert((player_indx + 1), age) player[player_indx] = player[player_indx].replace('Age:', '') return players
def make_html_table(self, data, skipchar=None): out = ['<table cellspacing="0" cellpadding="3">'] first = True comments = [] try: lines = data.splitlines() for line in lines: if skipchar and line.startswith(skipchar): comments.append(line.strip()) continue line = line.strip() if not line: continue elems = line.split("\t") if first: #generate header first = False out.append('<tr>') for index, elem in enumerate(elems): out.append("<th>%s</th>" % (index+1)) out.append('</tr>') while len(comments)>0: out.append('<tr><td colspan="100%">') out.append(escape(comments.pop(0))) out.append('</td></tr>') out.append('<tr>') # body for elem in elems: elem = escape(elem) out.append("<td>%s</td>" % elem) out.append('</tr>') out.append('</table>') out = "".join(out) except Exception, exc: out = "Can't create peek %s" % exc
def make_html_table(self, data, skipchar=None): out = ['<table cellspacing="0" cellpadding="3">'] first = True comments = [] try: lines = data.splitlines() for line in lines: if skipchar and line.startswith(skipchar): comments.append(line.strip()) continue line = line.strip() if not line: continue elems = line.split("\t") if first: #generate header first = False out.append('<tr>') for index, elem in enumerate(elems): out.append("<th>%s</th>" % (index + 1)) out.append('</tr>') while len(comments) > 0: out.append('<tr><td colspan="100%">') out.append(escape(comments.pop(0))) out.append('</td></tr>') out.append('<tr>') # body for elem in elems: elem = escape(elem) out.append("<td>%s</td>" % elem) out.append('</tr>') out.append('</table>') out = "".join(out) except Exception, exc: out = "Can't create peek %s" % exc
file = open(filename,"w") file.write(blob) file.close() #### #### PART 3 #### open txt file with data, clean and format row to [category, year, team, region, state] #### filename = 'us_youth_national_champions_raw.txt' data = open(filename, 'r').read() lines = data.splitlines() all_winners = [] for line in lines: try: line = line.strip() if (line[0] == 'G' or line[0] == 'B'): categories = line.split('-') category = categories[0] else: year = int(line[0:4]) team, region = line.split(',') team = team.replace(str(year), '').strip()