Update script for updating all plex statuses of requestes.

This commit is contained in:
2019-07-16 18:50:27 +02:00
parent 3a9131a022
commit 3f04d9bc56
2 changed files with 42 additions and 1 deletions

View File

@@ -11,7 +11,7 @@
"test": "cross-env SEASONED_CONFIG=conf/test.json NODE_PATH=. mocha --recursive test/unit test/system",
"coverage": "cross-env SEASONED_CONFIG=conf/test.json NODE_PATH=. nyc mocha --recursive test && nyc report --reporter=text-lcov | coveralls",
"lint": "./node_modules/.bin/eslint src/",
"update": "cross-env SEASONED_CONFIG=conf/development.json NODE_PATH=. node src/plex/updateRequestsInPlex.js"
"update": "cross-env SEASONED_CONFIG=conf/development.json NODE_PATH=. node src/plex/updateRequestsInPlex.js",
},
"dependencies": {
"axios": "^0.18.0",

View File

@@ -0,0 +1,41 @@
const PlexRepository = require('src/plex/plexRepository');
const configuration = require('src/config/configuration').getInstance();
const establishedDatabase = require('src/database/database');
const plexRepository = new PlexRepository();
class UpdateRequestsInPlex {
constructor() {
this.database = establishedDatabase;
this.queries = {
getRequests: `SELECT * FROM requests WHERE status IS 'requested' OR 'downloaded'`,
saveNewStatus: `UPDATE requests SET status = ? WHERE id IS ? and type IS ?`,
}
}
getRequests() {
return this.database.all(this.queries.getRequests);
}
scrub() {
return this.getRequests()
.then((requests) => Promise.all(requests.map(async (movie) => {
return plexRepository.inPlex(movie)
})))
.then((requests_checkInPlex) => requests_checkInPlex.filter((movie) => movie.matchedInPlex))
}
updateStatus(status) {
this.scrub().then((newInPlex) =>
newInPlex.map((movie) => {
console.log('updated', movie.title, 'to', status)
// this.database.run(this.queries.saveNewStatus, [status, movie.id, movie.type])
})
)
}
}
var requestsUpdater = new UpdateRequestsInPlex();
requestsUpdater.updateStatus('downloaded')
module.exports = UpdateRequestsInPlex