Write new QEC log for each email
This commit is contained in:
parent
e871aefbaa
commit
2ebd8c5235
|
@ -25,3 +25,7 @@ if payload==payload.rstrip():
|
|||
|
||||
log("title = {!r}".format(title))
|
||||
log("payload = {!r}".format(payload))
|
||||
|
||||
filename = utils.get_name_from_title(title)
|
||||
|
||||
utils.write_file(filename,payload)
|
||||
|
|
24
utils.py
24
utils.py
|
@ -1,7 +1,10 @@
|
|||
import sys,os,contextlib,builtins,email
|
||||
import sys,os,contextlib,builtins,email,re
|
||||
|
||||
NOT_ALPHANUM = re.compile("[^A-Za-z0-9]")
|
||||
|
||||
inp = email.message_from_file(sys.stdin)
|
||||
homedir = os.path.dirname(__file__)
|
||||
ship = "anon.hmm.st"
|
||||
|
||||
def input():
|
||||
return inp
|
||||
|
@ -18,3 +21,22 @@ def open(*args,**kwargs):
|
|||
yield f
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
def getshipdir():
|
||||
return os.path.join(homedir,"ships",ship)
|
||||
|
||||
def get_name_from_title(title):
|
||||
shipdir = getshipdir()
|
||||
t = NOT_ALPHANUM.sub("-",title)
|
||||
t = t[:10]
|
||||
if os.path.exists(os.path.join(shipdir,t+".txt")):
|
||||
n = 1
|
||||
while os.path.exists(os.path.join(shipdir,t+str(n)+".txt")):
|
||||
n+=1
|
||||
return os.path.join(shipdir,t+str(num)+".txt")
|
||||
else: return os.path.join(shipdir,t+".txt")
|
||||
|
||||
def write_file(filename,text):
|
||||
with open(filename,"w") as f:
|
||||
f.write(text)
|
||||
os.chmod(filename,0o666)
|
||||
|
|
Loading…
Reference in New Issue