1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-22 05:57:28 +01:00
Jisho-Study-Tool/lib/migrations/tools/update_0003.dart
h7x4 67f46ccbc7 Add more functionality to sqlite database
- Automate and cache dart sql generators
- Add RADKFILE
- Add jouyou kanji data
2022-05-08 15:39:57 +02:00

29 lines
741 B
Dart

import 'dart:io';
// TODO: Automate download of radkfile
void main() {
final String content = File('data/radkfile_utf8').readAsStringSync();
final Iterable<String> blocks =
content.replaceAll(RegExp(r'^#.*$'), '').split(r'$').skip(2);
final List<String> tuples = [];
for (final block in blocks) {
final String radical = block[1];
final List<String> kanjiList = block
.replaceFirst(RegExp(r'.*\n'), '')
.split('')
..removeWhere((e) => e == '' || e == '\n');
for (final kanji in kanjiList) {
tuples.add(" ('$radical', '$kanji')");
}
}
File('0003_populate_radkfile.sql').writeAsStringSync(
'''
INSERT INTO RADKFILE(radical, kanji) VALUES
${tuples.join(',\n')};''',
);
}