-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmodel.xml
More file actions
89 lines (81 loc) · 2.74 KB
/
model.xml
File metadata and controls
89 lines (81 loc) · 2.74 KB
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
<project name="lua_connector" pubsub="auto" threads="4" heartbeat-interval="1" index="pi_EMPTY" luaroot="@ESP_PROJECT_OUTPUT@/luaroot">
<description><![CDATA[This project contains a Source window with a Lua connector that reads RSS feeds from scientific sites and publishes them into the project.]]></description>
<metadata>
<meta id="layout">{"cq":{"Counter":{"x":50,"y":175},"Source":{"x":50,"y":50}}}</meta>
<meta id="studioTags">Example</meta>
<meta id="studioUploadedBy">anonymous</meta>
<meta id="studioUploaded">1764341003833</meta>
<meta id="studioModifiedBy">anonymous</meta>
<meta id="studioModified">1764341045942</meta>
</metadata>
<contqueries>
<contquery name="cq">
<windows>
<window-source name="Source">
<schema>
<fields>
<field name="id" type="string" key="true"/>
<field name="source" type="string"/>
<field name="title" type="string"/>
<field name="date" type="string"/>
<field name="description" type="string"/>
<field name="link" type="string"/>
</fields>
</schema>
<connectors>
<connector class="lua" name="pub">
<properties>
<property name="type"><![CDATA[pub]]></property>
<property name="interval"><![CDATA[5 seconds]]></property>
<property name="code"><![CDATA[local feeds = {
"https://feeds.bbci.co.uk/news/science_and_environment/rss.xml",
"https://beta.nsf.gov/rss/rss_www_news.xml",
"https://www.newscientist.com/section/news/feed/"
}
function publish()
for i,feed in ipairs(feeds)
do
events = getFeed(feed)
if esp_inject(events) == false
then
return true
end
end
return false
end
function getFeed(feed)
local request = {}
request.url = feed
request.tolua = true
local data = esp_sendHttp(request)
local events = {}
local index = 1
for i,entry in ipairs(data.response.rss.item_array)
do
local event = {}
event.id = entry.item.guid["*value"]
event.source = feed
event.title = entry.item.title
event.date = entry.item.pubDate
event.description = entry.item.description
event.link = entry.item.link
event._opcode = "upsert"
events[index] = event
index = index + 1
end
return events
end]]></property>
</properties>
</connector>
</connectors>
</window-source>
<window-counter name="Counter">
<description><![CDATA[Check throughput]]></description>
</window-counter>
</windows>
<edges>
<edge source="Source" target="Counter"/>
</edges>
</contquery>
</contqueries>
</project>