File tree 3 files changed +58
-1
lines changed
3 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,12 @@ inputs:
12
12
trigger :
13
13
schedule : ' */5 9-16 * * *'
14
14
now : true
15
+ - class : Rss
16
+ enabled : false
17
+ uri : https://www.archlinux.org/feeds/news/
18
+ trigger :
19
+ schedule : ' */10 * * * *'
20
+ now : false
15
21
- class : RocketChat
16
22
enabled : false
17
23
channel : ' #xify-in'
Original file line number Diff line number Diff line change
1
+ require 'rss'
2
+ require 'open-uri'
3
+
4
+ module Input
5
+ class Rss
6
+ def initialize ( config )
7
+ @config = config
8
+
9
+ @uri = URI . parse config [ 'uri' ]
10
+
11
+ working_dir = "#{ ENV [ 'HOME' ] } /.xify/Rss"
12
+ Dir . mkdir working_dir rescue Errno ::EEXIST
13
+ @latest_file = "#{ working_dir } /#{ @uri . to_s . gsub ( /\W +/ , '_' ) } "
14
+ end
15
+
16
+ def updates
17
+ opts = { }
18
+ opts [ :first ] = :now if @config [ 'trigger' ] [ 'now' ]
19
+ Rufus ::Scheduler . singleton . repeat @config [ 'trigger' ] [ 'schedule' ] , opts do
20
+ open ( @uri ) do |rss |
21
+ latest = Time . parse File . read ( @latest_file ) rescue Time . now - 24 *60 *60
22
+ feed = RSS ::Parser . parse ( rss )
23
+ feed . items
24
+ . select do |item |
25
+ item . pubDate > latest
26
+ end
27
+ . sort_by do |item |
28
+ item . pubDate
29
+ end
30
+ . each do |item |
31
+ yield Xify ::Event . new (
32
+ item . dc_creator ,
33
+ "*#{ item . title } *\n \n #{ item . description } " ,
34
+ link : item . link ,
35
+ parent : feed . channel . title ,
36
+ parent_link : feed . channel . link ,
37
+ time : item . pubDate
38
+ )
39
+ update_latest item
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def update_latest ( latest )
48
+ File . write @latest_file , latest . pubDate . to_s
49
+ end
50
+ end
51
+ end
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ require 'date'
2
2
3
3
Gem ::Specification . new do |s |
4
4
s . name = 'xify'
5
- s . version = '0.4.2 '
5
+ s . version = '0.5.0 '
6
6
s . date = Date . today . to_s
7
7
s . summary = 'Cross-post content from one service to another.'
8
8
s . description = 'Cross-post content from one service to another.'
You can’t perform that action at this time.
0 commit comments