Skip to content

Commit 566dc7f

Browse files
pqrspqrs
pqrs
authored and
pqrs
committed
Uploaded example file
1 parent ea9a0bb commit 566dc7f

File tree

3 files changed

+104
-2
lines changed

3 files changed

+104
-2
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ lastrss.txt
22
tests/lastrss.txt
33
your.log
44
rssnotifier.php
5-
tests/test.php
65
regit.sh
76
data.txt

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ define( "OAUTH_TOKEN", "XXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
135135
define( "OAUTH_SECRET", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" );
136136
```
137137

138-
And then we call the ** function, inside the foreach loop, under the Facebook code we saw above:
138+
And then we call the *post2twitter* function, inside the foreach loop, under the Facebook code we saw above:
139139

140140
``` php
141141
if (post2twitter( CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET, $value->title . " " . $value->link ) ) {
@@ -176,6 +176,8 @@ And, as usual, inside the foreach loop, under the Twitter code:
176176

177177
In further revisions of this repository I will write about how you can get all these keys and create Twitter and Facebook applications.
178178

179+
You can find the file we have just created in [tests folder](tests).
180+
179181

180182
## Prerequisites
181183

tests/test.php

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
<?php
2+
3+
define( "TIMEZONE", "Europe/Madrid" ); // Your timezone
4+
define( "RSS_FEED", "https://www.cnbc.com/id/100727362/device/rss/rss.html" ); // The RSS feed URL
5+
6+
// Telegram
7+
define( "TELEGRAM_USER_ID", "XXXXXXXX" ); // Your telegram User ID
8+
define( "BOT_AUTH_TOKEN", "XXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXX" ); // Telegram bot token
9+
10+
// Facebook
11+
define( 'APP_ID', "XXXXXXXXXXXXXXX" );
12+
define( 'APP_SECRET', "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" );
13+
define( 'GROUP_ID', "XXXXXXXXXXXXXXX" );
14+
define( 'PAGE_ACCESS_TOKEN', "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" );
15+
16+
// Twitter
17+
define( "CONSUMER_KEY", "XXXXXXXXXXXXXXXXXXXXXXXXX" );
18+
define( "CONSUMER_SECRET", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" );
19+
define( "OAUTH_TOKEN", "XXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" );
20+
define( "OAUTH_SECRET", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" );
21+
22+
// Android App
23+
define( "API_ACCESS_KEY", "XXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" );
24+
25+
26+
date_default_timezone_set(TIMEZONE);
27+
28+
require_once __DIR__ . '/vendor/autoload.php'; // Autoload files using Composer autoload
29+
30+
include __DIR__ . '/includes/functions.php';
31+
32+
use CheckRSS\RSS;
33+
34+
$rss = new RSS;
35+
36+
// Gets all the items published in the rss feed and stores them in $items
37+
$items = $rss->getItems(RSS_FEED);
38+
39+
// Checks which items are new since last check
40+
if ($newitems = $rss->getNewItems($items) ) {
41+
42+
foreach ($newitems as $value) {
43+
44+
post2telegram(TELEGRAM_USER_ID, BOT_AUTH_TOKEN, "NEW ITEM: " . $value->title); // Sends item title to telegram
45+
46+
logit( "RSS", "New item found -> $value->title", "info" );
47+
48+
49+
$linkData = [ // Sends item link & description to FB page
50+
'link' => $value->link,
51+
'message' => strip_tags($value->description),
52+
];
53+
54+
if (post2facebookpage(APP_ID, APP_SECRET, GROUP_ID, PAGE_ACCESS_TOKEN, $linkData)) {
55+
56+
post2telegram(TELEGRAM_USER_ID, BOT_AUTH_TOKEN, "PUBLICADO EN FACEBOOK: " . $value->title . PHP_EOL . PHP_EOL . strip_tags($value->description) . PHP_EOL . PHP_EOL . $value->link );
57+
logit( "Facebook", "New publication in Facebook -> $value->title", "info" );
58+
59+
} else {
60+
61+
post2telegram(TELEGRAM_USER_ID, BOT_AUTH_TOKEN, "ERROR: No se pudo publicar en Facebook la noticia '" . $value->title . "'" );
62+
logit( "Facebook", "Couldn't publish to Facebook -> $value->title", "error" );
63+
64+
}
65+
66+
67+
if (post2twitter( CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET, $value->title . " " . $value->link ) ) {
68+
69+
post2telegram(TELEGRAM_USER_ID, BOT_AUTH_TOKEN, "PUBLICADO EN TWITTER: " . $value->title . PHP_EOL . PHP_EOL . strip_tags($value->description) . PHP_EOL . PHP_EOL . $value->link );
70+
logit( "Twittter", "New tweet -> $value->title", "info" );
71+
72+
73+
} else {
74+
75+
post2telegram(TELEGRAM_USER_ID, BOT_AUTH_TOKEN, "ERROR: No se pudo publicar en Twitter la noticia '" . $value->title . "'" );
76+
logit( "Twitter", "Couldn't publish to Twitter -> $value->title", "error" );
77+
78+
}
79+
80+
81+
if (androidnotification( API_ACCESS_KEY, $value->title ) ) {
82+
83+
post2telegram(TELEGRAM_USER_ID, BOT_AUTH_TOKEN, "ENVIADA NOTIFICACIÓN ANDROID: " . $value->title );
84+
logit( "Android", "New Android notification -> $value->title", "info" );
85+
86+
} else {
87+
88+
post2telegram(TELEGRAM_USER_ID, BOT_AUTH_TOKEN, "ERROR: No se pudo enviar a dispositivos Android '" . $value->title . "'" );
89+
logit( "Android", "Couldn't notify to Android app -> $value->title", "error" );
90+
91+
}
92+
93+
}
94+
95+
} else {
96+
97+
logit( "RSS", "No new items found", "info" );
98+
99+
}
100+
101+
?>

0 commit comments

Comments
 (0)