Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WTS version of the script #5

Open
citylims opened this issue Jul 3, 2021 · 2 comments
Open

WTS version of the script #5

citylims opened this issue Jul 3, 2021 · 2 comments

Comments

@citylims
Copy link

citylims commented Jul 3, 2021

For those of you who would also like to convert convert your "want to see" list into CSV format, this just requires a couple small tweaks to the index.js script. This also answers Issue #2 asked by @southisup.

If I get a response to this, I will submit a pull request which can allow for CSV for both myRatings and wts.
Otherwise you can just copy this gist into index.js. Cheers.

const rp = require('request-promise-native')
const fs = require('fs')
const { DateTime } = require('luxon')

const URI = 'https://www.rottentomatoes.com/napi/userProfile/wts/'

// Change to your Rotten Tomatoes user ID
const USER_ID = 'YOUR_ID'

async function getRatings(cursor) {
  try {
    let res = await rp({
      uri: URI + USER_ID,
      json: true,
      qs: { endCursor: cursor },
    })

    console.log('Got a chunk.')

    if (res.pageInfo.hasNextPage) {
      let nextRatings = await getRatings(res.pageInfo.endCursor)
      return res.wtsMedia.concat(nextRatings)
    } else {
      return res.wtsMedia
    }
  } catch (err) {
    console.error('Oops, something went wrong!', err)
  }
}

function createImportFile(ratings) {
  let out = 'Title, Year'

  ratings.forEach(r => {
    if (!r) {
      return
    }
    if (!r.item) {
      return
    }

    let {
      item: { title, releaseYear },
    } = r

    out += `"${title}",${releaseYear} \n`
  })

  fs.writeFile('importMeWTS.csv', out, 'utf8', err => {
    if (err) console.log(err)
    console.log('Import file created - importMeWTS.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)

@southisup
Copy link

Thanks for the offer. I am still interested in getting an export of my WTS list.

@Moglum
Copy link
Owner

Moglum commented Jul 8, 2021

Hi, any contribution is more than welcome. Please send a PR 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants