2023-11-13 14:45:10 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
FIXME
|
|
|
|
|
|
|
|
1) Check feed duplication on runtime.
|
|
|
|
When feed is valid and is not yet in the database it is
|
|
|
|
posible to send a batch which would result in duplication.
|
|
|
|
Consequently, it might result in database lock error upon
|
|
|
|
feed removal attempt
|
|
|
|
|
2024-02-10 18:53:53 +01:00
|
|
|
2) Communicate to messages of new contacts (not subscribed and not in roster)
|
2023-11-13 14:45:10 +01:00
|
|
|
|
2024-02-10 18:53:53 +01:00
|
|
|
TODO
|
2023-12-04 15:41:02 +01:00
|
|
|
|
2023-12-28 15:50:23 +01:00
|
|
|
2) Machine Learning for scrapping Title, Link, Summary and Timstamp;
|
2023-12-24 19:37:05 +01:00
|
|
|
Scrape element </article> (example: Liferea)
|
|
|
|
http://intertwingly.net/blog/
|
|
|
|
https://www.brandenburg.de/
|
2023-11-13 14:45:10 +01:00
|
|
|
|
2023-12-28 15:50:23 +01:00
|
|
|
3) Set MUC subject
|
2023-12-04 15:41:02 +01:00
|
|
|
Feeds which entries are to be set as groupchat subject.
|
|
|
|
Perhaps not, as it would require to check every feed for this setting.
|
2023-12-24 19:37:05 +01:00
|
|
|
Maybe a separate bot;
|
2023-11-13 14:45:10 +01:00
|
|
|
|
2024-02-10 18:53:53 +01:00
|
|
|
5) OMEMO;
|
2023-11-13 14:45:10 +01:00
|
|
|
|
2024-02-10 18:53:53 +01:00
|
|
|
6) Logging;
|
2023-12-24 19:37:05 +01:00
|
|
|
https://docs.python.org/3/howto/logging.html
|
2023-11-13 14:45:10 +01:00
|
|
|
|
2024-01-06 23:03:08 +01:00
|
|
|
9.1) IDEA: Bot to display Title and Excerpt
|
|
|
|
(including sending a PDF version of it) of posted link
|
|
|
|
|
2024-01-09 16:53:19 +01:00
|
|
|
10) Fetch summary from URL, instead of storing summary, or
|
2023-12-04 15:41:02 +01:00
|
|
|
Store 5 upcoming summaries.
|
|
|
|
This would help making the database files smaller.
|
2023-11-15 15:02:39 +01:00
|
|
|
|
2024-01-09 16:53:19 +01:00
|
|
|
13) Tip Of The Day.
|
2023-11-22 12:47:34 +01:00
|
|
|
Did you know that you can follow you favorite Mastodon feeds by just
|
|
|
|
sending the URL address?
|
|
|
|
Supported fediverse websites are:
|
2024-01-02 12:42:41 +01:00
|
|
|
Akkoma, Firefish (Calckey), Friendica, HubZilla,
|
|
|
|
Mastodon, Misskey, Pixelfed, Pleroma, Socialhome, Soapbox.
|
2023-11-22 12:47:34 +01:00
|
|
|
|
2024-01-09 16:53:19 +01:00
|
|
|
14) Brand: News Broker, Newsman, Newsdealer, Laura Harbinger
|
2023-12-24 19:37:05 +01:00
|
|
|
|
2024-01-09 16:53:19 +01:00
|
|
|
16) Search messages of government regulated publishers, and promote other sources.
|
2023-12-24 19:37:05 +01:00
|
|
|
Dear reader, we couldn't get news from XYZ as they don't provide RSS feeds.
|
|
|
|
However, you might want to get news from (1) (2) and (3) instead!
|
2023-12-11 10:04:45 +01:00
|
|
|
|
2024-02-10 18:53:53 +01:00
|
|
|
17) The operator account will be given reports from the bot about its
|
2024-01-14 19:05:12 +01:00
|
|
|
activities every X minutes.
|
|
|
|
When a suspicious activity is detected, it will be reported immediately.
|
|
|
|
|
2023-11-13 14:45:10 +01:00
|
|
|
"""
|
2023-07-16 17:23:10 +02:00
|
|
|
|
|
|
|
# vars and their meanings:
|
|
|
|
# jid = Jabber ID (XMPP)
|
|
|
|
# res = response (HTTP)
|
|
|
|
|
|
|
|
from argparse import ArgumentParser
|
2024-01-18 21:57:49 +01:00
|
|
|
from getpass import getpass
|
|
|
|
import sys
|
2023-12-11 10:04:45 +01:00
|
|
|
import configparser
|
2023-12-28 15:50:23 +01:00
|
|
|
# import filehandler
|
|
|
|
# from slixfeed.file import get_default_confdir
|
2023-07-16 17:23:10 +02:00
|
|
|
from getpass import getpass
|
|
|
|
import logging
|
2023-12-11 10:04:45 +01:00
|
|
|
import os
|
2023-07-16 17:23:10 +02:00
|
|
|
|
2023-12-04 15:41:02 +01:00
|
|
|
# from datetime import date
|
|
|
|
# import time
|
2023-07-16 17:23:10 +02:00
|
|
|
|
2023-09-29 13:49:24 +02:00
|
|
|
# from eliot import start_action, to_file
|
2024-02-04 19:19:56 +01:00
|
|
|
# # to_file(open('slixfeed.log', 'w'))
|
|
|
|
# # with start_action(action_type='set_date()', jid=jid):
|
|
|
|
# # with start_action(action_type='message()', msg=msg):
|
2023-07-16 17:23:10 +02:00
|
|
|
|
2024-01-24 19:11:39 +01:00
|
|
|
#import slixfeed.smtp
|
|
|
|
#import slixfeed.irc
|
|
|
|
#import slixfeed.matrix
|
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
import slixfeed.config as config
|
2024-02-04 19:19:56 +01:00
|
|
|
from slixfeed.version import __version__
|
2023-07-16 17:23:10 +02:00
|
|
|
|
2024-03-07 07:56:11 +01:00
|
|
|
# import socks
|
|
|
|
# import socket
|
2024-01-22 13:48:00 +01:00
|
|
|
|
2024-03-12 18:13:01 +01:00
|
|
|
account = config.get_values('accounts.toml', 'xmpp')
|
2024-03-07 15:52:51 +01:00
|
|
|
|
2024-03-12 18:13:01 +01:00
|
|
|
if not 'mode' in account['settings']:
|
|
|
|
account_mode = 'client'
|
|
|
|
print('Key "mode" was not found.\nSetting value to "client".')
|
|
|
|
# raise Exception('Key type is missing from accounts.toml.')
|
|
|
|
else:
|
|
|
|
account_mode = 'component'
|
2024-01-24 19:11:39 +01:00
|
|
|
|
2024-03-12 18:13:01 +01:00
|
|
|
match account_mode:
|
2024-02-04 19:19:56 +01:00
|
|
|
case 'client':
|
2024-01-24 19:11:39 +01:00
|
|
|
from slixfeed.xmpp.client import Slixfeed
|
2024-03-12 18:13:01 +01:00
|
|
|
# from slixfeed.config import ConfigClient as ConfigAccount
|
2024-02-04 19:19:56 +01:00
|
|
|
case 'component':
|
2024-01-24 21:28:14 +01:00
|
|
|
from slixfeed.xmpp.component import SlixfeedComponent
|
2024-03-12 18:13:01 +01:00
|
|
|
# from slixfeed.config import ConfigComponent as ConfigAccount
|
2024-01-24 19:11:39 +01:00
|
|
|
|
2024-03-12 18:13:01 +01:00
|
|
|
# account = ConfigAccount() # TODO Delete as soon as posible after is no longer needed
|
2024-01-24 19:11:39 +01:00
|
|
|
|
|
|
|
class JabberComponent:
|
2024-01-24 21:28:14 +01:00
|
|
|
def __init__(self, jid, secret, hostname, port, alias=None):
|
|
|
|
xmpp = SlixfeedComponent(jid, secret, hostname, port, alias)
|
2024-01-24 19:11:39 +01:00
|
|
|
xmpp.register_plugin('xep_0004') # Data Forms
|
|
|
|
xmpp.register_plugin('xep_0030') # Service Discovery
|
|
|
|
xmpp.register_plugin('xep_0045') # Multi-User Chat
|
|
|
|
# xmpp.register_plugin('xep_0048') # Bookmarks
|
2024-02-04 18:08:12 +01:00
|
|
|
xmpp.register_plugin('xep_0050') # Ad-Hoc Commands
|
2024-01-24 19:11:39 +01:00
|
|
|
xmpp.register_plugin('xep_0054') # vcard-temp
|
|
|
|
xmpp.register_plugin('xep_0060') # Publish-Subscribe
|
|
|
|
# xmpp.register_plugin('xep_0065') # SOCKS5 Bytestreams
|
|
|
|
xmpp.register_plugin('xep_0066') # Out of Band Data
|
|
|
|
xmpp.register_plugin('xep_0071') # XHTML-IM
|
|
|
|
xmpp.register_plugin('xep_0084') # User Avatar
|
2024-02-11 22:31:31 +01:00
|
|
|
xmpp.register_plugin('xep_0085') # Chat State Notifications
|
2024-02-04 18:08:12 +01:00
|
|
|
xmpp.register_plugin('xep_0115') # Entity Capabilities
|
2024-02-14 18:09:54 +01:00
|
|
|
xmpp.register_plugin('xep_0122') # Data Forms Validation
|
2024-01-24 19:11:39 +01:00
|
|
|
xmpp.register_plugin('xep_0153') # vCard-Based Avatars
|
2024-03-12 20:46:50 +01:00
|
|
|
xmpp.register_plugin('xep_0199') # XMPP Ping
|
2024-02-23 10:00:39 +01:00
|
|
|
xmpp.register_plugin('xep_0203') # Delayed Delivery
|
2024-02-04 18:08:12 +01:00
|
|
|
xmpp.register_plugin('xep_0249') # Direct MUC Invitations
|
2024-02-23 10:00:39 +01:00
|
|
|
xmpp.register_plugin('xep_0297') # Stanza Forwarding
|
|
|
|
xmpp.register_plugin('xep_0356') # Privileged Entity
|
2024-01-24 19:11:39 +01:00
|
|
|
xmpp.register_plugin('xep_0363') # HTTP File Upload
|
|
|
|
xmpp.register_plugin('xep_0402') # PEP Native Bookmarks
|
2024-02-04 18:08:12 +01:00
|
|
|
xmpp.register_plugin('xep_0444') # Message Reactions
|
2024-01-24 19:11:39 +01:00
|
|
|
xmpp.connect()
|
|
|
|
xmpp.process()
|
|
|
|
|
2023-07-16 17:23:10 +02:00
|
|
|
|
2024-01-24 19:11:39 +01:00
|
|
|
class JabberClient:
|
2024-01-24 21:28:14 +01:00
|
|
|
def __init__(self, jid, password, hostname=None, port=None, alias=None):
|
|
|
|
xmpp = Slixfeed(jid, password, hostname, port, alias)
|
2023-12-28 15:50:23 +01:00
|
|
|
xmpp.register_plugin('xep_0004') # Data Forms
|
|
|
|
xmpp.register_plugin('xep_0030') # Service Discovery
|
|
|
|
xmpp.register_plugin('xep_0045') # Multi-User Chat
|
|
|
|
xmpp.register_plugin('xep_0048') # Bookmarks
|
2024-02-04 18:08:12 +01:00
|
|
|
xmpp.register_plugin('xep_0050') # Ad-Hoc Commands
|
2024-01-17 15:36:28 +01:00
|
|
|
xmpp.register_plugin('xep_0054') # vcard-temp
|
2024-01-02 12:42:41 +01:00
|
|
|
xmpp.register_plugin('xep_0060') # Publish-Subscribe
|
|
|
|
# xmpp.register_plugin('xep_0065') # SOCKS5 Bytestreams
|
2024-01-03 11:37:33 +01:00
|
|
|
xmpp.register_plugin('xep_0066') # Out of Band Data
|
|
|
|
xmpp.register_plugin('xep_0071') # XHTML-IM
|
2024-01-17 15:36:28 +01:00
|
|
|
xmpp.register_plugin('xep_0084') # User Avatar
|
2024-02-11 22:31:31 +01:00
|
|
|
xmpp.register_plugin('xep_0085') # Chat State Notifications
|
2024-02-04 18:08:12 +01:00
|
|
|
xmpp.register_plugin('xep_0115') # Entity Capabilities
|
2024-02-14 18:09:54 +01:00
|
|
|
xmpp.register_plugin('xep_0122') # Data Forms Validation
|
2024-01-17 15:36:28 +01:00
|
|
|
xmpp.register_plugin('xep_0153') # vCard-Based Avatars
|
2024-01-02 12:42:41 +01:00
|
|
|
xmpp.register_plugin('xep_0199', {'keepalive': True}) # XMPP Ping
|
2024-02-04 18:08:12 +01:00
|
|
|
xmpp.register_plugin('xep_0249') # Direct MUC Invitations
|
2024-01-03 11:37:33 +01:00
|
|
|
xmpp.register_plugin('xep_0363') # HTTP File Upload
|
2023-12-28 15:50:23 +01:00
|
|
|
xmpp.register_plugin('xep_0402') # PEP Native Bookmarks
|
2024-02-04 18:08:12 +01:00
|
|
|
xmpp.register_plugin('xep_0444') # Message Reactions
|
2024-01-02 12:42:41 +01:00
|
|
|
|
2024-02-04 19:19:56 +01:00
|
|
|
# proxy_enabled = config.get_value('accounts', 'XMPP', 'proxy_enabled')
|
2024-01-02 12:42:41 +01:00
|
|
|
# if proxy_enabled == '1':
|
2024-02-04 19:19:56 +01:00
|
|
|
# values = config.get_value('accounts', 'XMPP', [
|
|
|
|
# 'proxy_host',
|
|
|
|
# 'proxy_port',
|
|
|
|
# 'proxy_username',
|
|
|
|
# 'proxy_password'
|
2024-01-02 12:42:41 +01:00
|
|
|
# ])
|
2024-02-04 19:19:56 +01:00
|
|
|
# print('Proxy is enabled: {}:{}'.format(values[0], values[1]))
|
2024-01-02 12:42:41 +01:00
|
|
|
# xmpp.use_proxy = True
|
|
|
|
# xmpp.proxy_config = {
|
|
|
|
# 'host': values[0],
|
|
|
|
# 'port': values[1],
|
|
|
|
# 'username': values[2],
|
|
|
|
# 'password': values[3]
|
|
|
|
# }
|
|
|
|
# proxy = {'socks5': (values[0], values[1])}
|
|
|
|
# xmpp.proxy = {'socks5': ('localhost', 9050)}
|
|
|
|
|
2023-12-28 15:50:23 +01:00
|
|
|
# Connect to the XMPP server and start processing XMPP stanzas.
|
2024-03-12 18:13:01 +01:00
|
|
|
if hostname and port:
|
|
|
|
xmpp.connect((hostname, port))
|
2024-01-22 13:48:00 +01:00
|
|
|
else:
|
|
|
|
xmpp.connect()
|
2023-12-28 15:50:23 +01:00
|
|
|
xmpp.process()
|
2024-01-22 13:48:00 +01:00
|
|
|
|
|
|
|
|
2024-01-18 21:57:49 +01:00
|
|
|
def main():
|
|
|
|
|
2024-02-04 18:08:12 +01:00
|
|
|
config_dir = config.get_default_config_directory()
|
2024-02-04 19:19:56 +01:00
|
|
|
logging.info('Reading configuration from {}'.format(config_dir))
|
|
|
|
print('Reading configuration from {}'.format(config_dir))
|
2024-01-26 12:34:07 +01:00
|
|
|
|
2024-02-19 21:50:53 +01:00
|
|
|
# values = config.get_value('accounts', 'XMPP Proxy',
|
|
|
|
# ['socks5_host', 'socks5_port'])
|
|
|
|
# if values[0] and values[1]:
|
|
|
|
# host = values[0]
|
|
|
|
# port = values[1]
|
|
|
|
# s = socks.socksocket()
|
|
|
|
# s.set_proxy(socks.SOCKS5, host, port)
|
|
|
|
# # socks.set_default_proxy(socks.SOCKS5, host, port)
|
|
|
|
# # socket.socket = socks.socksocket
|
2024-01-22 13:48:00 +01:00
|
|
|
|
2024-01-18 21:57:49 +01:00
|
|
|
# Setup the command line arguments.
|
2024-03-12 18:13:01 +01:00
|
|
|
match account_mode:
|
2024-02-23 14:51:19 +01:00
|
|
|
case 'client':
|
|
|
|
parser = ArgumentParser(description=Slixfeed.__doc__)
|
|
|
|
case 'component':
|
|
|
|
parser = ArgumentParser(description=SlixfeedComponent.__doc__)
|
2024-01-18 21:57:49 +01:00
|
|
|
|
2024-02-04 19:19:56 +01:00
|
|
|
parser.add_argument('-v', '--version', help='Print version',
|
|
|
|
action='version', version=__version__)
|
|
|
|
|
2024-01-18 21:57:49 +01:00
|
|
|
# Output verbosity options.
|
2024-02-04 19:19:56 +01:00
|
|
|
parser.add_argument('-q', '--quiet', help='set logging to ERROR',
|
|
|
|
action='store_const', dest='loglevel',
|
2024-02-04 18:08:12 +01:00
|
|
|
const=logging.ERROR, default=logging.INFO)
|
2024-02-04 19:19:56 +01:00
|
|
|
parser.add_argument('-d', '--debug', help='set logging to DEBUG',
|
|
|
|
action='store_const', dest='loglevel',
|
2024-02-04 18:08:12 +01:00
|
|
|
const=logging.DEBUG, default=logging.INFO)
|
2024-01-18 21:57:49 +01:00
|
|
|
|
|
|
|
# JID and password options.
|
2024-02-04 19:19:56 +01:00
|
|
|
parser.add_argument('-j', '--jid', help='Jabber ID', dest='jid')
|
|
|
|
parser.add_argument('-p', '--password', help='Password of JID',
|
|
|
|
dest='password')
|
|
|
|
parser.add_argument('-a', '--alias', help='Display name', dest='alias')
|
|
|
|
parser.add_argument('-n', '--hostname', help='Hostname', dest='hostname')
|
|
|
|
parser.add_argument('-o', '--port', help='Port number', dest='port')
|
2024-01-18 21:57:49 +01:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# Setup logging.
|
2024-02-04 18:08:12 +01:00
|
|
|
logging.basicConfig(level=args.loglevel,
|
|
|
|
format='%(levelname)-8s %(message)s')
|
2024-01-18 21:57:49 +01:00
|
|
|
|
2024-03-03 15:13:01 +01:00
|
|
|
# # Setup logging.
|
|
|
|
# logging.basicConfig(level=args.loglevel,
|
|
|
|
# format='%(levelname)-8s %(message)s')
|
|
|
|
# # logging.basicConfig(format='[%(levelname)s] %(message)s')
|
|
|
|
# logger = logging.getLogger()
|
|
|
|
# logdbg = logger.debug
|
|
|
|
# logerr = logger.error
|
|
|
|
# lognfo = logger.info
|
|
|
|
# logwrn = logger.warning
|
|
|
|
|
2024-01-18 21:57:49 +01:00
|
|
|
# Try configuration file
|
2024-03-12 18:13:01 +01:00
|
|
|
jid = account[account_mode]['jid']
|
|
|
|
password = account[account_mode]['password']
|
|
|
|
alias = account[account_mode]['alias'] if 'alias' in account[account_mode] else None
|
|
|
|
hostname = account[account_mode]['hostname'] if 'hostname' in account[account_mode] else None
|
|
|
|
port = account[account_mode]['port'] if 'port' in account[account_mode] else None
|
2024-01-18 21:57:49 +01:00
|
|
|
|
|
|
|
# Use arguments if were given
|
|
|
|
if args.jid:
|
2024-01-24 19:59:10 +01:00
|
|
|
jid = args.jid
|
2024-01-18 21:57:49 +01:00
|
|
|
if args.password:
|
|
|
|
password = args.password
|
2024-01-24 19:11:39 +01:00
|
|
|
if args.alias:
|
|
|
|
alias = args.alias
|
|
|
|
if args.hostname:
|
|
|
|
hostname = args.hostname
|
|
|
|
if args.port:
|
|
|
|
port = args.port
|
2024-01-18 21:57:49 +01:00
|
|
|
|
|
|
|
# Prompt for credentials if none were given
|
2024-01-24 19:59:10 +01:00
|
|
|
if not jid:
|
2024-02-04 19:19:56 +01:00
|
|
|
jid = input('JID: ')
|
2024-01-18 21:57:49 +01:00
|
|
|
if not password:
|
2024-02-04 19:19:56 +01:00
|
|
|
password = getpass('Password: ')
|
2024-01-24 19:11:39 +01:00
|
|
|
if not alias:
|
2024-02-04 19:19:56 +01:00
|
|
|
alias = (input('Alias: ')) or 'Slixfeed'
|
2024-01-24 19:11:39 +01:00
|
|
|
|
2024-03-12 18:13:01 +01:00
|
|
|
match account_mode:
|
2024-02-04 19:19:56 +01:00
|
|
|
case 'client':
|
2024-01-24 21:28:14 +01:00
|
|
|
JabberClient(jid, password, hostname=hostname, port=port, alias=alias)
|
2024-02-04 19:19:56 +01:00
|
|
|
case 'component':
|
2024-01-24 21:28:14 +01:00
|
|
|
JabberComponent(jid, password, hostname, port, alias=alias)
|
2024-01-18 21:57:49 +01:00
|
|
|
sys.exit(0)
|
|
|
|
|
2024-02-04 19:19:56 +01:00
|
|
|
if __name__ == '__main__':
|
2024-01-18 21:57:49 +01:00
|
|
|
main()
|