# Consigli su come creare un plugin di scraping e pubblicazione

**URL:** https://meta.discourse.org/t/advice-on-how-to-build-a-scraping-posting-plugin/92901
**Category:** Development
**Created:** [22 Luglio 2018, 11:15pm UTC](https://meta.discourse.org/t/advice-on-how-to-build-a-scraping-posting-plugin/92901 "2018-07-22T23:15:50Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![bletch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bletch/32/69088_2.png) [@bletch](https://meta.discourse.org/u/bletch)
#### Post date: [22 Luglio 2018, 11:15pm UTC](https://meta.discourse.org/t/advice-on-how-to-build-a-scraping-posting-plugin/92901/1 "2018-07-22T23:15:50Z")

</div>

I’m looking to build a plugin that periodically searches the web / Twitter / Facebook / Instagram / etc for relevant news and then creates summary posts in Discourse.

Can anyone point me at a plugin or a part of core that I could look at to get some ideas of how to approach this project?

### More details…

Our forum is focussed on a UK football team and these news items would relate to the team and players.

The news might be used to start discussion threads or more often simply collected as a news-aggregator and placed into searchable news repository category.

During matches the frequency of the posts may increase dramatically.

I’m at the planning stage at the moment, but right now, outside of some system settings, I don’t believe I will need any front-end UI. So this will all be back-end Ruby.

What I really need to understand is how I can kickoff (cron-like) server jobs - probably with sidekiq.

I’ve written an MVCForum → Discourse migrator so I’m relatively comfortable moving the gathered news items into posts.

I’ve also written the scraper / Twitter gatherer before for our previous forum (in Python that time), and I used nokogiri as part of the migration so I think I’ll be OK writing the scraper.

I’m guessing that Discourse uses an existing Twitter Gem that I can piggy-back on. If not can you recommend one?

I’ve read the plugins tutorial but outside of the basic structure it didn’t really help as it (understandably) had more focus on front-end UI.

My goal is to parameterise the scraping / CSS selectors as much as possible so that the plugin might have use for the wider community. Same for the Twitter accounts / #hashtags that I want to monitor and create posts from.

Any other advice, tips or pointers gratefully received.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [23 Luglio 2018, 1:59am UTC](https://meta.discourse.org/t/advice-on-how-to-build-a-scraping-posting-plugin/92901/2 "2018-07-23T01:59:14Z")

</div>

Have you considered not writing a plugin here?

You could just run a program in whatever language you like on a regular schedule that used the Discourse API to create the posts.

---

<div class="post-metadata">

### Author: ![bletch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bletch/32/69088_2.png) [@bletch](https://meta.discourse.org/u/bletch)
#### Post date: [23 Luglio 2018, 8:56am UTC](https://meta.discourse.org/t/advice-on-how-to-build-a-scraping-posting-plugin/92901/3 "2018-07-23T08:56:59Z")

</div>

Absolutely.

I effectively have the core already in Python. I initially tried to migrate via the API so I’m familiar with that too, but I want to write some Discourse plugins over time and saw this as a gentle introductory project to learn about plugin development.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [23 Luglio 2018, 10:12am UTC](https://meta.discourse.org/t/advice-on-how-to-build-a-scraping-posting-plugin/92901/4 "2018-07-23T10:12:14Z")

</div>

Discourse has a feature that allows you to poll RSS feeds and create topics for them. I guess that’s similar to what you want to do. At least it’s a good starting point.

[https://github.com/discourse/discourse/blob/master/app/jobs/scheduled/poll\_feed.rb](https://github.com/discourse/discourse/blob/master/app/jobs/scheduled/poll_feed.rb)

---

<div class="post-metadata">

### Author: ![bletch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bletch/32/69088_2.png) [@bletch](https://meta.discourse.org/u/bletch)
#### Post date: [23 Luglio 2018, 10:19am UTC](https://meta.discourse.org/t/advice-on-how-to-build-a-scraping-posting-plugin/92901/5 "2018-07-23T10:19:26Z")

</div>

Excellent.

That’s exactly the sort of pointer I was looking for.

Thanks!

---

<div class="post-metadata">

### Author: ![bletch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bletch/32/69088_2.png) [@bletch](https://meta.discourse.org/u/bletch)
#### Post date: [24 Luglio 2018, 12:09pm UTC](https://meta.discourse.org/t/advice-on-how-to-build-a-scraping-posting-plugin/92901/6 "2018-07-24T12:09:53Z")

</div>

Are the settings mentioned in the code not generally exposed - as I can’t find them in the UI?

Do I need to enable a flag that will then make the settings visible, or am I heading to the Rails console?

Sorry if I’m being thick.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [24 Luglio 2018, 12:12pm UTC](https://meta.discourse.org/t/advice-on-how-to-build-a-scraping-posting-plugin/92901/7 "2018-07-24T12:12:27Z")

</div>

Go to Customize → Embedding in the admin interface and click on the “Add Host” button.

---

<div class="post-metadata">

### Author: ![bletch](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/bletch/32/69088_2.png) [@bletch](https://meta.discourse.org/u/bletch)
#### Post date: [24 Luglio 2018, 12:52pm UTC](https://meta.discourse.org/t/advice-on-how-to-build-a-scraping-posting-plugin/92901/8 "2018-07-24T12:52:56Z")

</div>

Gotcha!

I found that, searched on here and found that it was to do with embedding Discourse in an `<iframe></iframe>`.

I didn’t go through the creation process and now I see there are more settings.

Thanks again.
