Commit 1b749299 authored by nanahira's avatar nanahira

finish

parent d4898080
Pipeline #221 passed with stages
in 2 minutes and 9 seconds
# tx3-bang-reader
Read TX3 bang and parse it
Reads TX3 bang http://bang.tx3.163.com and parse it.
## How to use
* `npm run build`
* Create a `config.yaml` file based on `config.example.yaml`.
* `npm run fetch`
## Docker image
You may also build a Docker image from the Dockerfile here. mount a `config.yaml` file into `/usr/src/app`.
\ No newline at end of file
outDir: ./output
useMySQL: false
server: null # server name array if specific servers
MySQLConfig:
host: mysql
user: tx3
......
......@@ -41,6 +41,7 @@ export const servers = [
export interface Config {
outDir: string;
server: string[];
useMySQL: boolean,
MySQLConfig: mysql.PoolConfig,
proxy: ProxyConfig
......
......@@ -7,7 +7,10 @@ let fetcher;
async function runServer(server: string) {
const users = await fetcher.fetchListFromServer(server);
await fs.promises.writeFile(`./output/servers/${server}.json`, JSON.stringify(users, null, 2));
await fs.promises.writeFile(`./output/servers/${server}.json`, JSON.stringify({
date: fetcher.date,
data: users
}, null, 2));
return users;
}
......@@ -22,8 +25,8 @@ async function main() {
const config: Config = yaml.parse(await fs.promises.readFile("./config.yaml", "utf8"));
fetcher = new Tx3Fetcher(config);
await fetcher.init();
if (process.env.SERVER) {
await runServer(servers[parseInt(process.env.SERVER)]);
if (config.server) {
await Promise.all(config.server.map(runServer));
return;
}
const userListWithServer = await Promise.all(servers.map(runServer));
......@@ -31,7 +34,10 @@ async function main() {
for (let i = 0; i < servers.length;++i) {
allServersList[servers[i]] = userListWithServer[i];
}
await fs.promises.writeFile(`./output/all.json`, JSON.stringify(allServersList, null, 2));
await fs.promises.writeFile(`./output/all.json`, JSON.stringify({
date: fetcher.date,
data: allServersList
}, null, 2));
process.exit();
}
main();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment