Created
April 15, 2019 05:37
-
-
Save iggyvolz/e8b9df91a8302360b098d985ff1535c3 to your computer and use it in GitHub Desktop.
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
<?php | |
require "xkcd.config.php"; | |
//$lastfile=__DIR__.".xkcd_last"; // temporary file to keep track of the last comic posted | |
//$whurl="https://discordapp.com/api/webhooks/.../..."; // get this url from discord | |
//$xkcdurl="https://xkcd.com/rss.xml"; // get this url from xkcd oh wait i already got it | |
$xml=new SimpleXMLElement(file_get_contents($xkcdurl)); | |
$item=$xml->channel->item; | |
$guid=$item->guid; | |
$lastguid=file_get_contents($lastfile); | |
if(trim($lastguid)===trim($guid)){ | |
die(); // if we already posted this comic, don't post it again | |
} | |
file_put_contents($lastfile,$guid); | |
$data=["content"=>(string)$guid]; | |
$ch = curl_init($whurl); | |
curl_setopt($ch,CURLOPT_POST,1); | |
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($data)); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); | |
curl_exec($ch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment