'is there a way to get the unix date and print out all the times of the day corresponding to that day?
In my executable file (tsk_gettimes), it prints out a unix timestamp with every piece of information it prints out in the terminal. I was wondering if there was a way that i could have the user input a date (2004,09,19) and it outputs all the unix timestamps that happened on that day (in other words, i send off the date above into the unix converter using zero hours, mins, secs, etc. and it prints out all the times of that day) please let me know if i need to word this better!
i have updated the code to using a range but i am receiving no output.
from asyncio import subprocess
import datetime
import time
import subprocess, os
#print("[file name] [year, month, day]")
#filename, keydate = input().split(' ')
def UNIX(date):
#takes in input
x = date
#prints input date as normal
print("[date]", x)
#creates unix timestamp after conversion
keyunix = int(time.mktime(datetime.datetime.strptime(x, "%d/%m/%Y").timetuple()))
#prints unix timestamp
print("[UNIXTimestamp]", keyunix)
return keyunix
# user file input
print("Enter file name with extention")
filename = input()
#print file name
print("[file name]", filename )
assert os.path.exists(filename)
assert os.path.exists("C:\\Program Files\\sleuthkit-4.11.1-win32\\bin\\tsk_gettimes.exe")
# user date input
print("Enter date [dd/mm/yyyy]")
userdate = input()
keydate = str(UNIX(userdate))
#86400 seconds in a day
interval = str(int(keydate) + int('86400'))
print("[interval]",
interval)
#reading the output of the executable fileclear
test = subprocess.run(["C:\\Program Files\\sleuthkit-4.11.1-win32\\bin\\tsk_gettimes.exe", filename],
stdout = subprocess.PIPE)
output = test.stdout.decode().split('\n')
#retreiving all the matches of the keydate (i)
for i in output:
#looking for the keydate in the i
if keydate in i:
#looking if its in range
if keydate in range(keydate,interval):
print(i)
Solution 1:[1]
def UNIX(date):
#takes in input
x = date
#prints input date as normal
print("[date]", x)
#creates unix timestamp after conversion
keyunix = int(time.mktime(datetime.datetime.strptime(x, "%d/%m/%Y").timetuple()))
#prints unix timestamp
print("[UNIXTimestamp]", keyunix)
return keyunix
#looking if its in range
for keydate in str(range(keydate, interval)):
#retreiving all the matches of the keydate (i)
for i in output:
#looking for the keydate in the i
if keydate in i:
print(i)
this printed out the input i needed from the executable.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | study hard |