Supported for --config when scripts are in PATH
[ccoop.git] / ccoop-atomize
1 #!/usr/bin/env python
2
3 import sys,os,datetime
4
5 account=sys.argv[1]
6 name=sys.argv[2]
7 balance=sys.argv[3]
8
9 lines = file(os.path.join(os.getenv("CCPATH"), account+".csv")).readlines()
10 nlines = len(lines)
11
12 print '<?xml version="1.0" encoding="UTF-8"?>'
13 print '<feed xmlns="http://www.w3.org/2005/Atom">'
14 print "<id>tag:nirgal.com,2000:ccoop/"+account+"</id>"
15 print "<title>"+name+" "+account+"</title>"
16 print '<subtitle type="text">Balance: '+balance+'</subtitle>'
17 print "<updated>"+datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")+"</updated>"
18  
19 iline = 0
20 for line in lines:
21     line = line[:-1]
22     iline+=1
23     if not line:
24         continue
25     date,libel1,libel2,amount,sign,checkid = line.split(';')
26     date=date[6:]+"-"+date[3:5]+"-"+date[0:2]
27     libel1=libel1.strip()
28     libel2=libel2.strip()
29     amount=amount.strip()
30     sign=sign.strip()
31     print "<entry>"
32     print "   <id>"+str(nlines-iline)+"</id>"
33     print "   <updated>"+date+"</updated>"
34     print "   <title>"+libel1+"</title>"
35     print "   <content type='text'>"
36     print "      "+libel1
37     print "      "+libel2
38     print "      "+sign
39     print "      "+amount
40     print "      "+checkid
41     print "   </content>"
42     print "</entry>"
43
44 print "</feed>"