-
Notifications
You must be signed in to change notification settings - Fork 1
/
phone.py
72 lines (64 loc) · 2.27 KB
/
phone.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import gammu
import datetime
##############################################################################################################
# Cell phone interaction
class CellPhone(object):
"""A cell phone object that uses gammu to sychnronize the cell phones todo list"""
def __init__(self):
self.sm = gammu.StateMachine()
self.sm.ReadConfig()
self.sm.Init()
self.tasklist = []
self.__read_entries()
def __read_entries(self):
try:
todo = self.sm.GetNextToDo(Start=True)
except gammu.ERR_EMPTY:
return
self.tasklist.append(self.format_todo(todo))
while True:
loc = todo["Location"]
try:
todo = self.sm.GetNextToDo(Location=loc)
except gammu.ERR_EMPTY:
break
self.tasklist.append(self.format_todo(todo))
def format_todo(self, todo):
duedate = None
taskmsg = ""
for e in todo["Entries"]:
if e["Type"] == "TEXT":
taskmsg = e["Value"]
elif e["Type"] == "ALARM_DATETIME":
duedate = e["Value"]
if todo["Priority"] == None:
priority = 0
elif todo["Priority"] == "Low":
priority = 1
elif todo["Priority"] == "Medium":
priority = 2
elif todo["Priority"] == "High":
priority = 3
taskstr = u"%s +%d " % (taskmsg, priority)
if duedate is not None:
taskstr += u"@%s" % (duedate.isoformat().split("T")[0],)
return taskstr
def write_entry(self, task, when):
if when is None:
hour = 12
else:
hour = int(when)
if task.due is not None:
year, month, day = task.due.split("-")
entries = [{"Type": "ALARM_DATETIME",
"Value": datetime.datetime(day=int(day), year=int(year), month=int(month), hour=hour)}]
else:
entries = []
entries.append({"Type": "TEXT",
"Value": "%s :%s" % (task.task, task.project)})
newentry = {"Priority": "Medium",
"Type": "MEMO",
"Entries": entries}
self.sm.AddToDo(newentry)