├── LICENSE ├── commanderroot.txt ├── get_follower_as_list.php └── run_update.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 CommanderRoot 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /get_follower_as_list.php: -------------------------------------------------------------------------------- 1 | 'Followers', 31 | 'variables' => [ 32 | 'limit' => 100, 33 | 'login' => $target_user, 34 | 'order' => 'DESC', 35 | ], 36 | 'extensions' => [ 37 | 'persistedQuery' => [ 38 | 'version' => 1, 39 | 'sha256Hash' => 'deaf3a7c3227ae1bfb950a3d3a2ba8bd47a01a5b528c93ae603c20427e1d829d', 40 | ], 41 | ], 42 | ]]; 43 | if(!empty($cursor)) { 44 | $gqlQuery[0]['variables']['cursor'] = $cursor; 45 | } 46 | 47 | redo_request: 48 | if($error_counter >= 10) { 49 | echo 'Over 10 errors after each other ... stopping here'.PHP_EOL; 50 | if($write_to_file === true) { 51 | fclose($handle); 52 | unlink(__DIR__ . DIRECTORY_SEPARATOR . $target_user.'.tmp.txt'); 53 | } 54 | exit(); 55 | } 56 | 57 | // echo 'Requesting cursor: '.$cursor.PHP_EOL; 58 | curl_setopt($ch, CURLOPT_POST, true); 59 | curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($gqlQuery, JSON_UNESCAPED_UNICODE)); 60 | $curl_ouput = curl_exec($ch); 61 | $curl_info = curl_getinfo($ch); 62 | if($curl_info['http_code'] == 200) { 63 | $json_decode = json_decode($curl_ouput, true); 64 | if($json_decode !== null) { 65 | $error_counter = 0; 66 | if(isset($json_decode[0], $json_decode[0]['data'], $json_decode[0]['data']['user'], $json_decode[0]['data']['user']['followers'], $json_decode[0]['data']['user']['followers']['edges']) && !is_null($json_decode[0]['data']['user']['followers']['edges']) && count($json_decode[0]['data']['user']['followers']['edges']) > 0) { 67 | $string = ''; 68 | foreach($json_decode[0]['data']['user']['followers']['edges'] as $follow) { 69 | if(isset($follow['node']['login'])) { 70 | $string .= $follow['node']['login'].PHP_EOL; 71 | } 72 | 73 | // Update cursor 74 | $cursor = isset($follow['cursor']) ? $follow['cursor'] : ''; 75 | if(empty($cursor)) { 76 | echo PHP_EOL.PHP_EOL.'Done!'.PHP_EOL; 77 | $keep_running = false; 78 | } 79 | } 80 | 81 | echo $string; 82 | 83 | if($write_to_file === true && strlen($string) > 0) { 84 | fwrite($handle, $string); 85 | } 86 | } else { 87 | echo PHP_EOL.PHP_EOL.'Done!'.PHP_EOL; 88 | $keep_running = false; 89 | } 90 | } else { 91 | echo 'Json_decode error ('.json_last_error_msg().') on: '.$curl_ouput.PHP_EOL; 92 | $error_counter++; 93 | sleep(1); 94 | goto redo_request; 95 | } 96 | } elseif($curl_info['http_code'] == 502) { 97 | // Server error so retry 98 | echo '502 error'.PHP_EOL; 99 | $error_counter++; 100 | sleep(1); 101 | goto redo_request; 102 | } elseif($curl_info['http_code'] == 503) { 103 | // Server error so retry 104 | echo '503 error'.PHP_EOL; 105 | $error_counter++; 106 | sleep(1); 107 | goto redo_request; 108 | } elseif($curl_info['http_code'] == 0) { 109 | // Timeout so retry 110 | echo 'Timeout error'.PHP_EOL; 111 | echo 'Curl error: '.curl_error($ch).PHP_EOL; 112 | $error_counter++; 113 | sleep(1); 114 | goto redo_request; 115 | } else { 116 | echo 'HTTP error: '.$curl_info['http_code'].PHP_EOL; 117 | $error_counter++; 118 | sleep(1); 119 | goto redo_request; 120 | } 121 | } 122 | 123 | if($write_to_file === true) { 124 | fclose($handle); 125 | rename(__DIR__ . DIRECTORY_SEPARATOR . $target_user.'.tmp.txt', __DIR__ . DIRECTORY_SEPARATOR . $target_user.'.txt'); 126 | } 127 | 128 | -------------------------------------------------------------------------------- /run_update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | BASEDIR=$(dirname $0) 3 | CURDATE=$(date +"%Y-%m-%d %T") 4 | 5 | if [ -z "$1" ] 6 | then 7 | echo "No channel argument supplied" 8 | exit 1 9 | fi 10 | 11 | php -f ${BASEDIR}/get_follower_as_list.php $1 12 | 13 | cd ${BASEDIR} && git add $1.txt && git commit -m "Update $1 at $CURDATE" && git push 14 | --------------------------------------------------------------------------------