You are not logged in.
HI, i have this little bookmark script in python: https://github.com/carnager/robot/blob/master/robot
there are 2 functions that spit out the same output, but one is filtered (listAll and listURL)
while listAll is formatted nicely, I couldnt manage to format the listURL stuff.
for convinience here are both functions:
def listURL(args):
bookmarkfile = open(str(bmarks), 'r')
bookmarks = json.loads(bookmarkfile.read(), 'r')
bookmarkfile.close()
if args.group:
url = [bookmark['name'] + " " + bookmark['url'] + " " + ', '.join(bookmark['tags']) + " " + bookmark['group'] for bookmark in bookmarks if bookmark['group'] == str(args.group)]
print("\n".join(url))
if args.tag:
url = [bookmark['name'] + " " + bookmark['url'] + " " + ', '.join(bookmark['tags']) + " " + bookmark['group'] for bookmark in bookmarks if args.tag in bookmark['tags']]
print("\n".join(url))
def listAll(args):
bookmarkfile = open(str(bmarks))
bookmarks = json.loads(bookmarkfile.read())
bookmarkfile.close()
if args.urls:
for x in bookmarks:
print("%-40s %-90s %77s %15s" % (x['name'], x['url'], ', '.join(x['tags']), x['group']))
else:
for x in bookmarks:
print("%-40s %77s %15s" % (x['name'], ', '.join(x['tags']), x['group']))
Any idea how to format listURL too?
Last edited by Rasi (2014-08-24 00:36:40)
He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.
Douglas Adams
Offline
I'm a little confused...
i have this little bookmark script in python
What does it do?
there are 2 functions that spit out the same output, but one is filtered (listAll and listURL)
while listAll is formatted nicely, I couldnt manage to format the listURL stuff.
What is the output? What does "filtered" mean? Which one is filtered?
Any idea how to format listURL too?
What do you want to format "listURL" to? JPEG?
Offline
Use the same format in both functions.
def listURL(args):
bookmarkfile = open(str(bmarks), 'r')
bookmarks = json.loads(bookmarkfile.read(), 'r')
bookmarkfile.close()
fstr = "%-40s %-90s %77s %15s"
if args.group:
for x in bookmarks:
if x['group'] == str(args.group):
print(fstr % (x['name'], x['url'], ', '.join(x['tags']), x['group']))
if args.tag:
for x in bookmarks:
if args.tag in x['tags']:
print(fstr % (x['name'], x['url'], ', '.join(x['tags']), x['group']))
If you want to use Python 3 style formating (which also works with recent versions of python 2), substitute the following:
fstr = "{:40s} {:90s} {:77s} {:15s}"
...
print(fstr.format(x['name'], x['url'], ', '.join(x['tags']), x['group']))
Offline
thanks, its working perfectly
He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.
Douglas Adams
Offline