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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#! /usr/bin/env python
# -*- coding: utf8 -*-
#
# Copyright (C) 2018 The Mana World 2
# Author: Jonatas N. (Jesusalva)
import datetime
date=str(datetime.date.today())
#date="2019-08-05"
# Update the INDEX
i1=open("index.bin", "r")
i2=open("1index.bin", "w")
for i in i1:
i2.write(i)
i2.close()
i1.close()
i1=open("index.bin", "w")
i2=open("1index.bin", "r")
i1.write(date+'\n')
for i in i2:
i1.write(i)
i2.close()
i1.close()
i1=open("index.bin", "r")
# 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, and strip new lines
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
def nn(r):
return r.replace('\n', '')
# 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>")
wp.write("<table border=1 align=left><tr><td>Archive</td></tr>")
for i in i1:
wp.write('<tr><td><a href=#'+nn(i)+'>'+nn(i)+'</a></td></tr>')
wp.write('</table><br/>')
for line in dt:
wp.write(nn(line))
wp.write("</body></html>")
wp.close()
dt.close()
i1.close()
|