question 221 CLI & Automation · easy
The newest dated export
A sync script only uploads the most recent export. Exports are named <kind>-<year>-<month>-<day>.csv, and the folder also holds other files. Given the file names, pick the newest export.
Function
newest_export(names)namesa list of file names (text)
Returnsthe name whose date is latest, or
None when no name is a dated exportDated exportsuffix
.csv (any capitals); the stem split on - ends in a 4-digit year, a 2-digit month and a 2-digit dayTiesthe same date twice: the name that comes first in the list
Examples
callnewest_export(['orders-2011-03-14.csv', 'orders-2011-03-02.csv', 'orders-2010-12-31.csv', 'notes.txt'])returns'orders-2011-03-14.csv'
callnewest_export(['returns-2010-01-05.csv', 'orders-2011-02-01.csv'])returns'orders-2011-02-01.csv'
callnewest_export(['notes.txt', 'summary.csv'])returnsNone