Created
October 18, 2019 00:13
Revisions
-
rtorresve created this gist
Oct 18, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ #!/usr/bin/python3 import subprocess from cement import App def find_occurences(stores, items, fpath=None): print('find ocurrences') for _id in items: if fpath: cmd = "grep {0} file >> {0}99.dat".format(fpath) process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) _ = process.communicate()[0] print('Done', fpath, _id) for store in stores: cmd = "grep {0} items{1}*.dat >> items_0{1}9999.dat".format(_id, store) process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True) _ = process.communicate()[0] print('Done', store, _id) print('finished!!!') class SearchApp(App): class Meta: label = 'searchapp' with SearchApp() as app: app.args.add_argument('-i', '--items', help='items', dest='items') app.args.add_argument('-s', '--stores', help='stores', dest='stores') app.args.add_argument('-f', '--file', help='file', dest='file') app.run() # do something with parsed arguments items = list() stores = list() fpath = None if app.pargs.items: items = app.pargs.items.split(',') if app.pargs.file: fpath = app.pargs.file if app.pargs.stores: stores = app.pargs.stores.split(',') if not stores: stores = ['011', '159', '453'] find_occurences(stores, items, fpath)