track primordial goo frontends
This commit is contained in:
11
contrib/frontends/py/README.md
Normal file
11
contrib/frontends/py/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# python nntpchan demo frontend #
|
||||
|
||||
## usage ##
|
||||
|
||||
add to nntpchan.json hooks section:
|
||||
|
||||
{
|
||||
"name": "pyfront",
|
||||
"exec": "/path/to/frontend.py"
|
||||
}
|
||||
|
9
contrib/frontends/py/frontend.py
Normal file
9
contrib/frontends/py/frontend.py
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
import nntpchan
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
msgid = sys.argv[1]
|
||||
group = sys.argv[2]
|
||||
if nntpchan.addArticle(msgid, group):
|
||||
nntpchan.regenerate(msgid, group)
|
42
contrib/frontends/py/nntpchan/__init__.py
Normal file
42
contrib/frontends/py/nntpchan/__init__.py
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
from nntpchan import store
|
||||
from nntpchan import message
|
||||
from nntpchan import preprocess
|
||||
|
||||
|
||||
def addArticle(msgid, group):
|
||||
"""
|
||||
add article to system
|
||||
:return True if we need to regenerate otherwise False:
|
||||
"""
|
||||
msg = None
|
||||
# open message
|
||||
with store.openArticle(msgid) as f:
|
||||
# read article header
|
||||
hdr = message.readHeader(f)
|
||||
|
||||
mclass = message.MultipartMessage
|
||||
if hdr.isTextOnly:
|
||||
# treat as text message instead of multipart
|
||||
mclass = message.TextMessage
|
||||
elif hdr.isSigned:
|
||||
# treat as signed message
|
||||
mclass = message.TripcodeMessage
|
||||
# create messgae
|
||||
msg = mclass(hdr, f)
|
||||
|
||||
if msg is not None:
|
||||
# we got a message that is valid
|
||||
store.storeMessage(msg)
|
||||
else:
|
||||
# invalid message
|
||||
print("invalid message: {}".format(msgid))
|
||||
return msg is not None
|
||||
|
||||
|
||||
def regenerate(msgid, group):
|
||||
"""
|
||||
regenerate markup
|
||||
"""
|
||||
pass
|
||||
|
Reference in New Issue
Block a user