Last active
August 25, 2016 11:09
-
-
Save lyoshenka/8ba9ae88b13a5a923d46 to your computer and use it in GitHub Desktop.
Script to pull RSS data and create a Trello card for each post. Useful for Beeminder RSS integration since they don't support it but they do support Trello.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "grin/rss-to-trello", | |
"require": { | |
"simplepie/simplepie": "~1.3", | |
"guzzlehttp/guzzle": "~5.0" | |
}, | |
"authors": [ | |
{ | |
"name": "Alex Grintsvayg", | |
"email": "[email protected]" | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
require __DIR__.'/vendor/autoload.php'; | |
// FILL IN ALL THESE VALUES. ALL ARE REQUIRED | |
const TRELLO_KEY = ''; // https://trello.com/1/appKey/generate | |
const TRELLO_TOKEN = ''; // https://trello.com/1/connect?key=YOUR-KEY-HERE&name=rss2trello&response_type=token&scope=read,write&expiration=never | |
const TRELLO_BOARD_ID = ''; // the hashs after the /b/ when you're viewing the board. e.g. https://trello.com/b/d5jHzcDp/ | |
const TRELLO_LIST = ''; // name of list where cards will be added | |
const FEED_URL = ''; // url of your feed | |
$guzzle = new GuzzleHttp\Client(); | |
$trelloApiEndpoint = 'https://api.trello.com/1'; | |
$trelloAuth = ['key' => TRELLO_KEY, 'token' => TRELLO_TOKEN]; | |
$response = $guzzle->get($trelloApiEndpoint.'/boards/'.TRELLO_BOARD_ID.'/lists/open', ['query' => $trelloAuth]); | |
$lists = $response->json(); | |
$listToUse = null; | |
foreach($lists as $list) | |
{ | |
if ($list['name'] == TRELLO_LIST) | |
{ | |
$listToUse = $list; | |
break; | |
} | |
} | |
if (!$listToUse) | |
{ | |
echo "Could not find list " . TRELLO_LIST . "\n"; | |
die(); | |
} | |
$listData = $guzzle->get($trelloApiEndpoint.'/lists/'.$listToUse['id'], [ | |
'query' => array_merge($trelloAuth, [ | |
'fields' => 'name', | |
'cards' => 'open', | |
'card_fields' => 'id,name,desc' | |
]) | |
]); | |
$cards = $listData->json()['cards']; | |
$existingPostIds = []; | |
foreach($cards as $card) | |
{ | |
$existingPostIds[$card['desc']] = true; | |
} | |
$feed = new SimplePie(); | |
$feed->set_feed_url(FEED_URL); | |
$feed->enable_cache(false); | |
$feed->init(); | |
$items = $feed->get_items(); | |
$count = 0; | |
foreach ($items as $item) | |
{ | |
if (!isset($existingPostIds[$item->get_id()])) | |
{ | |
echo "Adding " . $item->get_title() . "\n"; | |
$guzzle->post($trelloApiEndpoint.'/cards', [ | |
'body' => array_merge($trelloAuth,[ | |
'name' => $item->get_title(), | |
'desc' => $item->get_id(), | |
'due' => null, | |
'idList' => $listToUse['id'], | |
'urlSource' => null | |
]) | |
]); | |
} | |
$count++; | |
if ($count > 1) | |
{ | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In my fork I updated this script to latest versions of
simplepie
andguzzle
. Also I added the possibility to have multiple feeds processed.