diff options
| author | 冯昶 <seaker@qq.com> | 2021-03-15 18:18:09 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2021-03-15 18:18:09 +0800 |
| commit | 5ed25077fde85262036c9db3e893d70ae0907b5c (patch) | |
| tree | 8932d25b3fa6076e2d91ab2a331d4d8bfff20544 /challenge-103/roger-bell-west/python/ch-2.py | |
| parent | 8b6be37fe4dac8b4c6489a95e55514b76b298d15 (diff) | |
| parent | 65d54d52500028ec5359a7d39619803ade281543 (diff) | |
| download | perlweeklychallenge-club-5ed25077fde85262036c9db3e893d70ae0907b5c.tar.gz perlweeklychallenge-club-5ed25077fde85262036c9db3e893d70ae0907b5c.tar.bz2 perlweeklychallenge-club-5ed25077fde85262036c9db3e893d70ae0907b5c.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-103/roger-bell-west/python/ch-2.py')
| -rwxr-xr-x | challenge-103/roger-bell-west/python/ch-2.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-103/roger-bell-west/python/ch-2.py b/challenge-103/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..eb804da2eb --- /dev/null +++ b/challenge-103/roger-bell-west/python/ch-2.py @@ -0,0 +1,31 @@ +#! /usr/bin/python3 + +import csv +def wp(ts,tn,csvfile): + td=(tn-ts)*1000; + aoa=list() + with open(csvfile) as csvfile: + cr=csv.reader(csvfile) + for row in cr: + aoa.append(row) + tp=sum(int(t[0]) for t in aoa) + td %= tp + for t in aoa: + t[0]=int(t[0]) + if td < t[0]: + td=int(td/1000) + h=int(td/3600) + m=int(td/60) % 60 + s=td % 60 + return "{:02d}:{:02d}:{:02d} {:s}".format(h,m,s,t[1]) + else: + td -= t[0] + +import unittest + +class TestWp(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(wp(1606134123,1614591276,'t2.csv'),'00:10:24 Les Miserables Episode 1: The Bishop (broadcast date: 1937-07-23)','example 1') + +unittest.main() |
