Skip to content

Instantly share code, notes, and snippets.

@nowakf
Created January 1, 2018 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nowakf/02ca2563d4e6d27592cfe1fbab3d75fe to your computer and use it in GitHub Desktop.
Save nowakf/02ca2563d4e6d27592cfe1fbab3d75fe to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import datetime
import os
import tasklib
os.environ['XDG_RUNTIME_DIR'] = '/run/user/1000'
now = datetime.datetime.now()
def day(day, time):
try:
alert(day[time], time)
except KeyError:
print("only work hous are defined- change the crontab")
monday = {
9: "creative",
10: "",
11: "",
12: "",
13: "german",
14: "Eat lunch",
15: "physical",
16: "",
17: "writing",
18: "start cooking supper"
}
tuesday = {
9: "creative",
10: "",
11: "",
12: "",
13: "german",
14: "Eat lunch",
15: "physical",
16: "",
17: "shopping",
18: "start cooking supper"
}
wednesday = {
9: "creative",
10: "",
11: "",
12: "",
13: "german",
14: "Eat lunch",
15: "physical",
16: "",
17: "writing",
18: "start cooking supper"
}
thursday = {
9: "creative",
10: "",
11: "",
12: "",
13: "german",
14: "Eat lunch",
15: "physical",
16: "",
17: "writing",
18: ""
}
friday = {
9: "creative",
10: "",
11: "",
12: "",
13: "german",
14: "Eat lunch",
15: "physical",
16: "",
17: "writing",
18: ""
}
saturday = {
9: "",
10: "",
11: "",
12: "Do household stuff",
13: "",
14: "Eat lunch",
15: "",
16: "shopping",
17: "writing",
18: ""
}
sunday = {
9: "",
10: "",
11: "",
12: "",
13: "",
14: "Eat lunch",
15: "",
16: "",
17: "writing",
18: "start cooking supper",
}
def playsound(filename):
path = "~/Music/hoursounds/"
extension = ".ogg"
if os.path.isfile('paplay '+path+filename+extension):
os.system(path+filename+extension)
else:
os.system('paplay '+path+"default"+extension)
projects = {
"writing",
"german",
"creative",
"household",
"shopping",
"physical"
}
def alert(scheduleEntry, time):
if scheduleEntry == "":
os.system('notify-send '+"'take a long break!'")
elif scheduleEntry in projects:
os.system('notify-send "'+scheduleEntry+'"')
tw = tasklib.TaskWarrior(data_location='~/.task', create=False)
tasks = tw.tasks.filter(status='pending', project=scheduleEntry)
if len(tasks) > 0:
for task in tasks:
os.system('notify-send '+str(task))
else:
os.system('notify-send '+"'no "+scheduleEntry+" tasks left'")
else:
os.system('notify-send "'+scheduleEntry+'"')
playsound(scheduleEntry)
days = {
0: monday,
1: tuesday,
2: wednesday,
3: thursday,
4: friday,
5: saturday,
6: sunday
}
try:
day(days[now.today().weekday()], now.hour)
except KeyError:
print("very strange - this isn't a day")
@nowakf
Copy link
Author

nowakf commented Jan 1, 2018

What is this?

It's a script designed to run every work-hour, which will:

  • send a notification either:
    • containing your todolist for a given project,
    • containing the text for the hour,
    • telling you to take a break.
  • play a sound, which can be put in a folder called 'hoursounds'. You need to label the sounds either 'default' or the name of the project.
Why doesn't it work?

This script depends on:

  • tasklib,
  • taskwarrior,
  • cron,
  • pulseaudio-

I was really presenting this more as an idea for an approach to solving a problem, rather than as a drop-in application. I'm not a programmer - and, while I think this is useful (since I don't know of any very simple timetable programs) - I think anybody even barely competent would no doubt be able to improve upon it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment