-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrawl.dart
53 lines (37 loc) · 1.3 KB
/
crawl.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import 'dart:io';
import 'package:dart_style/dart_style.dart';
import 'package:string_normalizer/src/data/local.dart';
import 'crawler/crawler.dart';
import 'crawler/utils.dart';
void main(List<String> args) async {
final crawler = Crawler();
print('Crawling new data..');
final map = await crawler.crawl();
final flattedMap = flatMap(map);
if (_mapEquals(flattedMap, data)) {
print('The local data is up to date');
print('Done');
return;
}
print('There is an available update');
final file = File('lib/src/data/local.dart');
print('Writing the new data to `lib/data/local.dart`..');
// Write new file
final string = '''
// Copyright (c) 2023, Lam Thanh Nhan. All rights reserved. Use of this source code
// is governed by a MIT license that can be found in the LICENSE file.
//
// Generated by the crawler. Run `dart run tool/crawl.dart` to re-generate.
const data = ''';
final dartText = '$string${crawler.crawledDataToString(map)}';
file.writeAsStringSync(DartFormatter().format(dartText));
print('Done');
}
bool _mapEquals(Map<String, String> map1, Map<String, String> map2) {
if (map1.keys.length != map2.keys.length) return false;
for (String k in map1.keys) {
if (!map2.containsKey(k)) return false;
if (map1[k] != map2[k]) return false;
}
return true;
}