-
Notifications
You must be signed in to change notification settings - Fork 1
/
tsync
executable file
·51 lines (42 loc) · 1.49 KB
/
tsync
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
#!/usr/bin/env python
import sys
import os
import re
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__ )))
from todotxt import TodotxtParser
from tracks import TracksClient
if __name__ == '__main__':
# Show usage
if len(sys.argv) > 2 and sys.argv[2] == "usage":
print "%s tsynch -- synchs local todo.txt with tracks instance data" \
% (os.getenv('TODO_SH'))
sys.exit()
# Get environment values set from config file
TRACKS_URL = os.getenv('TRACKS_URL', '')
TRACKS_USERNAME = os.getenv('TRACKS_USERNAME', '')
TRACKS_PASSWORD = os.getenv('TRACKS_PASSWORD', '')
# Require credentials be present
for credential in ['TRACKS_URL', 'TRACKS_USERNAME', 'TRACKS_PASSWORD']:
if globals()[credential] == '':
print "%s must be set in %s" % (credential, os.getenv('TODOTXT_CFG_FILE'))
sys.exit()
# Require TRACKS_URL be a url
pattern = re.compile('^https?\:\/\/.*')
if not pattern.search(TRACKS_URL):
print "TRACKS_URL set in %s should be a valid URL starting with http(s)://" % \
(os.getenv('TODOTXT_CFG_FILE'))
sys.exit()
tracks_client = TracksClient( {
'url' : TRACKS_URL,
'username' : TRACKS_USERNAME,
'password' : TRACKS_PASSWORD,
'verbose' : True,
}
)
todotxt_parser = TodotxtParser(verbose = True)
todotxt_parser.load()
todotxt_parser.importFromTracks(tracks_client)
todotxt_parser.writeData()
todotxt_parser.load()
todotxt_parser.exportToTracks(tracks_client)
todotxt_parser.writeData()