supports multiple accounts, removed harcoded account on top, added _credentials_example
This commit is contained in:
parent
0d3b7594f7
commit
8b6d35779e
7 changed files with 84 additions and 10 deletions
0
_credentials_example/.gitkeep
Normal file
0
_credentials_example/.gitkeep
Normal file
2
_credentials_example/client_secret.json
Normal file
2
_credentials_example/client_secret.json
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
{"installed":{"client_id":"XYZ.apps.googleusercontent.com","project_id":"yourproject_with_youtube_access","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"XYZXYZ"}}
|
||||||
|
|
2
_credentials_example/fedi_accounts.txt
Normal file
2
_credentials_example/fedi_accounts.txt
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
your.instance.org|XXXYYY
|
||||||
|
another.instance.com.br|XXXYYY
|
1
_credentials_example/fedilist_id.txt
Normal file
1
_credentials_example/fedilist_id.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
XXXXXXXYYYYYYYYY
|
1
_credentials_example/readeck_account.txt
Normal file
1
_credentials_example/readeck_account.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
your.readeck.fr|XXXXXYYYY
|
1
_credentials_example/token.json
Normal file
1
_credentials_example/token.json
Normal file
|
@ -0,0 +1 @@
|
||||||
|
{"access_token":"XXXYYY","expires_in":3599,"refresh_token":"1\/\/AAABBBCCC","scope":"https:\/\/www.googleapis.com\/auth\/youtube","token_type":"Bearer","expires_at":1755745256}
|
|
@ -1,31 +1,63 @@
|
||||||
#!/usr/bin/php
|
#!/usr/bin/php
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require("add_to_fedilist.php");
|
||||||
|
|
||||||
//-----------------------------
|
//-----------------------------
|
||||||
// CREDENTIALS
|
// CREDENTIALS
|
||||||
//-----------------------------
|
//-----------------------------
|
||||||
|
|
||||||
$MASTODON_TOKEN = '8beea62e32b336e5d934d06a21b0b996';
|
|
||||||
$MASTODON_HOST = 'go.lema.org';
|
|
||||||
|
|
||||||
$READECK_TOKEN = 'LDJb4YbGKe6Fp8cSygpuw5LjmwkgGTAbFbP77TQtYwe1hFZ4';
|
|
||||||
$READECK_HOST = 'read.lema.org';
|
|
||||||
|
|
||||||
$MINIMUM_TEXT_SIZE = 500; // article with less characters of content will be ignored
|
$MINIMUM_TEXT_SIZE = 500; // article with less characters of content will be ignored
|
||||||
|
|
||||||
|
$fediAccounts = loadAccounts(__DIR__ . '/_credentials/fedi_accounts.txt');
|
||||||
|
$readeckAccount = loadAccounts(__DIR__ . '/_credentials/readeck_account.txt');
|
||||||
|
|
||||||
|
// _credentials/readeck_account.txt
|
||||||
|
// should have only one line with host|token
|
||||||
|
// ex: gone.lema.org|XXXXYYYXXXYYY
|
||||||
|
|
||||||
|
$acc = $readeckAccount[0];
|
||||||
|
$READECK_HOST = $acc['host'];
|
||||||
|
$READECK_TOKEN = $acc['token'];
|
||||||
|
|
||||||
|
echo "Readeck Host: $READECK_HOST \n";
|
||||||
|
echo "Fedi Accounts to loop: ".count($fediAccounts)."\n";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// _credentials/fedi_accountst.txt
|
||||||
|
// each line like with host|token
|
||||||
|
// ex: gotosocial.lema.org|XXXXYYYXXXYYY
|
||||||
|
foreach ($fediAccounts as $acc) {
|
||||||
|
$MASTODON_HOST = $acc['host'];
|
||||||
|
$MASTODON_TOKEN = $acc['token'];
|
||||||
|
|
||||||
|
echo "";
|
||||||
|
echo "";
|
||||||
|
echo "--------------------------------\n";
|
||||||
|
echo "Host: $MASTODON_HOST\n";
|
||||||
|
echo "Token: $MASTODON_TOKEN\n";
|
||||||
|
echo "--------------------------------\n";
|
||||||
|
echo "";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//-----------------------------
|
//-----------------------------
|
||||||
// FETCH MASTODON BOOKMARKS
|
// FETCH MASTODON BOOKMARKS
|
||||||
//-----------------------------
|
//-----------------------------
|
||||||
echo "# Fetching mastodon / snac bookmarks...\n";
|
echo "# Fetching mastodon / gotosocial / snac bookmarks...\n";
|
||||||
date_default_timezone_set('America/Sao_Paulo');
|
date_default_timezone_set('America/Sao_Paulo');
|
||||||
echo date('Y-m-d H:i:s')."\n";
|
echo date('Y-m-d H:i:s')."\n";
|
||||||
|
|
||||||
$ch = curl_init("https://$MASTODON_HOST/api/v1/bookmarks");
|
$ch = curl_init("https://$MASTODON_HOST/api/v1/bookmarks");
|
||||||
|
|
||||||
|
#GotoSocial will reply with error "I am a teapot" if no user agent is sent...
|
||||||
curl_setopt_array($ch, [
|
curl_setopt_array($ch, [
|
||||||
CURLOPT_RETURNTRANSFER => true,
|
CURLOPT_RETURNTRANSFER => true,
|
||||||
|
CURLOPT_USERAGENT => "FediSlurperScript/1.0 (https://code.lema.org/santiago/fedi_slurp)",
|
||||||
|
|
||||||
CURLOPT_HTTPHEADER => [
|
CURLOPT_HTTPHEADER => [
|
||||||
"Authorization: Bearer $MASTODON_TOKEN",
|
"Authorization: Bearer $MASTODON_TOKEN",
|
||||||
"Accept: application/json"
|
"Accept: application/json"
|
||||||
|
@ -40,6 +72,8 @@ if (!is_array($bookmarks)) {
|
||||||
|
|
||||||
echo "Found bookmarks:".count($bookmarks)."\n";
|
echo "Found bookmarks:".count($bookmarks)."\n";
|
||||||
|
|
||||||
|
#print_r($bookmarks);
|
||||||
|
|
||||||
//-----------------------------
|
//-----------------------------
|
||||||
// FIND VALID URLs in posts
|
// FIND VALID URLs in posts
|
||||||
//-----------------------------
|
//-----------------------------
|
||||||
|
@ -62,12 +96,17 @@ foreach ($bookmarks as $status) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($links)
|
if (isset($links))
|
||||||
|
{
|
||||||
echo "Valid URLS:".count($links)."\n";
|
echo "Valid URLS:".count($links)."\n";
|
||||||
else
|
|
||||||
echo "NO links founds \n";
|
|
||||||
print_r($links);
|
print_r($links);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
echo "NO links founds. Kthxbye \n";
|
||||||
|
die(0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------
|
//-----------------------------
|
||||||
// SEND LINKS TO READECK
|
// SEND LINKS TO READECK
|
||||||
|
@ -92,7 +131,6 @@ if (!is_dir($alreadySentDir)) {
|
||||||
mkdir($alreadySentDir, 0755, true); // recursive mkdir
|
mkdir($alreadySentDir, 0755, true); // recursive mkdir
|
||||||
}
|
}
|
||||||
|
|
||||||
require("add_to_fedilist.php");
|
|
||||||
|
|
||||||
|
|
||||||
foreach ($links as $link) {
|
foreach ($links as $link) {
|
||||||
|
@ -177,3 +215,32 @@ if (isYouTubeLink($link)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
|
} // end accounts loop
|
||||||
|
|
||||||
|
|
||||||
|
function loadAccounts(string $filepath): array {
|
||||||
|
$accounts = [];
|
||||||
|
|
||||||
|
if (!file_exists($filepath)) {
|
||||||
|
return $accounts; // empty if file not found
|
||||||
|
}
|
||||||
|
|
||||||
|
$lines = file($filepath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||||
|
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
$line = trim($line);
|
||||||
|
if ($line === '') continue;
|
||||||
|
|
||||||
|
[$host, $token] = explode('|', $line, 2);
|
||||||
|
$accounts[] = [
|
||||||
|
'host' => $host,
|
||||||
|
'token' => $token
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $accounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue