-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorrect_num_gen.dart
37 lines (33 loc) · 1.11 KB
/
correct_num_gen.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
import 'dart:convert';
import 'dart:io';
import 'package:http/http.dart' as http;
import './lib/view/utils/constants/const.dart';
import 'lib/view/utils/constants/landscape_objectIDs.dart';
void main() async {
// File name will be changed as needed.
var file = await File('./tmp/test1.txt').create();
// Categories will be changed as needed.
var size = landscapeObjectIDs.length;
var dataList = [];
for (var i = 0; i < size; i++) {
// Categories will be changed as needed.
Uri uri = Uri.parse(api + "${landscapeObjectIDs[i]}");
var response = await http.get(uri);
var parsedData = jsonDecode(response.body) as Map<String, dynamic>;
var imageData = parsedData['primaryImage'];
if (imageData != null) {
try {
var imageResponse = await http.get(Uri.parse(imageData));
if (imageResponse.statusCode == 200) {
dataList.add(landscapeObjectIDs[i]);
await file.writeAsString(dataList.toString() + "\n");
}
print(landscapeObjectIDs[i]);
} catch (e) {
print(e);
}
}
sleep(const Duration(seconds: 2));
}
print("done");
}