-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit.php
62 lines (39 loc) · 1.3 KB
/
init.php
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
54
55
56
57
58
59
60
61
62
<?php
require_once 'groupme.php';
if(!isset($argc)){
if(file_exists('tmp/hashes_store.csv')){
echo 'Has already been initialized.';
exit(1);
} else {
exec('php ./init.php > /dev/null &');
exit(0);
}
}
if($argc == 1){
post_GroupMe('Initializing');
$i = 0;
$last = '';
} else {
$last = $argv[1];
$i = $argv[2];
}
$hasher = getHasher();
$data = '';
$NUM_TO_GET = 100;
$resp = curl_GroupMe($last, $NUM_TO_GET);
//post_GroupMe('Last msg was ' . $last . ', has processed ' . $i . ' images, and found ' . `cat tmp/hashes_store.csv | wc -l` . ' unique');
foreach($resp as $msg){
if($msg['attachments'] && $msg['attachments'][0]['type'] == 'image'){//eventually check for mult attach?
$data .= $msg['id'] . ',' . $hasher->hash($msg['attachments'][0]['url']) . "\n";
$i += 1;
}
}
file_put_contents('tmp/hashes_store.csv', $data, FILE_APPEND);
exec('awk \'{print NR "," $0}\' tmp/hashes_store.csv | sort -u -t , -k 3 | sort -t , -k 1 | cut -d , -f 2- > tmp/hashes_store.csv.tmp && mv tmp/hashes_store.csv.tmp tmp/hashes_store.csv');
$count = count($resp);
if($count < $NUM_TO_GET){
post_GroupMe('Hashed ' . $i . ' images (' . `cat tmp/hashes_store.csv | wc -l` . ' unique) and waiting');
} else {
$last = $resp[$count - 1]['id'];
exec('php ./init.php ' . $last . ' ' . $i . ' > /dev/null &');
}