Add entries to top of guestbook instead

This commit is contained in:
Tanner Collin 2023-04-19 04:29:41 +00:00
parent 9220022d3e
commit 7943e291fb

View File

@ -46,7 +46,7 @@ async def new_message(event):
await event.reply('Message ID not found. Did the bot restart?')
return
entry = '------------------------------------------------------------\n\n{} - {}'.format(data['date'], data['name'])
entry = '\n\n{} - {}'.format(data['date'], data['name'])
website = data['website']
if website:
@ -59,10 +59,18 @@ async def new_message(event):
entry += ' (<a href="{0}" target="_blank" rel="noreferrer noopener">{0}</a>)'.format(website)
entry += '\n\n{}\n\n'.format(data['message'])
entry += '\n\n{}\n\n------------------------------------------------------------'.format(data['message'])
with open('data/g/index.html', 'a') as f:
with open('data/g/index.html', 'r') as f:
page = f.read()
with open('data/g/index.html', 'w') as f:
header, entries = page.split('===========', maxsplit=1)
f.write(header)
f.write('===========')
f.write(entry)
f.write(entries)
await event.reply('Entry added to t0.vc/g')
logging.info('Added: {}'.format(data))