Spaceface16518 / strat-collector

Combs through a specific subreddit for posts with over a certain threshold in comments. It then adds them to a database.
MIT License
2 stars 0 forks source link

Validate submission #13

Open Spaceface16518 opened 6 years ago

Spaceface16518 commented 6 years ago

The bot needs to know which posts are submissions and which are not.

This will help the bot sort through the posts more efficiently. Here are some thoughts I had on this.

Code

The code will be simpler, maybe just an includes statement. The module could double check the validation using an consecutive array method. Maybe?

Some suggestions

This would check to see if the title had the keyword submission in it:

data.title.includes('[submission]')

This would remove the [submission] text from the title. This could be invoked right before adding it to data.

if(str.includes('[submission]'){
  str.replace('[submission]', '')
 }

Here is a link for the MDN docs for the replace method.


Another method for loping off the submisson text:

if(str.includes('[submission]'){
  str.substring('[submission]'.length)
 }

In this example, we use the length of the [submission] keyword to take it off the beginning of the title.

This method has some advantages:

But also has some disadvantages:

It will definitely be easier to code. Here is the docs reference for substring.


Format is pretty free, but I would recommend formatting it like I (@Spaceface16518) formatted the export module.

I have formatted it like the following:

module.exports.mainFunction(input: any) {
  if(conditionalFunction(input.part) === "condition") {
    return "return value"
   } else {
    return null
   }

  function conditionalFunction(input: any){
    if(input === condition) {
      return true;
   } else {
      return false;
     }
 }

Summary

Essentially, the point of this (hypothetical) module is to make sure that the bot only pulls posts that contain actual strat submissions. There are limited ways to do this, but the real problem is after the check happens. Formatting is also an issue, and not just for consistency.

Spaceface16518 commented 6 years ago

This module is a pre-req to release v0.1.

Spaceface16518 commented 6 years ago

The export branch is deprecated, this is the new link to the export module