• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

dmcblue/php-mastodon-rss-to-bot-stateless

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

dmcblue/php-mastodon-rss-to-bot-stateless

开源软件地址(OpenSource Url):

https://github.com/dmcblue/php-mastodon-rss-to-bot-stateless

开源编程语言(OpenSource Language):

PHP 100.0%

开源软件介绍(OpenSource Introduction):

PHP Feed-to-Bot Tool for Mastodon

A tool for creating bots for Mastodon which read RSS/Atom feeds.

Features:

  • Multiple bots from one script
  • Multiple feeds per bot
  • Supports (valid) RSS and Atom
  • Stateless: in the sense that it does not maintain a cache of which RSS posts have been converted to toots.

Currently running the RFI Bot on mastodon.social

Setup

Requires PHP 7.0

You will need a cert file to run Guzzle.

You will also need to set the timezone of your computer via the php.ini date.timezone setting.

Load Dependencies

Dependencies are loaded via Composer

composer install

It uses the following dependencies:

Application

This code takes care of running the 3rd party application which handles the bots.

You will need to copy /configurations/APP.example.json to /configurations/APP.json.

In /configurations/APP.json change the name property to a custom name.

Bot Configuration

You will first need to manually make the account on the Mastodon instance of your choice with an email, password and username.

The file /configurations/example.json is an example of a bot configuration. Create a new JSON in the /configurations/ folder and name it for your bot.

{
	"instance" : "social.targaryen.house", //like 'mastodon.social'

	"username" : "my_username",            //username for your bot's account, not display name
                                             //not used at this point

	"email" : "myemail+botname@mail.com",  //email for your bot's login

	"password" : "realpassword",           //password for your bot's login

	"hashtags" : ["all"],                  //array of strings that you want as 
                                             //hashtags (#) in each toot
                                             //do not add '#'

	"feeds" : [{                           //array of feeds for this bot

		"type" : "rss",                    //type of feed, rss or atom

		"url" : "http://www.website.com/rss/one.xml",
                                           //url to feed

		"hashtags" : ["cats"]              //hashtags for every toot from this feed
	},{
		"type" : "rss",
		"url" : "http://www.website.com/rss/two.xml",
		"hashtags" : ["music"]
	},{
		"type" : "atom",
		"url" : "http://www.website.com/atom/three.xml",
		"hashtags" : ["mood"]
	}]
}

Create a separate configuration file for each bot you wish to run.

Use

Updates

If your configuration file is called my_rss.json, then the RSS items can be posted/updated with:

php /path/to/php-mastodon-rss-to-bot-stateless/index.php my_rss

Please note the lack of '.json' in the parameter.

To keep the application 'stateless' (see top), the tool works based off of timestamps. The tool will check the timestamp of the latest toot and get all Feed items after that timestamp and posts them.

Obviously, this has the potential to not be as accurate as a bot with a cache, but I'm too lazy to build one. If your feed has items added every minute (hopefully unlikely), then this tool may miss an item or two along the way.

If the bot is new and has no posts, it will only post the most recent feed item, not the entire feed.

Scheduling

In order to have a bot that updates regularly, you will need to schedule the above PHP call with a Cron task or a Scheduled Task depending on your system.

You will need to schedule separate tasks for each bot/config.

Additional

If you need to disable the tool for a while (system maintenance, etc), but you don't want the bot to flood Mastodon with a bunch of belated posts when it starts up again, you can just make a post directly to the bot via the Mastodon interface and then start the scheduled task again. The new post will make sure the most recent timestamp in the Toot timeline is up to date.

TODO

  • Create config class to validate configurations
  • Add utility class and PHPUnit for long term stability
  • Get toot length by instance
  • Replace strlen with more reliable function
  • Extend to any iterable, fetchable, timestamped resource



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap