Created
November 27, 2018 15:48
-
-
Save TakamiChie/e245185d35af17b40e040c2bd2376467 to your computer and use it in GitHub Desktop.
文章中の時間表記をシフトするPythonコードのひな形
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# あとで再利用可能な形にまとめるかも | |
# ex). 23:00→30分前を指定 22:30 | |
import re | |
import math | |
s = """ | |
ここに変換したい文章を入れる | |
""" | |
def timeshift(m): | |
t = int(m.group(1)) * 60 + int(m.group(2)) | |
t -= 0 # ここでタイムシフトしたい時間(分)を指定する | |
return "{0:02d}:{1:02d}".format(math.floor(t // 60), int(t % 60)) | |
print(re.sub(r'(\d{1,2}):(\d{1,2})', timeshift, s)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment