-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update Dart SDK version (2.17.1 -> 2.17.3) & kassakuitti version * Fix an error with parsing an S-kaupat HTML file * Update dependencies (incl. dev dependencies) * Update transitive dependencies * Changes to arg commands - Move handleArgCommands method into own file - Update help command - Add initially hive command * Some refactoring * Pull Hive initialization to the root level & add count command for Hive CLI * Add methods for Hive CLI & add isNullOrEmpty String extension * Update add, readAll & searchBy methods in Hive CLI * Make needed Hive methods awaitable / asynchronous * Make ean_handler awaitable / asynchronous & close the box in the main method * Update Hive read methods to show the key value (currently an order number) * Fix delete method to delete based on given order number * Fix update method of hive_handling * Refactor printing methods * Fix div parsing in load_html_s_kaupat * Removed '_countProducts' from '_updateProduct' method * Some refactoring into update & delete methods * Fix a bug with digit-beginning receipt product * Refactor update & delete methods * Add installation page & update readme * Add developing page & update readme * Update readme * Update readme
- Loading branch information
Showing
16 changed files
with
443 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Generate `hive_product.g.dart` file | ||
|
||
You can generate `hive_product.g.dart` file by running: | ||
|
||
``` | ||
dart run build_runner build | ||
``` | ||
|
||
This generating process is needed before running the program for the first time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Installation | ||
|
||
## Install Chrome extension & clone this project | ||
|
||
1. Download a Chrome extension called "[snapshot-as-html](https://github.com/areee/snapshot-as-html)" (edited by the author of this project). | ||
- In the [latest release page](https://github.com/areee/snapshot-as-html/releases/latest), go to the assets section and click the "Source code (zip)" link. It'll download the source code to your computer. | ||
- Unzip the zip file. | ||
- Open Google Chrome and go to the [Extensions page](chrome://extensions) (chrome://extensions). | ||
- Enable the developer mode and click "Load unpacked". Browse to the unzipped folder (e.g. `snapshot-as-html-0.1.0`) and go to the subdirectory (`snapshot-as-html`). That folder should include all the extension files, e.g. `manifest.json`. Click "Select" in the open dialog and Google Chrome will load the extension. | ||
2. Git clone this project (or Code → Download ZIP) under your Documents folder (or anywhere you like). Set an alias to use it with `kassakuitti` command (see the next section). | ||
|
||
## Set an alias | ||
|
||
Use `kassakuitti` alias by adding the row below to your profile file. Here we're assuming you have cloned this project under your Documents folder. | ||
|
||
``` | ||
alias kassakuitti='dart run $HOME/Documents/dart_kassakuitti_cli/bin/dart_kassakuitti_cli.dart' | ||
``` | ||
|
||
If you're unsure where to save the alias, this might help you: | ||
|
||
- If you're using _Zsh_ as your shell, use `~/.zshrc` profile file. | ||
- If you're using _Bash_ as your shell, use `~/.bash_profile` profile file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
const kHiveBoxName = 'hiveProducts'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,54 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:args/args.dart'; | ||
import 'read_ean_products.dart'; | ||
import 'ean_products_2_csv.dart'; | ||
import 'specific/s_kaupat/ean_handler.dart'; | ||
import 'specific/s_kaupat/read_receipt_products.dart'; | ||
import 'specific/s_kaupat/receipt_products_2_csv.dart'; | ||
import 'package:hive/hive.dart'; | ||
|
||
import 'constants.dart'; | ||
import 'hive_handling.dart'; | ||
import 'models/hive_product.dart'; | ||
import 'run_main_program.dart'; | ||
import 'utils/arg_selector_helper.dart'; | ||
import 'utils/parse_kassakuitti_arguments.dart'; | ||
import 'utils/printing_helper.dart'; | ||
import 'utils/shop_selector_helper.dart'; | ||
|
||
void main(List<String> arguments) async { | ||
exitCode = 0; // presume success | ||
var hiveProducts = await _initializeHiveProducts(); | ||
|
||
var parser = getParser(); | ||
var argResults = parser.parse(arguments); | ||
|
||
await handleArgCommands(argResults, parser); | ||
await _handleArgCommands(argResults, parser, hiveProducts); | ||
|
||
hiveProducts.close(); | ||
} | ||
|
||
/// Handles the commands in the arguments. | ||
Future<void> handleArgCommands(ArgResults argResults, ArgParser parser) async { | ||
Future<Box<HiveProduct>> _handleArgCommands(ArgResults argResults, | ||
ArgParser parser, Box<HiveProduct> hiveProducts) async { | ||
// Run command | ||
if (argResults.command?.name == ArgSelector.run.value) { | ||
await runMainProgram(argResults, hiveProducts); | ||
} | ||
// Help command | ||
if (argResults.command?.name == ArgSelector.help.value) { | ||
print('Help:\n${parser.usage}'); | ||
else if (argResults.command?.name == ArgSelector.help.value) { | ||
printHelpers(parser); | ||
} | ||
// Run command | ||
else if (argResults.command?.name == ArgSelector.run.value) { | ||
print('\nRunning...\n'); | ||
|
||
var selectedTextFile = argResults[ArgSelector.textFile.value] as String?; | ||
var selectedHtmlFile = argResults[ArgSelector.htmlFile.value] as String; | ||
var selectedStore = argResults[ArgSelector.foodOnlineStore.value] as String; | ||
var csvFilesPath = argResults[ArgSelector.csvPath.value] as String; | ||
|
||
printSelectedValues( | ||
selectedTextFile, selectedHtmlFile, selectedStore, csvFilesPath); | ||
|
||
try { | ||
if (ShopSelector.sKaupat.value == selectedStore) { | ||
var receiptProducts = | ||
await readReceiptProducts(selectedTextFile!, csvFilesPath); | ||
var eanProducts = await readEANProducts( | ||
selectedHtmlFile, ShopSelector.sKaupat, csvFilesPath); | ||
|
||
await eanHandler(receiptProducts, eanProducts.toList()); | ||
|
||
receiptProducts2CSV(receiptProducts, csvFilesPath); | ||
eanProducts2CSV(eanProducts, csvFilesPath, ShopSelector.sKaupat.name); | ||
} else if (ShopSelector.kRuoka.value == selectedStore) { | ||
var eanProducts = await readEANProducts( | ||
selectedHtmlFile, ShopSelector.kRuoka, csvFilesPath); | ||
|
||
eanProducts2CSV(eanProducts, csvFilesPath, ShopSelector.kRuoka.name); | ||
} else { | ||
print('Unknown store: $selectedStore'); | ||
exitCode = 1; | ||
} | ||
} on Exception catch (e) { | ||
print('Error: $e'); | ||
exitCode = 1; | ||
} | ||
|
||
print('\nDone!'); | ||
// Hive (storage) command | ||
else if (argResults.command?.name == ArgSelector.hive.value) { | ||
await hiveHandling(hiveProducts); | ||
} | ||
// Empty command (or other commands, e.g. 'moro' / 'hello') | ||
else { | ||
await printBasicInfo(parser); | ||
} | ||
|
||
return hiveProducts; | ||
} | ||
|
||
/// Initializes the Hive products. | ||
Future<Box<HiveProduct>> _initializeHiveProducts() async { | ||
Hive.init(Directory.current.path); | ||
Hive.registerAdapter(HiveProductAdapter()); | ||
return await Hive.openBox<HiveProduct>(kHiveBoxName); | ||
} |
Oops, something went wrong.