Created
October 18, 2019 00:13
-
-
Save rtorresve/2d587b142f6f819cc0b0d73309a1b767 to your computer and use it in GitHub Desktop.
Script to search items using cement
This file contains 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 characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment