Update script for updating all plex statuses of requestes.
This commit is contained in:
@@ -11,7 +11,7 @@
|
|||||||
"test": "cross-env SEASONED_CONFIG=conf/test.json NODE_PATH=. mocha --recursive test/unit test/system",
|
"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",
|
"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/",
|
"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": {
|
"dependencies": {
|
||||||
"axios": "^0.18.0",
|
"axios": "^0.18.0",
|
||||||
|
|||||||
41
seasoned_api/src/plex/updateRequestsInPlex.js
Normal file
41
seasoned_api/src/plex/updateRequestsInPlex.js
Normal 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
|
||||||
Reference in New Issue
Block a user