now creating events and publishing them

This commit is contained in:
2018-06-16 15:17:35 +02:00
parent e0cddbbd27
commit 0533a3101f
2 changed files with 126 additions and 30 deletions

44
event.py Normal file
View File

@ -0,0 +1,44 @@
import yaml
import os
import glob
import re
class Event( object ):
def __init__( self, path, glob ):
self.path = path
self.glob = glob
self.fields = {}
self.doc = ""
def path_short( self ):
# XXX needs tidy
return "content/event/" + os.path.basename( self.path )
def open( self ):
for path in glob.glob( self.glob ):
if os.path.exists( path ):
self.path = path
self.read()
return False
return True
def write( self ):
outfile = open( self.path, 'w', encoding = "utf-8" )
outfile.write( ( '''\
---
%(yaml)s
---
%(md)s
''' % { 'yaml': yaml.dump( self.fields, default_flow_style = False ),
'md': self.doc,
} ) )
def read( self ):
indata = open( self.path, 'r', encoding = "utf-8" ).read()
try:
( pre, yamldata, docdata ) = re.split( "^---$", indata, flags = re.MULTILINE )
except ValueError:
return
self.yaml = yaml.load( yamldata )
self.doc = docdata.strip()