58 lines · 1.5 KB · Python
RawDownload
import argparseimport osimport xml.etree.ElementTree as ET parser = argparse.ArgumentParser()parser.add_argument(    '-i',    dest='input',    type=str,    metavar='SOURCE',    help='path to your llpp.conf; default to ~/.config/llpp.conf',    default='~/.config/llpp.conf')parser.add_argument(    '-d',    dest='timestamp',    type=int,    help='entries saved earlier than this date will be removed')parser.add_argument(    '-k',    dest='keyword',    type=str,    help='entries with path matching the keyword will be removed')parser.add_argument(dest='dest',                    type=str,                    metavar='DEST',                    help='path to output config file') args = parser.parse_args()source = args.inputcts = args.timestampkeyword = args.keyworddest = args.dest tree = ET.parse(os.path.expanduser(source))root = tree.getroot() print('Removing the following entries in llpp.conf:')i = 0for doc in root.findall('doc'):    # skip entries with bookmarks    if doc.find('bookmarks'):        continue    # remove entries older than 2019.9.1    ts = int(doc.get('last-visit'))    if cts is not None and ts < cts:        print(doc.get('path'))        root.remove(doc)        i += 1        continue    # remove entries whose path contains the keyword    if keyword is not None and keyword in doc.get('path'):        print(doc.get('path'))        root.remove(doc)        i += 1 print(i, 'entries have been removed.',      'The new configuration file has been saved to', dest)tree.write(dest)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t