-
Notifications
You must be signed in to change notification settings - Fork 0
/
slackExample.php
97 lines (81 loc) · 2.8 KB
/
slackExample.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
require_once('RCGroupsForumSpyScraper.php');
/**
* Grab your Token: Go to https://api.slack.com/web to create your access-token. The token will look somewhat like this:
* xoxo-2100000415-0000000000-0000000000-ab1ab1
*
* https://api.slack.com/custom-integrations/legacy-tokens
*
* @param string $message The message to post into a channel.
* @param string $channel The name of the channel prefixed with #, example #foobar
* @return boolean
*/
function slack($message, $channel)
{
$ch = curl_init("https://slack.com/api/chat.postMessage");
$data = http_build_query([
"token" => "",
"channel" => $channel, //"#mychannel",
"text" => $message, //"Hello, Foo-Bar channel message.",
"username" => "rcg_spy_scraper",
]);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
/**
* set up the new object
*/
$RCG = new RCGroupsForumSpyScraper();
/**
* define the keywords we wish to filter on.
*/
//$RCG->keywords = ['x9d', 'qx7', 'Taranis', 'astrox'];
$RCG->forums = [
'Aircraft - Electric - Multirotor (FS/W)',
'Aircraft - General - Radio Equipment (FS/W)',
'FPV Equipment (FS/W)'
];
/**
* Scrap the results
*/
$results = $RCG->scrap();
/**
* print off the results
*/
if(!empty($results)) {
$rcgurl = 'https://www.rcgroups.com/forums/showthread.php?';
$message = "Found post within the following Threads '" . implode("', '", $RCG->forums) . "' \n";
$message .= "with the following Keywords '" . implode("', '", $RCG->keywords) . "' \n\n";
/**
* Example:
* (
* [what] => New Post
* [when] => Today 01:04 PM
* [title] => Durafly Bf-109E 1100mm - Official owners thread
* [urltitle] => Durafly-Bf-109E-1100mm-Official-owners-thread
* [preview] => Yeah, that's why triggered it I'm sure. For yucks, I dropped a DF Mk1 Spit in my cart just now. When I went to check out, sure enough, free shipping. Good Job HK! Sure hope it...
* [poster] => FLTRI
* [threadid] => 2767987
* [postid] => 39009623
* [lastpost] => 1516298646
* [userid] => 454055
* [forumid] => 248
* [forumname] => Electric Warbirds
* )
*/
foreach($results as $post)
{
$message .= "Title: *{$post->title}*\n";
$message .= "When: *{$post->when}*\n";
$message .= "URL: " . $rcgurl . $post->threadid . '-' . $post->urltitle . "\n";
$message .= "Preview: {$post->preview}\n\n";
$message .= "----------------------------------------------------------\n\n";
}
$slack = slack(print_r($message, true), 'rcgroup-spyscraper');
}
print_r($results);