Skip to content

Commit

Permalink
Merge 14038b8 into 2461cf0
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewshadura committed Oct 4, 2020
2 parents 2461cf0 + 14038b8 commit 441aa1b
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 53 deletions.
2 changes: 1 addition & 1 deletion gtimelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ minimal time logging application
:Manual section: 1


SYNOPSYS
SYNOPSIS
========

**gtimelog** [options]
Expand Down
16 changes: 8 additions & 8 deletions scripts/difftime.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/python
#!/usr/bin/python3
import readline # noqa


def parse_time(s):
h, m = map(int, s.strip().split(':'))
h, m = list(map(int, s.strip().split(':')))
return h * 60 + m


Expand All @@ -20,15 +20,15 @@ def fmt_delta(mins):

while True:
try:
what = raw_input("start, end> ")
what = input("start, end> ")
except EOFError:
print
print()
break
try:
if ',' in what:
t1, t2 = map(parse_time, what.split(','))
t1, t2 = list(map(parse_time, what.split(',')))
else:
t1, t2 = map(parse_time, what.split())
print fmt_delta(t2 - t1)
t1, t2 = list(map(parse_time, what.split()))
print(fmt_delta(t2 - t1))
except ValueError:
print eval(what)
print(eval(what))
2 changes: 1 addition & 1 deletion scripts/export-my-calendar.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python2.3
#!/usr/bin/python3
"""
Experimental script to export GTimeLog data to iCalendar file.
"""
Expand Down
6 changes: 3 additions & 3 deletions scripts/sum.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
import sys
import re

Expand Down Expand Up @@ -33,7 +33,7 @@ def format_time(t):
time = parse_time(line.split(' ')[-1].strip())
if time is None:
continue
print line.rstrip()
print(line.rstrip())
total += time

print "** Total: %s" % format_time(total)
print("** Total: %s" % format_time(total))
18 changes: 8 additions & 10 deletions scripts/timelog.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#!/usr/bin/python
#!/usr/bin/python3
import datetime
import readline # noqa: make raw_input() friendlier


f = open("timelog.txt", "a")
print >> f
f.close()
with open("timelog.txt", "a") as f:
print("", file=f)

while True:
try:
what = raw_input("> ")
what = input("> ")
except EOFError:
print
print()
break
ts = datetime.datetime.now()
line = "%s: %s" % (ts.strftime("%Y-%m-%d %H:%M"), what)
print line
f = open("timelog.txt", "a")
print >> f, line
f.close()
print(line)
with open("timelog.txt", "a") as f:
print(line, file=f)
36 changes: 18 additions & 18 deletions scripts/today.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3

import re
import os
Expand All @@ -8,7 +8,7 @@


def read_timelog(filename):
return file(filename)
return open(filename)


def todays_entries(today, lines):
Expand Down Expand Up @@ -38,7 +38,7 @@ def parse_datetime(dt):
m = re.match(r'^(\d+)-(\d+)-(\d+) (\d+):(\d+)$', dt)
if not m:
raise ValueError('bad date time: ', dt)
year, month, day, hour, min = map(int, m.groups())
year, month, day, hour, min = list(map(int, m.groups()))
return datetime.datetime(year, month, day, hour, min)


Expand Down Expand Up @@ -73,14 +73,14 @@ def print_diff(last_time, time, delta, action):
delta = format_time(delta.seconds / 60)

# format 1
# print "%s%15s %s" % (time, delta, action)
# print("%s%15s %s" % (time, delta, action))

# format 2
action = action[:1].title() + action[1:]
if not delta:
print "%s at %s\n" % (action, time)
print("%s at %s\n" % (action, time))
else:
print "%-62s %s" % (action, delta)
print("%-62s %s" % (action, delta))


def print_diffs(iter):
Expand All @@ -106,7 +106,7 @@ def main(argv=sys.argv):
if k == '-f':
filename = v
if len(args) > 1:
print >> sys.stderr, "too many arguments"
print("too many arguments", file=sys.stderr)
elif len(args) == 1:
if args[0] == 'yesterday':
today = datetime.date.today() - datetime.timedelta(1)
Expand All @@ -119,29 +119,29 @@ def main(argv=sys.argv):
today = datetime.date.today()

title = "Today, %s" % today.strftime('%Y-%m-%d')
print title
print "-" * len(title)
print(title)
print("-" * len(title))
chain = read_timelog(filename)
chain = todays_entries(today, chain)
chain = calculate_diffs(chain)
first_time, last_time, total_time, total_slack = print_diffs(chain)

now = datetime.datetime.now()
print ""
print "Total work done: %s" % format_time(total_time.seconds / 60)
print "Time spent slacking: %s" % format_time(total_slack.seconds / 60)
print ""
print "Time now: %s" % now.strftime('%H:%M')
print()
print("Total work done: %s" % format_time(total_time.seconds / 60))
print("Time spent slacking: %s" % format_time(total_slack.seconds / 60))
print()
print("Time now: %s" % now.strftime('%H:%M'))
if last_time is not None:
delta = now - last_time
print "Time since last entry: %s" % format_time(delta.seconds / 60)
print("Time since last entry: %s" % format_time(delta.seconds / 60))
delta = now - first_time
print "Time since first entry: %s" % format_time(delta.seconds / 60)
print("Time since first entry: %s" % format_time(delta.seconds / 60))
est_end_of_work = last_time + datetime.timedelta(hours=8) - total_time
delta = est_end_of_work - now
print "Time left at work: %s (til %s)" % (
print("Time left at work: %s (til %s)" % (
format_time(delta.seconds / 60),
est_end_of_work.strftime("%H:%M"))
est_end_of_work.strftime("%H:%M")))


if __name__ == '__main__':
Expand Down
10 changes: 5 additions & 5 deletions scripts/workdays.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
"""
Given a constraint to do at least 7 hours of work per day, how many actual
days of work you did in a given week?
Expand Down Expand Up @@ -36,7 +36,7 @@ def main():
if line.startswith('Total work done this week:'):
work_in_minutes = parse_time(line.split(':', 1)[1].strip())
assert work_in_minutes is not None
print line,
print(line)
break
else:
return
Expand All @@ -53,9 +53,9 @@ def main():
def fmt(f):
return ("%.1f" % f).replace(".0", "")

print " Days off: %s" % fmt(days_off)
print " Work days: %s" % fmt(work_days)
print " Average day length: %s" % format_time(avg_day_len)
print(" Days off: %s" % fmt(days_off))
print(" Work days: %s" % fmt(work_days))
print(" Average day length: %s" % format_time(avg_day_len))


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions src/gtimelog/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def search_callback(source, result):
# if several ones match (e.g. the user tried several different
# usernames). This is good because if the wrong username gets
# picked and is rejected by the server, we'll ask the user
# again and then rememebr the more recently provided answer.
# again and then remember the more recently provided answer.
# This is bad only if multiple sets of credentials are valid
# but cause different data to be returned -- the user will
# be forced to launch Seahorse and remove the saved credentials
Expand Down Expand Up @@ -1678,7 +1678,7 @@ def reposition_cursor(self):
self.get_buffer().place_cursor(where)

def scroll_to_end(self):
# If I do the scrolling immediatelly, it won't scroll to the end, usually.
# If I do the scrolling immediately, it won't scroll to the end, usually.
# If I delay the scrolling, it works every time.
# I only wish I knew how to disable the scroll animation.
GLib.idle_add(self._scroll_to_end)
Expand Down
8 changes: 4 additions & 4 deletions src/gtimelog/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_prepare_message_ascii(self):
sender='ASCII Name <test@example.com>',
recipient='activity@example.com',
subject='Report for Mr. Plain',
body='These are the activites done by Mr. Plain:\n...\n',
body='These are the activities done by Mr. Plain:\n...\n',
)
self.assertEqual("ASCII Name <test@example.com>", msg["From"])
self.assertEqual("activity@example.com", msg["To"])
Expand All @@ -36,7 +36,7 @@ def test_prepare_message_ascii(self):
Subject: Report for Mr. Plain
User-Agent: gtimelog/0.11.dev0
These are the activites done by Mr. Plain:
These are the activities done by Mr. Plain:
...
''').replace('0.11.dev0', __version__)
self.assertEqual(expected, msg.as_string())
Expand All @@ -47,7 +47,7 @@ def test_prepare_message_unicode(self):
sender='Ünicødę Name <test@example.com>',
recipient='Anöther nąme <activity@example.com>',
subject='Report for Mr. ☃',
body='These are the activites done by Mr. ☃:\n...\n',
body='These are the activities done by Mr. ☃:\n...\n',
)
expected = textwrap.dedent('''\
MIME-Version: 1.0
Expand All @@ -58,7 +58,7 @@ def test_prepare_message_unicode(self):
Subject: =?utf-8?b?UmVwb3J0IGZvciBNci4g4piD?=
User-Agent: gtimelog/0.11.dev0
VGhlc2UgYXJlIHRoZSBhY3Rpdml0ZXMgZG9uZSBieSBNci4g4piDOgouLi4K
VGhlc2UgYXJlIHRoZSBhY3Rpdml0aWVzIGRvbmUgYnkgTXIuIOKYgzoKLi4uCg==
''').replace('0.11.dev0', __version__)
self.assertEqual(expected, msg.as_string())

Expand Down
2 changes: 1 addition & 1 deletion src/gtimelog/timelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ def to_csv_daily(self, output, title_row=True):
"slacking (hours)", "work (hours)"])

# sum timedeltas per date
# timelog must be cronological for this to be dependable
# timelog must be chronological for this to be dependable

d0 = datetime.timedelta(0)
days = {} # date -> [time_started, slacking, work]
Expand Down

0 comments on commit 441aa1b

Please sign in to comment.