You are not logged in.
Dear visitor, welcome to Aqua Computer Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
S,XXX (wobei XXX millsekunden sind)|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import datetime
t_hr, t_min, t_sec, t_msec = (12, 45, 7, 123)
tobj = datetime.time(t_hr, t_min, t_sec, t_msec)
print tobj
dtobj = datetime.datetime.combine(datetime.datetime.today(), tobj)
print dtobj
tdelta = datetime.timedelta(hours=2, minutes=17, seconds=31, microseconds=321)
print tdelta
newtime = dtobj + tdelta
print newtime
print newtime.strftime('%H:%M:%S') + (',%06d' % newtime.microsecond)
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import os
import re
from datetime import datetime, timedelta
from time import *
i = 736
last_timeline = ""
out = open("out.txt", 'w')
# 10
# 00:00:47,600 --> 00:00:53,232
# And nothing will save us, except
# the Chalk of fate.
def check(filename, previous_entries, start_time):
global i
num = re.compile('^[0-9]+$') #regulaerer Ausrduck fuer id des Untertitels
current_entries = 0
# regulaerer ausdruck fuer Timestamp: 00:00:21,440 --> 00:00:24,750
time = re.compile('^([0-9]{2}:){2}[0-9]{2},[0-9]{3} --> ([0-9]{2}:){2}[0-9]{2},[0-9]{3}$')
for line in datei:
zahl = num.match(line)
if zahl:
current_entries+=1
out.write(str(i + current_entries) + "\n")
else:
zeit = time.match(line)
if zeit:
start = line[:line.find(" --> ")]
end = line[line.find(" --> ")+5:-1]
last_timeline = line
start = extract_time(start)
end = extract_time(end)
start = start + start_time
end = end + start_time
# rausschreiben, punkte durch Kommata ersetzen
out.write( (str(start)[:-3] + " --> " + str(end)[:-3] + "\n").replace('.', ',') )
else :
out.write(line)
i += current_entries
out.close()
# erwartet eine Zeitangabe im Stil von "00:00:47,600"
def extract_time(zeit):
ms = int(zeit[-3:])
time = zeit[:-4]
time = strptime( time, "%H:%M:%S")
time = timedelta( 0, time.tm_sec, 0, int(zeit[-3:]), time.tm_min, time.tm_hour)
return time
#timedelta( [days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]])
td = timedelta( 0, 45 , 0 ,0 , 7 , 1 )
check("a.txt", i, td)
|
-