-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss.rb
199 lines (187 loc) · 4.1 KB
/
rss.rb
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
if RUBY_ENGINE == 'ruby'
require 'pry-byebug'
end
require 'graphql/client'
require 'graphql/client/http'
require 'rss'
BASE_URL = 'https://republik.ch'
http_client = GraphQL::Client::HTTP.new('https://api.republik.ch/graphql') do
def headers(context)
# Optionally set any HTTP headers
{
'Cookie': ENV['cookie']
}
end
end
schema = GraphQL::Client.load_schema('schema.json')
graphql_client = GraphQL::Client.new(schema: schema, execute: http_client)
GET_SEARCH_RESULTS_QUERY = graphql_client.parse <<-'GRAPHQL'
query($search: String, $after: String, $sort: SearchSortInput, $filters: [SearchGenericFilterInput!], $trackingId: ID) {
search(first: 100, after: $after, search: $search, sort: $sort, filters: $filters, trackingId: $trackingId) {
totalCount
trackingId
nodes {
entity {
__typename
... on Document {
...DocumentListDocument
__typename
}
... on Comment {
id
content
text
preview(length: 240) {
string
more
__typename
}
createdAt
displayAuthor {
id
name
username
profilePicture
credential {
description
verified
__typename
}
__typename
}
published
updatedAt
tags
parentIds
discussion {
id
title
path
document {
id
meta {
title
path
template
ownDiscussion {
id
closed
__typename
}
__typename
}
__typename
}
__typename
}
__typename
}
... on User {
id
username
firstName
lastName
credentials {
verified
description
isListed
__typename
}
portrait
hasPublicProfile
__typename
}
}
highlights {
path
fragments
__typename
}
score
__typename
}
__typename
}
}
fragment DocumentListDocument on Document {
id
meta {
credits
title
description
publishDate
prepublication
path
kind
template
color
estimatedReadingMinutes
estimatedConsumptionMinutes
indicateChart
indicateGallery
indicateVideo
audioSource {
mp3
__typename
}
dossier {
id
__typename
}
format {
meta {
path
title
color
kind
__typename
}
__typename
}
ownDiscussion {
id
closed
comments {
totalCount
__typename
}
__typename
}
linkedDiscussion {
id
path
closed
comments {
totalCount
__typename
}
__typename
}
__typename
}
__typename
}
GRAPHQL
result = graphql_client.query(GET_SEARCH_RESULTS_QUERY, variables: {search: '', sort: {key: 'publishedAt'}, filters: [{key: 'audioSource', value: 'true'}]})
feed = RSS::Maker.make('2.0') do |maker|
maker.channel.author = 'https://republik.ch'
maker.channel.updated = Time.now.to_s
maker.channel.about = 'feed.rss'
maker.channel.title = 'Republik: Vorgelesene Artikel'
maker.channel.link = 'https://republik.ch'
maker.channel.description = 'Republik: Vorgelesene Artikel'
result.data.search.nodes.each do |node|
maker.items.new_item do |item|
url = "#{BASE_URL}#{node.entity.meta.path}"
item.id = Base64.decode64(node.entity.id)
item.link = url
item.title = node.entity.meta.title
item.updated = node.entity.meta.publish_date
item.enclosure.type = 'audio/mpeg'
item.enclosure.url = node.entity.meta.audio_source.mp3
item.enclosure.length = 1
item.description = node.entity.meta.description
end
end
end
puts feed.to_s