#!/usr/bin/python3

import glob
from datetime import datetime


TIMESTR = datetime.now().strftime('%Y-%m-%d %H:%M:%S')


res = []

for i in glob.glob("config/*.list"):
    print("#", "reading from", i)
    for j in open(i, encoding="utf-8").read().split("\n"):
        val = j.split('#', 1)[0].strip()
        if val != "":
        	res.extend(val.split(" "))


"""
print("#", "final result:")
for x in res:
	print("#", "'%s'" % x)
"""


	
# For hosts
s = """# This file is auto generated by `expt.py` at %s, in https://github.com/zcmimi/hosts-for-working-hard.
# Any changes applied will be removed after next generating.

""" % TIMESTR
for x in res:
	s += "%s 114.215.147.61\n" % x
open("hosts", "w", encoding="utf-8").write(s)


# For mythware_classroom.xml
s = """<!-- This file is auto generated by `expt.py` at %s, in https://github.com/zcmimi/hosts-for-working-hard. -->
<!-- Any changes applied will be removed after next generating. -->

<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<WebPolicy>
    <White count="0" />
    <Black count="%d">
%s
    </Black>
</WebPolicy>
""" % (TIMESTR, len(res), "\n".join(["        <item url=\"%s\" desc=\"\" />" % x for x in res]))

open("mythware_classroom.xml", "w", encoding="utf-8").write(s)
