Skip to content

Instantly share code, notes, and snippets.

@misTrasteos
Created February 10, 2021 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misTrasteos/684c28d372aeb55071bad870e67a1454 to your computer and use it in GitHub Desktop.
Save misTrasteos/684c28d372aeb55071bad870e67a1454 to your computer and use it in GitHub Desktop.
Generate a week of minutes for fake log purposes
import datetime
now = datetime.datetime.now().replace(second=0, microsecond=0)
# I use replace method to round to second and microsecond, as datetime is inmutable
minutesInAWeek = 7 * 24 * 60 # 7 days in a week, 24 hours a day, 60 minutes an hour
for i in reversed(range(minutesInAWeek)):
minuteInThePast = now - datetime.timedelta(minutes = i)
# microseconds in python are 6 digits, I "cut" the last 3
timeText = minuteInThePast.strftime('%Y-%m-%d %H:%M:%S,%f')[:-3]
finalText = '[{timeText}] - ...'.format(timeText=timeText)
print( finalText )

Output sample

[2021-02-10 22:14:00,000] - ...
[2021-02-10 22:15:00,000] - ...
[2021-02-10 22:16:00,000] - ...
[2021-02-10 22:17:00,000] - ...
[2021-02-10 22:18:00,000] - ...
[2021-02-10 22:19:00,000] - ...
[2021-02-10 22:20:00,000] - ...
[2021-02-10 22:21:00,000] - ...
[2021-02-10 22:22:00,000] - ...
[2021-02-10 22:23:00,000] - ...
[2021-02-10 22:24:00,000] - ...
[2021-02-10 22:25:00,000] - ...
[2021-02-10 22:26:00,000] - ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment