summaryrefslogtreecommitdiff
path: root/web/news_to_html.py
blob: 0f0b7c14e0d45e6e8058c0a0c963c4ff3e5fcf3c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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()