在Python中創建元組列表。然後將它們排序。然後遍歷列表並生成您的主頁HTML。下面是一個例子。您需要填寫網址,併爲每個報告的日期(無論是作爲一個日期對象或字符串,例如:'09 -12-2011' )
report_tuples = [
('http://www.myreport.com/report1', report1_date_object_or_string),
('http://www.myreport.com/report2', report2_date_object_or_string),
('http://www.myreport.com/report3', report3_date_object_or_string),
]
sorted(report_tuples, key=lambda reports: reports[1]) # sort by date
html = '<html><body>' #add anything else in here or even better
#use a template that you read and complement
lastDate = None
for r in report_tuples:
if not lastDate or not lastDate == r[1]:
html += '<h3>%s</h3>' % (str(r[1]))
html += '<a href="%s">Your Report Title</a>' % (r[0])
return html #or even better, write it to the disk.
這裏的一些網址,可以幫助:
How to sort a list in place
Python data structures in general
你** **不明白,鏈接到文件在本地計算機上,並因此毫無價值我們其餘的人,對不對? – 2011-09-27 17:00:57
我知道。但這只是一個例子 – BPm
**什麼**的例子?任何不在您的計算機上的人都**無法在您提供的鏈接中查看html。 – 2011-09-27 17:02:47