Skip to content

Commit

Permalink
remove xdate, commit some uncommitted tests
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Jun 12, 2021
1 parent bf19e06 commit 0eaa22b
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 324 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module.exports = {
"env": {
"commonjs": true,
"es2021": true,
"node": true
"node": true,
"mocha": true
},
"extends": "eslint:recommended",
"parserOptions": {
Expand Down
3 changes: 0 additions & 3 deletions botbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ export const log = mwn.log;
/** Parsed console arguments */
export const argv = require('minimist')(process.argv.slice(2));

/** Date library, deprecated (now available in mwn) */
export const xdate = require('./xdate');

/** bot account and database access credentials */
const auth = require('./.auth');
export class AuthManager {
Expand Down
12 changes: 6 additions & 6 deletions old/g13-watch/old-sqlite/save-to-db.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// start job using: npm run start

const {bot, log, xdate, emailOnError} = require('../botbase');
const {bot, log, emailOnError} = require('../botbase');
const EventSource = require('eventsource');
const TextExtractor = require('../TextExtractor')(bot);
const sqlite3 = require('sqlite3');
Expand Down Expand Up @@ -31,9 +31,9 @@ async function main() {
}

const firstrow = await db.get(`SELECT ts FROM g13 ORDER BY ts DESC`);
const lastTs = firstrow ? new Date(firstrow.ts * 1000).toISOString() :
(function() { var d = new xdate(); d.setUTCHours(0, 0, 0, 0); return d.toISOString(); })();

const lastTs = firstrow ? new Date(firstrow.ts * 1000).toISOString() :
(function() { var d = new bot.date(); d.setUTCHours(0, 0, 0, 0); return d.toISOString(); })();

const stream = new EventSource('https://stream.wikimedia.org/v2/stream/recentchange?since=' + lastTs, {
headers: {
Expand Down Expand Up @@ -61,7 +61,7 @@ async function main() {
}
let title = match[1];
let ts = data.timestamp;
log(`[+] Page ${title} at ${new xdate(ts * 1000).format('YYYY-MM-DD HH:mm:ss')}`);
log(`[+] Page ${title} at ${new bot.date(ts * 1000).format('YYYY-MM-DD HH:mm:ss')}`);
let pagedata = await bot.read(title, {prop: 'revisions|description'});
let text = pagedata.revisions && pagedata.revisions[0] && pagedata.revisions[0].content;
let desc = pagedata.description;
Expand Down Expand Up @@ -89,7 +89,7 @@ async function main() {
throw err;
}
};

}

main().catch(err => {
Expand Down
11 changes: 11 additions & 0 deletions redis.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { getRedisInstance, REDIS_HOST } from "./redis";
import assert = require("assert");
import { createLocalSSHTunnel } from "./utils";

it('redis', async function () {
this.timeout(10000);
await createLocalSSHTunnel(REDIS_HOST);
const redis = await getRedisInstance();
await redis.set('qwertyhjupo', '123');
assert.strictEqual(await redis.get('qwertyhjupo'), '123');
});
8 changes: 4 additions & 4 deletions reports/draftify-watch.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const {bot, mwn, log, xdate, utils, emailOnError, TextExtractor} = require('../botbase');
const {bot, mwn, log, utils, emailOnError, TextExtractor} = require('../botbase');
const {formatSummary} = require('./commons');

(async () => {

await bot.getTokensAndSiteInfo();

var ts1 = new xdate().subtract(8, 'days');
var ts1 = new bot.date().subtract(8, 'days');
ts1.setHours(0, 0, 0, 0);
var ts2 = new xdate().subtract(1, 'day');
var ts2 = new bot.date().subtract(1, 'day');
ts2.setHours(0, 0, 0, 0);

// fetch page moves
Expand Down Expand Up @@ -138,7 +138,7 @@ const {formatSummary} = require('./commons');
var user = utils.arrayChunk(data.user.split(''), 14).map(e => e.join('')).join('<br>');

table.addRow([
data.created ? new xdate(data.created).format('YYYY-MM-DD') : '',
data.created ? new bot.date(data.created).format('YYYY-MM-DD') : '',
`[[${page}]] <small>(moved from [[${data.source}]])</small>`,
`<small>${data.excerpt || ''}</small>`,
`[[User:${data.user}|${user}]]`,
Expand Down
8 changes: 4 additions & 4 deletions reports/prod-watch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {bot, log, xdate, mwn, emailOnError} = require('../botbase');
const {bot, log, mwn, emailOnError} = require('../botbase');
const {formatSummary} = require('./commons');

(async function() {
Expand Down Expand Up @@ -311,9 +311,9 @@ const {formatSummary} = require('./commons');

// Triggers:

await main(new xdate().subtract(7, 'days'), 'last week');
await main(new xdate().subtract(14, 'days'), 'last fortnight');
await main(new xdate().subtract(28, 'days'), 'last month');
await main(new bot.date().subtract(7, 'days'), 'last week');
await main(new bot.date().subtract(14, 'days'), 'last fortnight');
await main(new bot.date().subtract(28, 'days'), 'last month');

log(`[i] Finished`);

Expand Down
1 change: 1 addition & 0 deletions webservice/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ describe('articlesearch', () => {
assertValidId(stringToId('lor"m'));
assertValidId(stringToId('lor%$2&()@!m'));
assertValidId(stringToId('lo*^r"m-'));
assertValidId(stringToId('H. P. Lovecraft'));
});
});
Loading

0 comments on commit 0eaa22b

Please sign in to comment.