summaryrefslogtreecommitdiff
path: root/web/news_to_html.py
diff options
context:
space:
mode:
Diffstat (limited to 'web/news_to_html.py')
-rwxr-xr-xweb/news_to_html.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/web/news_to_html.py b/web/news_to_html.py
new file mode 100755
index 0000000..0f0b7c1
--- /dev/null
+++ b/web/news_to_html.py
@@ -0,0 +1,66 @@
+#! /usr/bin/env python
+# -*- coding: utf8 -*-
+#
+# Copyright (C) 2018 The Mana World 2
+# Author: Jonatas N. (Jesusalva)
+
+import datetime
+date=str(datetime.date.today())
+
+
+# Prepare to sort from newest to oldest
+dt=open("all_news.bin", "r")
+dc=open("backup.bin", "w")
+for i in dt:
+ dc.write(i)
+dc.close()
+dt.close()
+dt=open("all_news.bin", "w")
+dc=open("backup.bin", "r")
+
+# Read news and prepare header
+ns=open("../update/news.txt", "r")
+dt.write("\n<h3><a name="+date+">"+date+"</a></h3>\n\n<font color=black>")
+
+# Function to markup it
+def markup(r):
+ r=r.replace('##0', '</font><font color=black>')
+ r=r.replace('##1', '<font color=red>')
+ r=r.replace('##2', '<font color=green>')
+ r=r.replace('##3', '<font color=blue>')
+ r=r.replace('##4', '<font color=gold>')
+ r=r.replace('##5', '<font color=yellow>')
+ r=r.replace('##6', '<font color=pink>')
+ r=r.replace('##7', '<font color=purple>')
+ r=r.replace('##8', '<font color=gray>')
+ r=r.replace('##9', '<font color=brown>')
+ r=r.replace('##B', '<b>')
+ r=r.replace('##b', '</b>')
+ r=r.replace('[@@', '<a href="')
+ r=r.replace('|', '">')
+ r=r.replace('@@]', '</a>')
+ return r
+
+# Write the news at all_news.bin, and then reload the backup. Finally, close the file
+for i in ns:
+ dt.write(markup(i)+'<br/>\n')
+dt.write("</font><hr/>")
+for i in dc:
+ dt.write(i)
+
+ns.close()
+dt.close()
+dc.close()
+
+# Write the final HTML page
+wp=open("news.html", "w")
+dt=open("all_news.bin", "r")
+
+wp.write("<!DOCTYPE HTML><html><head><title>Server News</title></head><body>")
+for line in dt:
+ wp.write(line)
+wp.write("</body></html>")
+
+wp.close()
+dt.close()
+