The timelog.py
script provides functionality to parse, process, and reorder timelog data stored in HTML tables. The primary purpose is to calculate the time difference (in minutes) between start and end times for a given activity and reorder the table entries accordingly.
The script expects the table to have the following column headings:
- Date: The date of the activity.
- Start Time: The time when the activity started.
- Stop Time: The time when the activity stopped.
- Activity Code: A unique code representing the activity.
- Activity Description: A brief description of the activity.
- Delta Time: The difference in minutes between the start and stop times.
<table BORDER="3">
<tbody>
<tr>
<td> Date </td>
<td> Start </td>
<td> Stop </td>
<td> Activity Code </td>
<td> Activity </td>
<td> Delta Time </td>
</tr>
<tr>
<td> 08/21/23 </td>
<td> 23:10 </td>
<td> 01:10 </td>
<td> ADMIN </td>
<td> Created this README </td>
<td> xx </td>
</tr>
<tr>
<td> 08/20/23 </td>
<td> 16:10 </td>
<td> 19:10 </td>
<td> DEV </td>
<td> Worked on timelog.py </td>
<td> 180 </td>
</tr>
</tbody>
</table>
-
time_delta(row, date_column, start_time_column, end_time_column)
:- Description: Calculates the time difference in minutes between the start and end times for a given row.
- Parameters: The row data, the indices for the date, start time, and end time columns.
- Returns: The time difference in minutes.
-
create_final_table(table)
:- Description: Converts a list of lists (table) into an HTML table string.
- Parameters: A list of lists representing the table.
- Returns: An HTML string representation of the table.
-
process_html(soup)
:- Description: Parses an HTML table and returns its rows as lists.
- Parameters: A BeautifulSoup object containing the HTML table.
- Returns: A list of rows, where each row is a list of cell contents.
-
reorder_table(file_name, date_column, start_time_column, end_time_column)
:- Description: Parses an HTML file containing a table, calculates the time delta for each row, and returns a reordered table.
- Parameters: The file path of the HTML file, the indices for the date, start time, and end time columns.
- Returns: An HTML string representing the reordered table.
To use the reorder_table()
function:
final_table_html = reorder_table('timelogTable.html', 0, 1, 2)
with open('new.html', 'w') as f:
f.write(final_table_html)
This example reads data from timelogTable.html
, processes it, and writes the reordered table to new.html
.
- BeautifulSoup: Used for HTML parsing and processing.
Ensure that the provided HTML file follows the expected table structure mentioned above. Improperly formatted data may lead to unexpected results or errors.