#!python

import sys
import io

sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')

import cgi, os

form = cgi.FieldStorage()
page_id = form.getvalue('page_id')
title = form.getvalue('title')
description = form.getvalue('description')

opened_file = open('data/' + page_id, 'w')
opened_file.write(description)
opened_file.close()

os.rename('data/'+page_id, 'data/'+title)

#Redirection
print("Location: index.py?id="+title)
print()
