Last active
January 2, 2016 01:59
-
-
Save gillibrand/8233738 to your computer and use it in GitHub Desktop.
A custom preprocessor for Marked.app that makes it into a super simple time tracker. Finds all the hours in a document (e.g., +1h, +2h, +3h, etc.) and shows the total in a floating badge. Only looks for whole number hours (no minutes or fractions). See a screenshot at http://cl.ly/TB7D
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
#!/usr/bin/env python | |
import sys, re | |
hours_re = re.compile(r'([-+] \d+)h \b', re.X) | |
total = 0 | |
for line in sys.stdin: | |
total += sum(int(hour) for hour in hours_re.findall(line)) | |
print line.strip() | |
print """ | |
<style> | |
.total { | |
position: fixed; | |
top: 0px; | |
right: 10px; | |
background-color: #ff6f08; | |
color: white !important; | |
border-radius: 5px; | |
padding: 4px 6px !important; | |
line-height: normal; | |
} | |
</style> | |
<h3 class="total">%s hours</h3> | |
""" % (total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to process a line at a time instead of buffering the entire file in memory. Should be faster on very large files.