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

add playground environment, inspired heavily from israeli-ynab-updater #116

Merged
merged 2 commits into from
Jun 10, 2018
Merged

add playground environment, inspired heavily from israeli-ynab-updater #116

merged 2 commits into from
Jun 10, 2018

Conversation

esakal
Copy link
Collaborator

@esakal esakal commented Apr 15, 2018

An integrated playground environment that can be used to maintain/extend scrapers:

  • Simplifies the development workflow by providing a safe way to run the scrapers.
  • Enables using IDE debugging tools.

Copy link
Owner

@eshaham eshaham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal 👍 left some comments

CONTRIBUTING.md Outdated
## Using the playground
> With the integrated playground support, you can easily extend the scrapers and also enjoy the IDE debug feature if needed.

Once you prepare the playground environment you will be able to set scraping options, debug using the IDE and get the scraped transactions as generated csv file.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal files*

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

package.json Outdated
"lint": "eslint src playground",
"playground:prepare": "npm run prepublishOnly && babel playground --out-dir .playground-lib",
"playground:scrape": "node .playground-lib/scrape.js",
"playground:setup": "node .playground-lib/setup.js",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal why not simply run the playground:scrape and playground:setup scripts using babel-cli to avoid the need to prepare stuff every time?

Copy link
Collaborator Author

@esakal esakal Apr 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding babel-cli make sense, but I didn't want to do major changes to the current project structure. If you want I can change the workflow to use babel-cli. let me know.

A prerequisite will be to make sure that we can add breakpoints somewhere when using babel-cli, otherwise we are missing the point of having playground support

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal I don't think this is a major change, we don't even have to add another dependency to use it (it's included under babel module).

A prerequisite will be to make sure that we can add breakpoints somewhere when using babel-cli, otherwise we are missing the point of having playground support

Good point, but I'm sure this is doable.

CONTRIBUTING.md Outdated
### Run a scraper
To run a scraper you should:
1. Provide the scraper credentials by running `npm run playground:setup`.
1. Set scraper options in file `.playground-lib/scrape-options.js`. Make sure you are not modifying the original file under `playground` folder.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal I would personally much rather providing the option in the command line than saving them under a temp file in the playground lib folder

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not practical providing it in command line:

  • many IDEs like webstorm doesn't play nice with command line prompt in debug mode. I tried to debug ynab-updater that is using inquirer and gave up after an hour or so.

  • setup the IDE is easier, just mention the path to the scrape.js and you are all set
    image

  • it is more practical defining them once and then re-running the same preset with few clicks as possible.
    image

Copy link
Owner

@eshaham eshaham Apr 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal got it.
Then, I would rather save the options under ${os.homedir()}/.bank-scrapers-playground, than under the repos folders.
What do you think?

CONTRIBUTING.md Outdated

> To keep your credentials safe, they will be stored in a separated folder under your os home directory as defined in file `playground/definitions.js`. The default value is set to `{homedir}/.bank-scrapers-playground`.

> The generated report will be added under `.playground-lib/output` folder. This folder is being ignored by github and npm to prevent exposing your data.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal Again, I would prefer setting this using command line parameter, and would definitely not output into the lib folder. I prefer to create as little personal / local files under the repo folder, even if they are excluded using .gitignore

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The motivation to put it under playground-lib was to create an isolated folder underwith we have all the playground assets. To remove the playground with all its related files all you need to do is to delete this folders. We can consider changing the folder names so:
./playground -> ./playground-src or ./src-playground
./playground-lib -> ./playground
./playground-lib/output -> ./playground/output

wdyt?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal I really hate mixing code and output under the repo.
Why can't the output go somewhere else, like in the ynab-updater repo?

CONTRIBUTING.md Outdated
> Before your push your changes to github, it is your responsibility to review changes and make sure that only desired information are being commited.

### Make changes to scrapers
The playground is using the transpiled files created in `lib` folder.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal what's the benefit of using the playground if it doesn't import the original files directly?
If you're importing the lib files, you can just as well create this playground in a different repo.
Or am I missing the motivation for this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writing a playground in a different repo takes time, you can see the amount of code I needed to include here just to support the core debugging flows.

Also you cannot debug using the IDE between two projects, having the playground internally allow you to add breakpoints which is what was the original motivation for having the playground.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal understood.
But why not import the source files directly, instead of the transpiled files?

CONTRIBUTING.md Outdated
### Debug your changes using the IDE
To run the playground scripts within your IDE debugger, make sure you use file `.playground-lib/scrape.js`

If you want to set breakpoints, you should add them to the transpiled code under `lib` folders. Any breakpoints added to the `src` folder will be ignored by the IDE.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal which is why we should import the source files and not the lib folder, see comment above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, quoted from my previous reply:

A prerequisite will be to make sure that we can add breakpoints somewhere when using babel-cli, otherwise we are missing the point of having playground support

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal 👍

"Headers": true
},
"extends": "airbnb-base"
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal this file should only specify the differences from the .eslintrc file in the root directory, not repeat all the settings. See here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

import crypto from 'crypto';

const ALGORITHM = 'aes-256-ctr';
const SALT = '8cs+8Y(nxDLY';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal perhaps use a different salt than what we use in https://github.com/eshaham/israeli-ynab-updater

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having the salt in source-version which means exposing the salt value misses the point of having encryptions at all.

I think we should create an issue addressing the current behavior. wdyt?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal agree

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

startDate: moment().add(-2, 'months'),
combineInstallments: false,
saveLocation: `${__dirname}/output`,
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal as mentioned above, I would not want this to be setup under the repo.
My favorite option would be to supply these as command line parameters (we could provide sample bash scripts).
The other option would be to instruct the user to save these settings under the config folder.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My favorite option would be to supply these as command line parameters

It is possible, yet I don't see the big advantage of having them as a cli arguments unless you want this feature to be added to ynab-updater as an alternative to the existing flow which requires user interactions

The other option would be to instruct the user to save these settings under the config folder

I personally try to avoid forcing the user to perform manual step if possible as I find them error prone and confusing.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal ok.
But can we save it for the user under ${os.homedir()}/.bank-scrapers-playground?

import { encryptCredentials } from './helpers/credentials';
import CONFIG_FOLDER from './definitions';


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal redundant line break

@esakal
Copy link
Collaborator Author

esakal commented Apr 16, 2018

@eshaham see my replies, I will push fixes once we resolve all the open issues.

@esakal
Copy link
Collaborator Author

esakal commented May 17, 2018

@eshaham I think you are going to love the commit I just pushed.

Interactive setup

Setup of playground credentials and options is done with interactive menus. No need to change sources as it was before.

Executing scraping without any cli interactions/prompts

I moved the selection of the scraper into the setup process so we can run the scraping process without prompting for information, this allow us to utilize the IDE debugger.

Debug the source files

I'm using babel-register to transpile and run the sources without creating them. This allow us to set breakpoints in the sources directly.

External folders for settings and output files

Per your request I moved both the setting file and the output files outside from the library folder as you did in israeli-ynab-updater.

@esakal
Copy link
Collaborator Author

esakal commented May 23, 2018

@eshaham let me know if you have any further thoughts/comments

@esakal
Copy link
Collaborator Author

esakal commented Jun 7, 2018

@eshaham Hi,
Can I assist somehow with the pending PRs?

Copy link
Owner

@eshaham eshaham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal really sorry, busy couple of weeks!

@@ -9,7 +9,9 @@
"main": "lib/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint src",
"lint": "eslint src playground",
"start": "node -r babel-register playground/scrape.js",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@esakal never tried using babel-register in the past, looks interesting... 👍

@eshaham eshaham merged commit 169fbf8 into eshaham:master Jun 10, 2018
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

Successfully merging this pull request may close these issues.

3 participants