Skip to content

Commit

Permalink
Create jazip
Browse files Browse the repository at this point in the history
  • Loading branch information
kra8 committed Feb 13, 2020
0 parents commit f21dd24
Show file tree
Hide file tree
Showing 10 changed files with 124,792 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
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
10 changes: 10 additions & 0 deletions Makefile
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}
11 changes: 11 additions & 0 deletions README.md
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).
14 changes: 14 additions & 0 deletions analysis_options.yaml
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/**
81 changes: 81 additions & 0 deletions bin/main.dart
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;
}
124,270 changes: 124,270 additions & 0 deletions data/KEN_ALL_ROME.CSV

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions lib/jazip.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int calculate() {
return 6 * 7;
}
Loading

0 comments on commit f21dd24

Please sign in to comment.