python - Obtain data from one time to another -



python - Obtain data from one time to another -

i have info unix time epoch. trying separate info falls in particular time range.

for example: total info between 8.00 8.00 pm only. i.e info fall between , including time range.

any suggestions how start please. know not code providing service. clue less how start kind of separation. time zone considered utc +8.00.

input data: col[2] col[3] start time , stop time respectively. 11048 10386 1171753215 1171753234 19 83987 85230 1171753213 1171753234 21 83987 86390 1171753213 1171753236 23 6574 12027 1171753212 1171753233 21 10788 40054 1171753217 1171753236 19 70178 6574 1171753209 1171753229 20 85241 87329 1171753205 1171753233 28 81532 88962 1171753208 1171753231 23 85271 82494 1171753213 1171753234 21 2210 6774 1171753210 1171753234 24 87563 11146 1171753203 1171753226 23 87563 84877 1171753203 1171753228 25 87563 40000 1171753203 1171753229 26

i need separate info of col[2] , col[3] falls in particular time range. time range should able changed when required.

you need compare datetime objects t1.hour >= 8 , t2.hour <= 20 homecoming true 20.01 etc.

from datetime import datetime,time s = "11048 10386 11717532234 1171753234 19" start = time(8, 0, 0) # start 8:00:00 end = time(20, 0, 0) # end 8:00:00 pm spl = s.split() # split line # convert col 2 , 3 datetime objects t1 = datetime.fromtimestamp(float(spl[2])).time() t2 = datetime.fromtimestamp(float(spl[3])).time() print(t1 >= start , t2 <= end)

to extract info file:

from datetime import datetime,time start = time(8, 0, 0) end = time(20, 0, 0) open("input.txt") f,open("output.txt","w") f1: line in f: spl = line.split() t1 = datetime.fromtimestamp(float(spl[2])).time() t2 = datetime.fromtimestamp(float(spl[3])).time() if t1 >= start , t2 <= end: f1.write(line)

python datetime time

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -