1515from xml .etree .ElementTree import Element , SubElement
1616
1717import argcomplete # type: ignore
18-
1918import things as api
19+
2020from things_cli import __version__
2121
2222
@@ -32,13 +32,37 @@ class ThingsCLI: # pylint: disable=R0902
3232 filter_project = None
3333 filter_area = None
3434 filter_tag = None
35+ only_projects = None
3536
3637 def __init__ (self , database = None ):
3738 """Initialize class."""
3839 self .database = database
3940
4041 def print_tasks (self , tasks ):
4142 """Print a task."""
43+
44+ if self .only_projects :
45+ for task in tasks :
46+ task ["items" ] = (
47+ [
48+ items
49+ for items in task ["items" ]
50+ if items ["type" ] in ["area" , "project" ]
51+ ]
52+ if task .get ("items" )
53+ else []
54+ )
55+ for items in task ["items" ]:
56+ items ["items" ] = (
57+ [
58+ sub_items
59+ for sub_items in items ["items" ]
60+ if sub_items ["type" ] in ["area" , "project" ]
61+ ]
62+ if items .get ("items" )
63+ else []
64+ )
65+
4266 if self .print_json :
4367 print (json .dumps (tasks ))
4468 elif self .print_opml :
@@ -102,7 +126,12 @@ def opml_convert(self, tasks, top):
102126 return
103127 for task in tasks :
104128 area = SubElement (top , "outline" )
105- area .set ("text" , task ["title" ])
129+ text = task ["title" ]
130+ if task .get ("start_date" ):
131+ text = f"{ text } (Scheduled: { task ['start_date' ]} )"
132+ elif task .get ("start" ):
133+ text = f"{ text } ({ task ['start' ]} )"
134+ area .set ("text" , text )
106135 self .opml_convert (task .get ("items" , []), area )
107136 task .pop ("items" , [])
108137 self .opml_convert (task .get ("checklist" , []), area )
@@ -135,7 +164,7 @@ def txt_dumps(self, tasks, indentation="", result=""):
135164 @classmethod
136165 def print_unimplemented (cls , command ):
137166 """Show warning that method is not yet implemented."""
138- print ("command '%s ' not implemented yet" % command , file = sys .stderr )
167+ print (f "command '{ command } ' not implemented yet" , file = sys .stderr )
139168
140169 @classmethod
141170 def get_parser (cls ):
@@ -222,15 +251,22 @@ def get_parser(cls):
222251 # help="anonymize output", dest="anonymize")
223252
224253 parser .add_argument (
225- "-p" , "--filter-project" , dest = "filter_project" , help = "Filter by project"
254+ "-p" , "--filter-project" , dest = "filter_project" , help = "filter by project"
226255 )
227256 parser .add_argument (
228- "-a" , "--filter-area" , dest = "filter_area" , help = "Filter by area"
257+ "-a" , "--filter-area" , dest = "filter_area" , help = "filter by area"
229258 )
230259 parser .add_argument (
231- "-t" , "--filtertag" , dest = "filter_tag" , help = "Filter by tag"
260+ "-t" , "--filtertag" , dest = "filter_tag" , help = "filter by tag"
261+ )
262+ parser .add_argument (
263+ "-e" ,
264+ "--only-projects" ,
265+ action = "store_true" ,
266+ default = False ,
267+ dest = "only_projects" ,
268+ help = "export only projects" ,
232269 )
233-
234270 parser .add_argument (
235271 "-o" ,
236272 "--opml" ,
@@ -275,7 +311,7 @@ def get_parser(cls):
275311 "--version" ,
276312 "-v" ,
277313 action = "version" ,
278- version = "%(prog)s (version {version })" . format ( version = __version__ ) ,
314+ version = f "%(prog)s (version { __version__ } )" ,
279315 )
280316
281317 argcomplete .autocomplete (parser )
@@ -306,6 +342,7 @@ def main(self, args=None):
306342 self .filter_project = args .filter_project or None
307343 self .filter_area = args .filter_area or None
308344 self .filter_tag = args .filter_tag or None
345+ self .only_projects = args .only_projects or None
309346 self .recursive = args .recursive
310347 # self.anonymize = args.anonymize
311348 # self.things3.anonymize = self.anonymize ## not implemented
0 commit comments