php-mastodon-rss-to-bot-stateless

授权协议 MIT License
开发语言 Python
所属分类 应用工具、 IM/聊天/语音工具
软件类型 开源软件
地区 不详
投 递 者 富钧
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

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
  • 使用的是php 7.0.21 环境  在将swoole_websocket_server 面向过程 写为类 启动 出现报错 PHP Fatal error:  swoole_http_server::start(): require onMessage callback in /home/wwwroot/default/demo/server/ws.php on line 17<?php clas

  •   <?php $rss=simplexml_load_file('http://meego123.net/rss.php');?> <?php foreach($rss->channel->item as $item){?> <h1><a href="<?php echo $item->link ?>"><?php echo $item->title; ?></a></h1> <?php ech

  • RSS 聚合最近非常流行,因此至少对 RSS 及其工作方式有所了解是一名 PHP 开发人员的迫切需要。本文介绍了 RSS 基础知识、RSS 众多用途中的一些用途、如何使用 PHP 从数据库创建 RSS 提要,以及如何使用 XML_RSS 模块读取现有 RSS 提要并将其转换为 HTML。 什么?您没听说过 RSS? RSS 聚合是最常见的 TLA(三字母缩写词)之一。RSS 作为缩写词具有多种含义

  • 一般在页面直接输出图片的时候需要 用header("Content-type: image/jpeg");或者是设置session 的时候容易出现这个问题,一般是之前有别的输出或者header的设置操作。 如果有别的输出或者header设置操作,在自己的header之前用ob_clean()执行一下就行。 如果是输出图片的话,如果加了ob_clean不起作用,检查一下 php.in i的outpu

  • <?php //get the q parameter from URL $q=$_GET["q"]; //find out which feed was selected if($q=="Google") { $xml=("http://news.google.com/news?ned=us&topic=h&output=rss"); } elseif($q=="MSNBC")

  • 第一种传统的是直接用php输出语句,按照rss结构规范,新建一个rss文件 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <?php connect_sql(); $arr = getall(); $files_url = "mytest/test.xml"; /*$xml_head = "<?xml ver

  • 不能识别变量名.两种方法 1.把if($_ POST ['submit'])改成 if (isset($_ POST ['submit'])) 因为刚开始没有获取submit的值.isset是判断submit是否存在 2: 在开头加上 error_reporting(E_ALL & ~E_NOTICE); 表示提示除去 E_NOTICE 之外的所有错误信息 刚刚在编程中遇到类似问题,用的第二种方法

  • <?php class RSS {     /**      +----------------------------------------------------------      * RSS频道名      +----------------------------------------------------------      */     protected $channel

  • <?php /* 程序:get_xml_array.php 作用:将xml数据生成数组,数组格式:标签名=>值。 时间:2009-3-20 */ //定义一个将xml标签对应值对象 class AminoAcid {      function AminoAcid ($aa)    {        foreach ($aa as $k=>$v){            $this->$k = $

  •  如果在执行php程序时看到这条警告:"Warning: Cannot modify header information - headers already sent by ...." Few notes based on the following user posts: 有以下几种解决方法:     第一种: 1. Blank lines (空白行): Make sure no blank

  • 复制代码 代码如下: $xmlfile = 'news/'.date('YmdH').'.xml'; $sourcexml = 'http://www.chinanews.com.cn/rss/scroll-news.xml'; if( !file_exists($xmlfile) ) { $str = @file($sourcexml) or die('加载文件时出错。'); $fp = fop

  • http://stackoverflow.com/questions/3346628/retrieving-rss-feed-with-tag-contentencoded In <content:encoded>, content is the namespace and encoded is the tag name. var_dump($entry->children("content",

  • <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> <?php // The file test.xml contains an XML document with a root element   // and at least an element /[root]/title.   $xmlfile = dat

  • PHP解析RSS的方法 本文实例讲述了PHP解析RSS的方法。分享给大家供大家参考。具体如下: 1. php代码如下: require "XML/RSS.php"; $rss = new XML_RSS("http://php.net/news.rss"); $rss->parse(); foreach($rss->getItems() as $item) { print_r($item); }

  • 网上关于PHP BOT程序的实例还是很少的,前段时间也是业务需求,开始接触此类程序,很有意思。所谓BOT实际上是模拟GET或POST,去action一些程序,实现一些自动化处理,当然这个东西是双刃剑,可别使坏就好。 PHP实现BOT有多种方式,个人比较喜欢HttpRequest,一来比较OO,而来编写简单方便。以下是class对应的function,还有一些examples。 function可以

  • How to Submit Your RSS Feed to iTunes If you have a podcast, you know you also need one very important thing: listeners. And most likely, lots of ‘em! The more listeners you have, the further your mes

 相关资料
  • Mastodon Bot Bots Hagh Hagh reblogs certain toots to itself creating a Hagh page. Users from local instance are able to make a toot hagh. Setup Have go and GNUMake installed. Copy the env var sample a

  • Mastodon Image Bot makes use of Mastodon.py, tweepy, pixivpy and pybooru $ python bot.py -husage: bot.py [-h] [-c FILE] [-a] [-p] [-v]simple scheduled image bot for your mastodon instanceoptional argu

  • Mas2tter - the Mastodon-to-Twitter Mirrorbot This Python3 script loads the latest Toots from your Mastodon account and posts them on Twitter.Some formatting is done to keep the content of Tweets in 28

  • Mastodon 是开源且免费的社交网络服务器,任何人都可以基于它创建类似推特/微博的产品(可以理解为搭建“私服微博/推特”)。但 Mastodon 与常见的社交网络不一样,其定位是去中心化的社交平台——可作为商业平台的替代方案,避免了单个公司垄断你沟通的风险。 基于 Mastodon 搭建的站点被称为“实例 (instance)”,这些“实例”既相互独立,又彼此关联(因为不同站点的用户可以毫无阻

  • PHP-to-OrgChart 能将 php 多维 array 生成组织结构图。 示例: $data=array(     'a'=>array(         'aa'=>array(             'aaa'=>'Mike',             'aab'=>'Look',             'aac'=>'Rum',         ),         'bb'=>

  • Mastodon Material Language | 言語 日本語 (Japanese) Overview Mastodon Material is the native theme for Mastodon, which based on Material Design. Development policy is here (Japanese). Screenshots show/hide