2017 © Pedro Peláez
 

library checkrss

Check rss feeds for new items

image

pqrs/checkrss

Check rss feeds for new items

  • Wednesday, February 14, 2018
  • by pqrs
  • Repository
  • 1 Watchers
  • 0 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

CheckRSS

Check RSS feeds for new items, (*1)

CheckRSS provides some methods to:, (*2)

  • Get all the items in a RSS feed
  • Check which of those items is/are new since last check
  • Write a log every time a checking for new items is run

It is recommended using CheckRSS with a cron job so you can get new items periodically, although you can run it manually too., (*3)

Installation

composer require pqrs/checkrss=dev-master

Alternatively, add the dependency directly to your composer.json file:, (*4)

"require": {
    "pqrs/checkrss": "dev-master"
}

Then add to your php code:, (*5)

``` php require_once DIR . '/vendor/autoload.php'; // Autoload files using Composer autoload, (*6)

use CheckRSS\RSS;, (*7)


## Usage ### method getItems($feed_url) This method gets **all the items** published in the rss feed and returns an object containing them. ``` php $rss = new RSS; $items = $rss->getItems("http://feeds.nbcnews.com/feeds/topstories");

An example of the object returned would be:, (*8)

SimpleXMLElement Object
(
    [guid] => https://www.nbcnews.com/storyline/hurricane-irma/...
    [title] => One-two punch of disease and Irma has left Florida citrus reeling
    [pubDate] => Sat, 10 Feb 2018 15:17:00 GMT
    [link] => https://www.nbcnews.com/storyline/hurricane-irma/...
    [description] => Hurricane Irma served as a knockout punch for many of Florida's...
)

method getNewItems($items)

This method checks which items in a feed (obtained with getItems) are new since the last a check was made., (*9)

Returns an object with just the new items., (*10)

``` php $rss = new RSS;, (*11)

// Gets all the items published in the rss feed and stores them in $items $items = $rss->getItems("http://feeds.nbcnews.com/feeds/topstories");, (*12)

// Checks which items are new since last check if ($newitems = $rss->getNewItems($items) ) {, (*13)

// Prints new items
echo "New items found:" . PHP_EOL . PHP_EOL;

foreach ($newitems as $value) {

    echo $value->title          . PHP_EOL;
    echo $value->description    . PHP_EOL;
    echo $value->guid           . PHP_EOL;
    echo $value->link           . PHP_EOL. PHP_EOL;

}

} else {, (*14)

echo "There'are no new items in RSS feed";

} ```, (*15)

method storeLastItemID($item_id)

Internal use. This method writes the last read item id in a file to compare it in future checks., (*16)

method isNewItem($item_id)

Internal use. This method compares the last read item id with the last stored one in previous check., (*17)

method WriteLog($logline)

A simple method to write a log file everytime a check is made., (*18)

Examples

You can find some uses for these functions in tests folder., (*19)

Prerequisites

PHP 5.3.0, (*20)

Contributing

Contributions are of course very welcome!, (*21)

Credits

Copyright © 2018 Alvaro Piqueras - pqrs, (*22)

This is a cleanup of a dirty code I wrote some time ago. Also it's my first try with GitHub, Composer and Packagist so if you find some mistakes or have some tips for me, I would be more than glad to hear you., (*23)

I hope this code suites your needs., (*24)

License

This project is licensed under the MIT License - see the LICENSE file for details., (*25)

The Versions

14/02 2018

dev-master

9999999-dev

Check rss feeds for new items

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Avatar pqrs