update denylist docs
This commit is contained in:
parent
aa4ee0382c
commit
ec1ea9710e
1 changed files with 6 additions and 4 deletions
|
@ -58,11 +58,10 @@ from my.ip.all import ips
|
||||||
from my.core.denylist import DenyList
|
from my.core.denylist import DenyList
|
||||||
|
|
||||||
d = DenyList("~/data/ip_denylist.json")
|
d = DenyList("~/data/ip_denylist.json")
|
||||||
d.deny_cli(ips())
|
d.deny_cli(ips()) # automatically writes after each selection
|
||||||
d.write()
|
|
||||||
```
|
```
|
||||||
|
|
||||||
That will open up an interactive `fzf` prompt, where you can select items to add to the denylist
|
That will open up an interactive `fzf` prompt, where you can select an item to add to the denylist
|
||||||
|
|
||||||
This is meant for relatively simple filters, where you want to filter items out
|
This is meant for relatively simple filters, where you want to filter items out
|
||||||
based on a single attribute of a namedtuple/dataclass. If you want to do something
|
based on a single attribute of a namedtuple/dataclass. If you want to do something
|
||||||
|
@ -77,7 +76,7 @@ This would typically be used in an overriden `all.py` file, or in a one-off scri
|
||||||
which you may want to filter out some items from a source, progressively adding more
|
which you may want to filter out some items from a source, progressively adding more
|
||||||
items to the denylist as you go.
|
items to the denylist as you go.
|
||||||
|
|
||||||
A potential `my/ip/all.py` file might look like:
|
A potential `my/ip/all.py` file might look like (Sidenote: `discord` module from [here](https://github.com/seanbreckenridge/HPI)):
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from typing import Iterator
|
from typing import Iterator
|
||||||
|
@ -87,12 +86,15 @@ from my.core.denylist import DenyList
|
||||||
|
|
||||||
deny = DenyList("~/data/ip_denylist.json")
|
deny = DenyList("~/data/ip_denylist.json")
|
||||||
|
|
||||||
|
# all possible data from the source
|
||||||
def _ips() -> Iterator[IP]:
|
def _ips() -> Iterator[IP]:
|
||||||
from my.ip import discord
|
from my.ip import discord
|
||||||
|
# could add other imports here
|
||||||
|
|
||||||
yield from discord.ips()
|
yield from discord.ips()
|
||||||
|
|
||||||
|
|
||||||
|
# filtered data
|
||||||
def ips() -> Iterator[IP]:
|
def ips() -> Iterator[IP]:
|
||||||
yield from deny.filter(_ips())
|
yield from deny.filter(_ips())
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue