-
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.
- Loading branch information
kra8
committed
Feb 13, 2020
0 parents
commit f21dd24
Showing
10 changed files
with
124,792 additions
and
0 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,11 @@ | ||
# Files and directories created by pub | ||
.dart_tool/ | ||
.packages | ||
|
||
# Conventional directory for build outputs | ||
build/ | ||
|
||
# Directory created by dartdoc | ||
doc/api/ | ||
|
||
.DS_Store |
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,10 @@ | ||
VERSION=0.1.0 | ||
|
||
default: | ||
cat ./Makefile | ||
|
||
.PHONY: build | ||
build: | ||
mkdir -p build/jazip-${VERSION} | ||
dart2native bin/main.dart -o build/jazip-${VERSION}/jazip | ||
tar -zcvf build/jazip-${VERSION}.tar.gz build/jazip-${VERSION} |
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,11 @@ | ||
# JaZip | ||
郵便番号から住所を検索するCLIツール。 | ||
|
||
``` sh | ||
$ jazip 2790031 | ||
千葉県,浦安市,舞浜 | ||
``` | ||
|
||
### Created by stagehand | ||
Created from templates made available by Stagehand under a BSD-style | ||
[license](https://github.com/dart-lang/stagehand/blob/master/LICENSE). |
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,14 @@ | ||
# Defines a default set of lint rules enforced for | ||
# projects at Google. For details and rationale, | ||
# see https://github.com/dart-lang/pedantic#enabled-lints. | ||
include: package:pedantic/analysis_options.yaml | ||
|
||
# For lint rules and documentation, see http://dart-lang.github.io/linter/lints. | ||
# Uncomment to specify additional rules. | ||
# linter: | ||
# rules: | ||
# - camel_case_types | ||
|
||
analyzer: | ||
# exclude: | ||
# - path/to/excluded/files/** |
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,81 @@ | ||
// import 'package:jazip/jazip.dart' as jazip; | ||
import 'dart:io'; | ||
import 'dart:async'; | ||
import 'dart:convert'; | ||
import 'package:path/path.dart' as path; | ||
import 'package:args/args.dart'; | ||
|
||
final argParser = ArgParser(); | ||
final CSV_DATA_FILE_NAME = 'KEN_ALL_ROME.CSV'; | ||
|
||
void main(List<String> arguments) { | ||
final argResults = argParser.parse(arguments); | ||
if (argResults.rest.isEmpty) { | ||
exit(1); | ||
} | ||
|
||
final postcode = argResults.rest.first; | ||
getAddressCSVFile().then((csvFile) => runCommand(csvFile, postcode)); | ||
} | ||
|
||
void runCommand(File csvFile, String postcode) { | ||
Stream fileReader = csvFile.openRead(); | ||
fileReader | ||
.transform(utf8.decoder) | ||
.transform(LineSplitter()) | ||
.listen( | ||
(String line) { | ||
var values = line.split(','); | ||
if (values.first.contains(postcode)) { | ||
var output = '${values[1]},${values[2]},${values[3]}'.replaceAll('"', '').replaceAll(' ', ''); | ||
stdout.writeln(output); | ||
exit(0); | ||
} | ||
}, | ||
onDone: () => exit(1) | ||
); | ||
} | ||
|
||
String getHomePath() { | ||
String home; | ||
final envVars = Platform.environment; | ||
if (Platform.isMacOS) { | ||
home = envVars['HOME']; | ||
} else if (Platform.isLinux) { | ||
home = envVars['HOME']; | ||
} else if (Platform.isWindows) { | ||
home = envVars['UserProfile']; | ||
} | ||
|
||
return home; | ||
} | ||
|
||
Directory configureCacheDirectory() { | ||
final cacheDir = Directory(path.fromUri('${getHomePath()}/.jazip')); | ||
if (!cacheDir.existsSync()) { | ||
cacheDir.createSync(); | ||
} | ||
return cacheDir; | ||
} | ||
|
||
Future<File> getAddressCSVFile() async { | ||
final cacheDir = configureCacheDirectory(); | ||
final csvPath = path.join(cacheDir.path, CSV_DATA_FILE_NAME); | ||
final csvFile = File(csvPath); | ||
if (!csvFile.existsSync()) { | ||
return fetchAddressData(csvFile); | ||
} | ||
|
||
var completer = Completer<File>(); | ||
completer.complete(csvFile); | ||
return completer.future; | ||
} | ||
|
||
Future<File> fetchAddressData(File file) async { | ||
final url = 'https://raw.githubusercontent.com/kra8/jazip/master/data/${CSV_DATA_FILE_NAME}'; | ||
var httpClient = HttpClient(); | ||
var request = await httpClient.getUrl(Uri.parse(url)); | ||
var response = await request.close(); | ||
await response.pipe(file.openWrite()); | ||
return file; | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
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,3 @@ | ||
int calculate() { | ||
return 6 * 7; | ||
} |
Oops, something went wrong.