...
 
Commits (2)
......@@ -77,11 +77,11 @@ module.ftQueries = {
module.processTweet = (err, row) => {
if (err) {
console.error(err.message);
return;
return Promise.reject(err);
}
if (row.id_str === '0') {
return;
return Promise.resolve();
}
if (module.args.options.verbose) {
......@@ -98,16 +98,18 @@ module.processTweet = (err, row) => {
}
if (module.args.options['dry-run']) {
return; // abort before creating status and queueing tweet ID
module.processedTweetIds.push(row.id_str);
return Promise.resolve();
}
(async ( ) => {
const data = await module.masto.createStatus(status);
return module.masto
.createStatus(status)
.then((data) => {
module.processedTweetIds.push(row.id_str);
if (module.args.options.verbose) {
console.log('processed status', { data: data });
console.log('mirrored tweet', { id: row.id_str, status: data });
}
})();
});
};
/*
......@@ -120,6 +122,9 @@ module.updateTweets = ( ) => {
if (!tweetId) {
return Promise.resolve();
}
if (module.args.options.verbose) {
console.log('clearing tweet', { id: tweetId });
}
return new Promise((resolve, reject) => {
module.db.run(module.ftQueries.updateTweet, [tweetId], function(err) {
if (err) {
......@@ -139,15 +144,21 @@ module.updateTweets = ( ) => {
* Process all unprocessed tweets for the opened sqlite3 database.
*/
module.runProcess = ( ) => {
module.db.each(module.ftQueries.getTweets, module.processTweet);
module.updateTweets();
return new Promise((resolve, reject) => {
module.db.each(module.ftQueries.getTweets, module.processTweet, (err, count) => {
if (err) {
return reject(err);
}
return resolve(count);
});
});
};
/*
* Main Entry Point
*/
console.log('connecting to Gab Social');
console.log('connecting to Gab Social');
Masto.Masto
.login({
uri: module.config.instanceUrl,
......@@ -155,7 +166,9 @@ Masto.Masto
})
.then((masto) => {
module.masto = masto;
console.log('connected to Gab Social');
if (module.args.options.verbose) {
console.log('connected to Gab Social');
}
return new Promise((resolve, reject) => {
module.dbFilename = path.join(module.config.dbPath, `${module.args.options.username}.db`);
......@@ -169,10 +182,20 @@ Masto.Masto
});
})
.then(( ) => {
console.log('connected to sqlite3 db', { dbFilename: module.dbFilename });
if (module.args.options.verbose) {
console.log('connected to sqlite3 db', { dbFilename: module.dbFilename });
}
module.processedTweetIds = [ ];
module.db.serialize(module.runProcess);
return module.runProcess();
})
.then(( ) => {
console.log('updating processed tweets');
return module.updateTweets();
})
.then(( ) => {
if (module.args.options.verbose) {
console.log('processed tweets updated');
}
return new Promise((resolve, reject) => {
console.log('disconnecting from sqlite3 db', {
dbFilename: module.dbFilename
......@@ -181,9 +204,11 @@ Masto.Masto
if (err) {
return reject(err);
}
console.log('disconnected from sqlite3 db', {
dbFilename: module.dbFilename
});
if (module.args.options.verbose) {
console.log('disconnected from sqlite3 db', {
dbFilename: module.dbFilename
});
}
});
});
})
......
{
"name": "freetweet",
"version": "1.0.0",
"version": "1.0.1",
"description": "",
"main": "freetweet.js",
"dependencies": {
......@@ -16,4 +16,4 @@
},
"author": "",
"license": "MIT"
}
\ No newline at end of file
}