Check-in [d995967f72]
Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Introduced --setup option |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
d995967f729d33bf19928cc6675fcf49 |
User & Date: | mario 2022-10-13 08:34:44 |
Context
2022-10-13
| ||
08:35 | doc --setup flag check-in: ca7d968d49 user: mario tags: trunk | |
08:34 | Introduced --setup option check-in: d995967f72 user: mario tags: trunk | |
08:33 | notes from 1.9.77 check-in: 3eff8fb9cb user: mario tags: trunk | |
Changes
Changes to dingonyms/dingonyms.py.
︙ | ︙ | |||
102 103 104 105 106 107 108 | pass# and pray def http_get(url): """ fetch page per requests GET, add user-agent header """ return requests.get( url, | | > | 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | pass# and pray def http_get(url): """ fetch page per requests GET, add user-agent header """ return requests.get( url, headers={"User-Agent":"dingonyms/0.8 (Python 3.x; Linux; CLI/ding; +https://pypi.org/projects/dingonyms)"}, timeout=3 ).text class out: """ output utility functions """ no_antonyms = False no_headers = False |
︙ | ︙ | |||
476 477 478 479 480 481 482 483 484 485 486 487 488 489 | print("Flags:") for name, method, doc in self._methods(): # lazy regex extraction of primary --parameter and |trailing explanation flag = re.findall("\s*([\w\-.]+)\s*\|", doc) help = re.findall("\|\s*(\w+\s*[^|]+(?<!\s))\s*$", doc) if flag: print(f" --{flag[0]:15}\t{help[0] if help else ''}") def _methods(self): # shorthand iterator for name, method in vars(lookup.__class__).items(): yield name, method, method.__doc__ or method.__name__ # instantiate right away | > > > > > > > > > > > > > > > > > > > > > > > > > > | 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 | print("Flags:") for name, method, doc in self._methods(): # lazy regex extraction of primary --parameter and |trailing explanation flag = re.findall("\s*([\w\-.]+)\s*\|", doc) help = re.findall("\|\s*(\w+\s*[^|]+(?<!\s))\s*$", doc) if flag: print(f" --{flag[0]:15}\t{help[0] if help else ''}") def setup(self, *w): """ setup | (setup-?)?ding[rc]* | Configure ~/.dingrc with an entry """ conf_fn = os.path.expanduser("~/.dingrc") conf = open(conf_fn).read() num = int(re.findall("^set searchmpos \{.+?\s(\d)\}", conf, re.M)[0]) + 1 flags = dict( name = "Synonyms (EN)", type = "0", dictfile = "", separator = " :: ", language1 = "Group", language2 = "Synonyms", grepcmd = "dingonyms", grepopts = "--async --thesaurus --merriam --hippo --moby", maxlength = "30", maxresults = "200", minlength = "2", shapedresult = "1", foldedresult = "0" ) add = "".join( f"set searchmeth({str(num)},{key}) {'{'+val+'}'}\n" for key,val in flags.items() ) conf = re.sub("(^set searchmpos[^\}]+)", "\\1 "+str(num), conf, 1, re.M) conf = re.sub("(.+^set searchmeth.+?$)", "\\1\\n" + add, conf, 1, re.S|re.M) open(conf_fn, "w").write(conf) def _methods(self): # shorthand iterator for name, method in vars(lookup.__class__).items(): yield name, method, method.__doc__ or method.__name__ # instantiate right away |
︙ | ︙ |