-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
88 lines (72 loc) · 2.14 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const rp = require('request-promise-native')
const fs = require('fs')
const { DateTime } = require('luxon')
const URI = 'https://www.rottentomatoes.com/napi/userProfile/movieRatings/'
// Change to your Rotten Tomatoes user ID
const USER_ID = 'YOUR_ID'
const COOKIE = 'YOUR_COOKIE'
async function getRatings(cursor) {
try {
let res = await rp({
uri: URI + USER_ID,
json: true,
qs: {
endCursor: cursor,
},
headers: {
cookie: COOKIE,
},
});
console.log('Got a chunk.')
if (res.pageInfo.hasNextPage) {
let nextRatings = await getRatings(res.pageInfo.endCursor)
return res.ratings.concat(nextRatings)
} else {
return res.ratings
}
} catch (err) {
console.error('Oops, something went wrong!', err)
}
}
function createImportFile(ratings) {
let out = 'Title, Year, Directors, WatchedDate, Rating, Review\n'
ratings.forEach(r => {
if (!r) {
return
}
if (!r.displayName || r.displayName == '' || !r.item) {
return
}
let {
review: { age, score, comment },
item: { title, releaseYear, rt_info },
} = r
let director = ''
rt_info ? (director = rt_info.director.name) : (director = '')
var date = new Date(age);
var watchedDate = date.getFullYear() + "-" + (date.getMonth() + 1).toString().padStart(2, "0") + "-" + date.getDate().toString().padStart(2, "0");
score = score || "";
comment = comment || "";
comment = comment.replace(/\n/g, '<br>')
comment = comment.replace(/\"/g, '\\"')
out += `"${title}",${releaseYear},"${director}",`
out += `${watchedDate},${score},"${comment}"\n`
})
fs.writeFile('importMe.csv', out, 'utf8', err => {
if (err) console.log(err)
console.log('Import file created - importMe.csv')
})
}
getRatings()
.then(ratings => {
fs.writeFileSync(
'rawRatings.json',
JSON.stringify(ratings, null, 2),
'utf8'
)
console.log('Raw ratings file created - rawRatings.json')
createImportFile(ratings)
})
.catch(err => console.error(err))
// let ratings = JSON.parse(fs.readFileSync('rawRatings.json'))
// createImportFile(ratings)