Ajuda script HTML

ruyandre

Power Member
Assim, desenvolva: a) Um script web_update.sh que produz a lista atualizada de utilizadores do nosso sistema, em formato HTML, e a coloca no ficheiro: ~/public_html/users.htm.


Exemplo de um ficheiro HTML minimalista:

**<html>
<head>
<title>Utilizadores do sistema PinIUL</title> </head>
<body>
<h1>Utilizadores PinIUL</h1><br>
10003 - alberto - Alberto Maria dos Santos<br> ...<br>
</body>
</html>**



Alguem me pode dizer como fazer isto? Obrigado
 
Última edição:
Primeiro tens que ver onde vais buscar a informação dos utilizadores, está num ficheiro, no próprio script? Caso esteja num ficheiro tens que fazer parse. Depois é imprimir a informação com as tags html em volta.
 
gera um ficheiro em HTML com CSS para fazer a zebra:
Código:
#!/usr/bin/python
# -*- coding: utf-8 -*-

def create_lines(dataset, stripes = True):
    toto = ''
    odd = True
    for n in dataset:
        if odd:
          dum =  '<tr class="alt">'
        else:
            dum =  '<tr>'

        if type(n) == int:
            dum += '<td id="right-cell">' + str(n) + '</td>'
        else:
            dum += '<td>'+ str(n) + '</td>' 
        if stripes : odd = not(odd)
        toto += dum + '</tr>'
    return toto

def create_header(css_style,header):
    toto = '<table id="' + css_style + '"> <tr>' 
    for n in header: 
        toto +=  '<th>' +  n  +'</th>' 
    toto += '</tr>'
    return toto

def main():
    html_header = '<!DOCTYPE html><html lang="pt_pt"><head><meta charset="utf-8"><title>Users</title>'
    listToHtml = ''

    f = open('/etc/passwd')
    a = f.readlines()
    f.close()

    user_list = []
    for n in a:
        user_list.append(n[:n.find(':')])
    css = '<style type="text/css">#users\
                {font-family:"Tahoma", Arial, Helvetica, sans-serif;width:100%;border-collapse:collapse;}\
                #users td, #users th {font-size:1em;border:1px solid #98bf21;padding:3px 7px 2px 7px;}\
                #users th {font-size:14px;font-weight:bold;text-align:center;padding-top:5px;padding-bottom:4px;background-color:#A7C942;color:#000000;}\
                #users tr.alt td {color:#0000px00;background-color:#EAF2D3;}\
                #right-cell {text-align: right;}</style></head>'
    css_table_header = 'users'
    row_header = create_header(css_table_header,['User'] )
    listToHtml = create_lines(user_list)
    toto = html_header + css + '<body>' + row_header + listToHtml + '</table></body></html>'

    file_name = 'output.html'
    f = open(file_name,'w')
    print >>f, toto

if __name__ == '__main__':
    main()


executar com python <nome>
 
Back
Topo