├── .github ├── FUNDING.yml ├── build ├── run-tests.sh └── workflows │ ├── pull_request.yml │ ├── push.yml │ └── release.yml ├── LICENSE ├── README.md ├── go.mod ├── go.sum ├── rss2hook.go ├── sample.cfg └── webhook └── webhook.go /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | github: skx 3 | custom: https://steve.fi/donate/ 4 | -------------------------------------------------------------------------------- /.github/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # The basename of our binary 4 | BASE="rss2hook" 5 | 6 | 7 | # I don't even .. 8 | go env -w GOFLAGS="-buildvcs=false" 9 | 10 | # 11 | # We build on only a single platform/arch. 12 | # 13 | BUILD_PLATFORMS="linux" 14 | BUILD_ARCHS="amd64" 15 | 16 | # For each platform 17 | for OS in ${BUILD_PLATFORMS[@]}; do 18 | 19 | # For each arch 20 | for ARCH in ${BUILD_ARCHS[@]}; do 21 | 22 | # Setup a suffix for the binary 23 | SUFFIX="${OS}" 24 | 25 | # i386 is better than 386 26 | if [ "$ARCH" = "386" ]; then 27 | SUFFIX="${SUFFIX}-i386" 28 | else 29 | SUFFIX="${SUFFIX}-${ARCH}" 30 | fi 31 | 32 | # Windows binaries should end in .EXE 33 | if [ "$OS" = "windows" ]; then 34 | SUFFIX="${SUFFIX}.exe" 35 | fi 36 | 37 | echo "Building for ${OS} [${ARCH}] -> ${BASE}-${SUFFIX}" 38 | 39 | # Run the build 40 | export GOARCH=${ARCH} 41 | export GOOS=${OS} 42 | export CGO_ENABLED=1 43 | 44 | go build -ldflags "-X main.version=$(git describe --tags)" -o "${BASE}-${SUFFIX}" 45 | 46 | done 47 | done 48 | -------------------------------------------------------------------------------- /.github/run-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | # I don't even .. 5 | go env -w GOFLAGS="-buildvcs=false" 6 | 7 | 8 | # Install the tools we use to test our code-quality. 9 | # 10 | # Here we setup the tools to install only if the "CI" environmental variable 11 | # is not empty. This is because locally I have them installed. 12 | # 13 | # NOTE: Github Actions always set CI=true 14 | # 15 | if [ ! -z "${CI}" ] ; then 16 | go install golang.org/x/lint/golint@latest 17 | go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest 18 | go install honnef.co/go/tools/cmd/staticcheck@latest 19 | fi 20 | 21 | 22 | # Run the static-check tool - we ignore errors in goserver/static.go 23 | t=$(mktemp) 24 | staticcheck -checks all ./... | grep -v "is deprecated"> $t 25 | if [ -s $t ]; then 26 | echo "Found errors via 'staticcheck'" 27 | cat $t 28 | rm $t 29 | exit 1 30 | fi 31 | rm $t 32 | 33 | 34 | 35 | # At this point failures cause aborts 36 | set -e 37 | 38 | # Run the linter 39 | echo "Launching linter .." 40 | golint -set_exit_status ./... 41 | echo "Completed linter .." 42 | 43 | # Run the shadow-checker 44 | echo "Launching shadowed-variable check .." 45 | go vet -vettool=$(which shadow) ./... 46 | echo "Completed shadowed-variable check .." 47 | 48 | # Run golang tests 49 | go test ./... 50 | -------------------------------------------------------------------------------- /.github/workflows/pull_request.yml: -------------------------------------------------------------------------------- 1 | on: pull_request 2 | name: Pull Request 3 | jobs: 4 | test: 5 | name: Test 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@master 9 | - name: Test 10 | uses: skx/github-action-tester@master 11 | -------------------------------------------------------------------------------- /.github/workflows/push.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: 4 | - master 5 | name: Push Event 6 | jobs: 7 | test: 8 | name: Test 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@master 12 | - name: Test 13 | uses: skx/github-action-tester@master 14 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | on: release 2 | name: Handle Release 3 | jobs: 4 | upload: 5 | name: Upload 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@master 9 | - name: Generate the artifacts 10 | uses: skx/github-action-build@master 11 | - name: Upload 12 | uses: skx/github-action-publish-binaries@master 13 | env: 14 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 15 | with: 16 | args: rss2hook-* 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Go Report Card](https://goreportcard.com/badge/github.com/skx/rss2hook)](https://goreportcard.com/report/github.com/skx/rss2hook) 2 | [![license](https://img.shields.io/github/license/skx/rss2hook.svg)](https://github.com/skx/rss2hook/blob/master/LICENSE) 3 | [![Release](https://img.shields.io/github/release/skx/rss2hook.svg)](https://github.com/skx/rss2hook/releases/latest) 4 | 5 | * [RSS2Hook](#rss2hook) 6 | * [Rational](#rational) 7 | * [Installation](#installation) 8 | * [Build without Go Modules (Go before 1.11)](#build-without-go-modules-go-before-111) 9 | * [Build with Go Modules (Go 1.11 or higher)](#build-with-go-modules-go-111-or-higher) 10 | * [Setup](#setup) 11 | * [Sample Webhook Receiver](#sample-webhook-receiver) 12 | * [Implementation Notes](#implementation-notes) 13 | * [Github Setup](#github-setup) 14 | 15 | 16 | # RSS2Hook 17 | 18 | This project is a self-hosted utility which will make HTTP POST 19 | requests to remote web-hooks when new items appear in an RSS feed. 20 | 21 | 22 | 23 | ## Rational 24 | 25 | I have a couple of webhooks in-place already which will take incoming 26 | HTTP submissions and "do stuff" with them, for example: 27 | 28 | * Posting to my alerting system. 29 | * Which is called [purppura](https://github.com/skx/purppura/) and is pretty neat. 30 | * Posting to IRC. 31 | * IRC was mattermost before slack before born. 32 | 33 | I _also_ have a bunch of RSS feeds that I follow, typically these include 34 | github releases of projects. For example my git-host runs [gitbucket](https://github.com/gitbucket/gitbucket) so I subscribe to the release feed of that, to ensure I'm always up to date: 35 | 36 | * https://github.com/gitbucket/gitbucket/releases.atom 37 | 38 | 39 | ## Installation 40 | 41 | There are two ways to install this project from source, which depend on the version of the [go](https://golang.org/) version you're using. 42 | 43 | If you prefer you can fetch a binary from [our release page](https://github.com/skx/rss2hook/releases). Currently there is only a binary for Linux (amd64) due to the use of `cgo` in our dependencies. 44 | 45 | ## Build without Go Modules (Go before 1.11) 46 | 47 | go get -u github.com/skx/rss2hook 48 | 49 | ## Build with Go Modules (Go 1.11 or higher) 50 | 51 | git clone https://github.com/skx/rss2hook ;# make sure to clone outside of GOPATH 52 | cd rss2hook 53 | go install 54 | 55 | 56 | 57 | ## Setup 58 | 59 | There are two parts to the setup: 60 | 61 | * Configure the list of feeds and the corresponding hooks to POST to. 62 | * Ensure the program is running. 63 | 64 | For the first create a configuration-file like so: 65 | 66 | http://example.com/feed.rss = https://webhook.example.com/notify/me 67 | 68 | (There is a sample configuration file [sample.cfg](sample.cfg) which 69 | will demonstrate this more verbosely.) 70 | 71 | You can use your favourite supervision tool to launch the deamon, but you 72 | can test interactively like so: 73 | 74 | $ rss2hook -config ./sample.cfg 75 | 76 | 77 | 78 | ### Sample Webhook Receiver 79 | 80 | There is a simple webserver located beneath [webhook/](webhook/) which 81 | will listen upon http://localhost:8080, and dump any POST submission to the 82 | console. 83 | 84 | You can launch it like so: 85 | 86 | cd webhook/ 87 | go run webhook.go 88 | 89 | Testing it via `curl` would look like this: 90 | 91 | $ curl --header "Content-Type: application/json" \ 92 | --request POST \ 93 | --data '{"username":"blah","password":"blah"}' \ 94 | http://localhost:8080/ 95 | 96 | The [sample.cfg](sample.cfg) file will POST to this end-point so you can 97 | see how things work: 98 | 99 | $ rss2hook --config=sample.cfg 100 | 101 | 102 | 103 | ## Implementation Notes 104 | 105 | * By default the server will poll all configured feeds immediately 106 | upon startup. 107 | * It will look for changes every five minutes. 108 | * To ensure items are only announced once state is kept on the filesystem. 109 | * Beneath the directory `~/.rss2hook/seen/`. 110 | * Feed items are submitted to the webhook as JSON. 111 | 112 | 113 | 114 | ## Github Setup 115 | 116 | This repository is configured to run tests upon every commit, and when 117 | pull-requests are created/updated. The testing is carried out via 118 | [.github/run-tests.sh](.github/run-tests.sh) which is used by the 119 | [github-action-tester](https://github.com/skx/github-action-tester) action. 120 | 121 | Releases are automated in a similar fashion via [.github/build](.github/build), 122 | and the [github-action-publish-binaries](https://github.com/skx/github-action-publish-binaries) action. 123 | 124 | Steve 125 | -- 126 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/skx/rss2hook 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/PuerkitoBio/goquery v1.9.2 // indirect 7 | github.com/mmcdole/gofeed v1.3.0 8 | github.com/mmcdole/goxpp v1.1.1 // indirect 9 | github.com/robfig/cron v1.2.0 10 | ) 11 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 2 | github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI= 3 | github.com/PuerkitoBio/goquery v1.9.2 h1:4/wZksC3KgkQw7SQgkKotmKljk0M6V8TUvA8Wb4yPeE= 4 | github.com/PuerkitoBio/goquery v1.9.2/go.mod h1:GHPCaP0ODyyxqcNoFGYlAprUFH81NuRPd0GX3Zu2Mvk= 5 | github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA= 6 | github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss= 7 | github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU= 8 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 9 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 10 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 11 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 12 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 13 | github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= 14 | github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= 15 | github.com/mmcdole/gofeed v1.3.0 h1:5yn+HeqlcvjMeAI4gu6T+crm7d0anY85+M+v6fIFNG4= 16 | github.com/mmcdole/gofeed v1.3.0/go.mod h1:9TGv2LcJhdXePDzxiuMnukhV2/zb6VtnZt1mS+SjkLE= 17 | github.com/mmcdole/goxpp v1.1.1-0.20240225020742-a0c311522b23/go.mod h1:v+25+lT2ViuQ7mVxcncQ8ch1URund48oH+jhjiwEgS8= 18 | github.com/mmcdole/goxpp v1.1.1 h1:RGIX+D6iQRIunGHrKqnA2+700XMCnNv0bAOOv5MUhx8= 19 | github.com/mmcdole/goxpp v1.1.1/go.mod h1:v+25+lT2ViuQ7mVxcncQ8ch1URund48oH+jhjiwEgS8= 20 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 21 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= 22 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 23 | github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= 24 | github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= 25 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 26 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 27 | github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ= 28 | github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k= 29 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 30 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 31 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 32 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 33 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 34 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 35 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 36 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 37 | github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= 38 | github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= 39 | github.com/urfave/cli v1.22.3/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= 40 | github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= 41 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 42 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 43 | golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= 44 | golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= 45 | golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= 46 | golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 47 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 48 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 49 | golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 50 | golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 51 | golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE= 52 | golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= 53 | golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= 54 | golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= 55 | golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= 56 | golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= 57 | golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= 58 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 59 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 60 | golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 61 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 62 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 63 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 64 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 65 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 66 | golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 67 | golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 68 | golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 69 | golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 70 | golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 71 | golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 72 | golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 73 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 74 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 75 | golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA= 76 | golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= 77 | golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= 78 | golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= 79 | golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= 80 | golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= 81 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 82 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 83 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 84 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 85 | golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 86 | golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 87 | golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= 88 | golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= 89 | golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= 90 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 91 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 92 | golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= 93 | golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= 94 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 95 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= 96 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 97 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 98 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 99 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 100 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 101 | -------------------------------------------------------------------------------- /rss2hook.go: -------------------------------------------------------------------------------- 1 | // rss2hook is a simple utility which will make HTTP POST 2 | // requests to remote web-hooks when new items appear in an RSS feed. 3 | // 4 | // Steve 5 | // 6 | 7 | package main 8 | 9 | import ( 10 | "bufio" 11 | "bytes" 12 | "crypto/sha1" 13 | "encoding/hex" 14 | "encoding/json" 15 | "flag" 16 | "fmt" 17 | "io/ioutil" 18 | "net/http" 19 | "os" 20 | "os/signal" 21 | "regexp" 22 | "strings" 23 | "syscall" 24 | "time" 25 | 26 | "github.com/mmcdole/gofeed" 27 | "github.com/robfig/cron" 28 | ) 29 | 30 | // RSSEntry describes a single RSS feed and the corresponding hook 31 | // to POST to. 32 | type RSSEntry struct { 33 | // The URL of the RSS/Atom feed 34 | feed string 35 | 36 | // The end-point to make the webhook request to. 37 | hook string 38 | } 39 | 40 | // Loaded contains the loaded feeds + hooks, as read from the specified 41 | // configuration file 42 | var Loaded []RSSEntry 43 | 44 | // Timeout is the (global) timeout we use when loading remote RSS 45 | // feeds. 46 | var Timeout time.Duration 47 | 48 | // loadConfig loads the named configuration file and populates our 49 | // `Loaded` list of RSS-feeds & Webhook addresses 50 | func loadConfig(filename string) { 51 | file, err := os.Open(filename) 52 | if err != nil { 53 | fmt.Printf("Error opening %s - %s\n", filename, err.Error()) 54 | return 55 | } 56 | defer file.Close() 57 | 58 | // 59 | // Process it line by line. 60 | // 61 | scanner := bufio.NewScanner(file) 62 | for scanner.Scan() { 63 | 64 | // Get the next line, and strip leading/trailing space 65 | tmp := scanner.Text() 66 | tmp = strings.TrimSpace(tmp) 67 | 68 | // 69 | // Skip lines that begin with a comment. 70 | // 71 | if (tmp != "") && (!strings.HasPrefix(tmp, "#")) { 72 | 73 | // 74 | // Otherwise find the feed + post-point 75 | // 76 | parser := regexp.MustCompile("^(.+?)=([^=].+)") 77 | match := parser.FindStringSubmatch(tmp) 78 | 79 | // 80 | // OK we found a suitable entry. 81 | // 82 | if len(match) == 3 { 83 | 84 | feed := strings.TrimSpace(match[1]) 85 | hook := strings.TrimSpace(match[2]) 86 | 87 | // Append the new entry to our list 88 | entry := RSSEntry{feed: feed, hook: hook} 89 | Loaded = append(Loaded, entry) 90 | } 91 | 92 | } 93 | } 94 | 95 | } 96 | 97 | // fetchFeed fetches the contents of the specified URL. 98 | func fetchFeed(url string) (string, error) { 99 | 100 | // Ensure we setup a timeout for our fetch 101 | client := &http.Client{Timeout: Timeout} 102 | 103 | // We'll only make a GET request 104 | req, err := http.NewRequest("GET", url, nil) 105 | if err != nil { 106 | return "", err 107 | } 108 | 109 | // We ensure we identify ourself. 110 | req.Header.Set("User-Agent", "rss2email (https://github.com/skx/rss2email)") 111 | 112 | // Make the request 113 | resp, err := client.Do(req) 114 | if err != nil { 115 | return "", err 116 | } 117 | defer resp.Body.Close() 118 | 119 | // Read the body returned 120 | output, err := ioutil.ReadAll(resp.Body) 121 | if err != nil { 122 | return "", err 123 | } 124 | return string(output), nil 125 | } 126 | 127 | // isNew returns TRUE if this feed-item hasn't been notified about 128 | // previously. 129 | func isNew(parent string, item *gofeed.Item) bool { 130 | 131 | hasher := sha1.New() 132 | hasher.Write([]byte(parent)) 133 | hasher.Write([]byte(item.GUID)) 134 | hashBytes := hasher.Sum(nil) 135 | 136 | // Hexadecimal conversion 137 | hexSha1 := hex.EncodeToString(hashBytes) 138 | 139 | if _, err := os.Stat(os.Getenv("HOME") + "/.rss2hook/seen/" + hexSha1); os.IsNotExist(err) { 140 | return true 141 | } 142 | return false 143 | } 144 | 145 | // recordSeen ensures that we won't re-announce a given feed-item. 146 | func recordSeen(parent string, item *gofeed.Item) { 147 | 148 | hasher := sha1.New() 149 | hasher.Write([]byte(parent)) 150 | hasher.Write([]byte(item.GUID)) 151 | hashBytes := hasher.Sum(nil) 152 | 153 | // Hexadecimal conversion 154 | hexSha1 := hex.EncodeToString(hashBytes) 155 | 156 | dir := os.Getenv("HOME") + "/.rss2hook/seen" 157 | os.MkdirAll(dir, os.ModePerm) 158 | 159 | _ = ioutil.WriteFile(dir+"/"+hexSha1, []byte(item.Link), 0644) 160 | 161 | } 162 | 163 | // checkFeeds is our work-horse. 164 | // 165 | // For each available feed it looks for new entries, and when founds 166 | // triggers `notify` upon the resulting entry 167 | func checkFeeds() { 168 | 169 | // 170 | // For each thing we're monitoring 171 | // 172 | for _, monitor := range Loaded { 173 | 174 | // Fetch the feed-contents 175 | content, err := fetchFeed(monitor.feed) 176 | 177 | if err != nil { 178 | fmt.Printf("Error fetching %s - %s\n", 179 | monitor.feed, err.Error()) 180 | continue 181 | } 182 | 183 | // Now parse the feed contents into a set of items 184 | fp := gofeed.NewParser() 185 | feed, err := fp.ParseString(content) 186 | if err != nil { 187 | fmt.Printf("Error parsing %s contents: %s\n", monitor.feed, err.Error()) 188 | continue 189 | } 190 | 191 | // For each entry in the feed 192 | for _, i := range feed.Items { 193 | 194 | // If we've not already notified about this one. 195 | if isNew(monitor.feed, i) { 196 | 197 | // Trigger the notification 198 | err := notify(monitor.hook, i) 199 | 200 | // and if that notification succeeded 201 | // then record this item as having been 202 | // processed successfully. 203 | if err == nil { 204 | recordSeen(monitor.feed, i) 205 | } 206 | } 207 | } 208 | } 209 | } 210 | 211 | // notify actually submits the specified item to the remote webhook. 212 | // 213 | // The RSS-item is submitted as a JSON-object. 214 | func notify(hook string, item *gofeed.Item) error { 215 | 216 | // We'll post the item as a JSON object. 217 | // So first of all encode it. 218 | jsonValue, err := json.Marshal(item) 219 | if err != nil { 220 | fmt.Printf("notify: Failed to encode JSON:%s\n", err.Error()) 221 | return err 222 | } 223 | 224 | // 225 | // Post to the specified hook URL. 226 | // 227 | res, err := http.Post(hook, 228 | "application/json", 229 | bytes.NewBuffer(jsonValue)) 230 | 231 | if err != nil { 232 | fmt.Printf("notify: Failed to POST to %s - %s\n", 233 | hook, err.Error()) 234 | return err 235 | } 236 | 237 | // 238 | // OK now we've submitted the post. 239 | // 240 | // We should retrieve the status-code + body, if the status-code 241 | // is "odd" then we'll show them. 242 | // 243 | defer res.Body.Close() 244 | _, err = ioutil.ReadAll(res.Body) 245 | if err != nil { 246 | return err 247 | } 248 | status := res.StatusCode 249 | 250 | if status != 200 { 251 | fmt.Printf("notify: Warning - Status code was not 200: %d\n", status) 252 | } 253 | return nil 254 | } 255 | 256 | // main is our entry-point 257 | func main() { 258 | 259 | // Parse the command-line flags 260 | config := flag.String("config", "", "The path to the configuration-file to read") 261 | timeout := flag.Duration("timeout", 5*time.Second, "The timeout used for fetching the remote feeds") 262 | flag.Parse() 263 | 264 | // Setup the default timeout. 265 | Timeout = *timeout 266 | 267 | if *config == "" { 268 | fmt.Printf("Please specify a configuration-file to read\n") 269 | return 270 | } 271 | 272 | // 273 | // Load the configuration file 274 | // 275 | loadConfig(*config) 276 | 277 | // 278 | // Show the things we're monitoring 279 | // 280 | for _, ent := range Loaded { 281 | fmt.Printf("Monitoring feed %s\nPosting to %s\n\n", 282 | ent.feed, ent.hook) 283 | } 284 | 285 | // 286 | // Make the initial scan of feeds immediately to avoid waiting too 287 | // long for the first time. 288 | // 289 | checkFeeds() 290 | 291 | // 292 | // Now repeat that every five minutes. 293 | // 294 | c := cron.New() 295 | c.AddFunc("@every 5m", func() { checkFeeds() }) 296 | c.Start() 297 | 298 | // 299 | // Now we can loop waiting to be terminated via ctrl-c, etc. 300 | // 301 | sigs := make(chan os.Signal, 1) 302 | done := make(chan bool, 1) 303 | signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) 304 | go func() { 305 | <-sigs 306 | done <- true 307 | }() 308 | <-done 309 | } 310 | -------------------------------------------------------------------------------- /sample.cfg: -------------------------------------------------------------------------------- 1 | # 2 | # This is the sample configuration file for rss2hook. 3 | # 4 | # rss2hook is designed to make a HTTP-POST to a webhook 5 | # when a new RSS item appears in a feed. 6 | # 7 | # There are two things to specify: 8 | # 9 | # * The URL of the RSS feed to monitor. 10 | # 11 | # * The corresponding end-point to make the POST request to. 12 | # 13 | # In this configuration-file they're specified as pairs like so: 14 | # 15 | # RSS = HOOK 16 | # 17 | 18 | 19 | # 20 | # The following example reads from my blog, and posts to the sample 21 | # webhook-handler as included in the repository: 22 | # 23 | https://blog.steve.fi/index.rss = http://localhost:8080/ 24 | 25 | # 26 | # We have a second feed here, containing news stories from the BBC 27 | # 28 | http://feeds.bbci.co.uk/news/rss.xml = http://localhost:8080/ 29 | -------------------------------------------------------------------------------- /webhook/webhook.go: -------------------------------------------------------------------------------- 1 | // webhook.go is a simple example program that will listen upon 2 | // localhost:8080 and dump the contents of any HTTP POST received 3 | // to the console. 4 | // 5 | 6 | package main 7 | 8 | import ( 9 | "fmt" 10 | "io" 11 | "io/ioutil" 12 | "log" 13 | "net/http" 14 | ) 15 | 16 | // HandleHook is called on any access to the server-root. 17 | // 18 | // If a POST request is received dump it to the console. Regardless 19 | // of the requested method we then send an "OK" response to the caller. 20 | func HandleHook(w http.ResponseWriter, r *http.Request) { 21 | 22 | if r.Method == "POST" { 23 | content, _ := ioutil.ReadAll(r.Body) 24 | fmt.Printf("%s\n", content) 25 | } 26 | // Always return a response to the caller. 27 | io.WriteString(w, "OK\n") 28 | } 29 | 30 | func main() { 31 | 32 | // Bind our handler 33 | http.HandleFunc("/", HandleHook) 34 | 35 | // Launch the server 36 | log.Fatal(http.ListenAndServe(":8080", nil)) 37 | } 38 | --------------------------------------------------------------------------------