Compare commits

..

No commits in common. "dac0c771dd33283e749a9c0094369a2bc1ba247f" and "79b80b169846157d6f4407ff027dd4be427c3ee8" have entirely different histories.

4 changed files with 6105 additions and 38 deletions

2253
slixfeed/xmpp/adhoc.py Normal file

File diff suppressed because it is too large Load diff

View file

@ -400,7 +400,20 @@ class XmppClient(slixmpp.ClientXMPP):
print('POSIX sockets: Initiating IPC server...')
self.ipc = asyncio.create_task(XmppIpcServer.ipc(self))
for result in await XmppPubsub.get_pubsub_services(self):
jids_of_pubsub = await XmppPubsub.get_pubsub_services(self)
for jid_bare in jids_of_pubsub:
jid_bare['type'] = 'pubsub'
# NOTE Do you need 'name' too, or only 'jid'?
#jids_of_roster = []
#for jid_bare in self.client_roster:
# jids_of_roster.append({'jid' : jid_bare,
# 'name' : '',
# 'type' : 'pep'})
jid_of_slixfeed = [{'jid' : self.boundjid.bare,
'name' : self.alias,
'type' : 'pep'}]
#for result in jids_of_pubsub + jids_of_roster + jid_of_slixfeed:
for result in jids_of_pubsub + jid_of_slixfeed:
jid_bare = result['jid']
if jid_bare not in self.settings:
db_file = config.get_pathname_to_database(jid_bare)
@ -418,7 +431,8 @@ class XmppClient(slixmpp.ClientXMPP):
asyncio.create_task(FeedTask.loop_task(self, jid_bare))
#await asyncio.sleep(10)
print('publish task for {}'.format(jid_bare))
asyncio.create_task(XmppPubsubTask.loop_task(self, jid_bare)),
publish_type = result['type']
asyncio.create_task(XmppPubsubTask.loop_task(self, jid_bare, publish_type)),
print('End')
time_end = time.time()
@ -1043,8 +1057,6 @@ class XmppClient(slixmpp.ClientXMPP):
form.add_field(desc='Enter a node to publish to.',
ftype='text-single',
label='Node',
required=True,
value='Slixfeed',
var='node')
# options = form.add_field(desc='Select XMPP Extension Protocol.',
# ftype='list-single',
@ -1053,7 +1065,7 @@ class XmppClient(slixmpp.ClientXMPP):
# value='0060',
# var='xep')
# options.addOption('XEP-0060: Publish-Subscribe', '0060')
# options.addOption('XEP-0277: Journaling over XMPP', '0277')
# options.addOption('XEP-0277: Microblogging over XMPP', '0277')
# options.addOption('XEP-0472: Pubsub Social Feed', '0472')
session['payload'] = form
session['allow_prev'] = True
@ -1096,6 +1108,11 @@ class XmppClient(slixmpp.ClientXMPP):
jid_bare = values['jid_bare']
node = values['node']
# xep = values['xep']
if not node:
if jid == self.boundjid.bare:
node = 'urn:xmpp:microblog:0'
else:
node = 'slixfeed'
form = self['xep_0004'].make_form('form', 'Publish')
form.add_field(var='node',
@ -1199,7 +1216,11 @@ class XmppClient(slixmpp.ClientXMPP):
node = values['node']
url = values['url']
# xep = values['xep']
if not node: node = Url.get_hostname(url)
if not node:
if jid == self.boundjid.bare:
node = 'urn:xmpp:microblog:0'
else:
node = Url.get_hostname(url)
form = self['xep_0004'].make_form('form', 'Publish')
while True:
result = await fetch.http(url)
@ -3162,7 +3183,7 @@ class XmppClient(slixmpp.ClientXMPP):
form = self['xep_0004'].make_form('form', 'PubSub')
form['instructions'] = ('Designate Publish-Subscribe services '
'for IoT updates, news publishing, '
'and even for publishing on '
'and even for microblogging on '
'platforms such as Libervia and Movim.')
form.add_field(desc='Select PubSub services to designate.',
ftype='fixed',

3769
slixfeed/xmpp/component.py Normal file

File diff suppressed because it is too large Load diff

View file

@ -260,9 +260,20 @@ class XmppPubsubAction:
function_name = sys._getframe().f_code.co_name
logger.debug('{}: jid_bare: {}'.format(function_name, jid_bare))
db_file = config.get_pathname_to_database(jid_bare)
feed_id = sqlite.get_feed_id_by_entry_index(db_file, entry_id)
feed_id = feed_id[0]
node_id, node_title, node_subtitle = sqlite.get_feed_properties(db_file, feed_id)
report = {}
if jid_bare == self.boundjid.bare:
node_id = 'urn:xmpp:microblog:0'
node_subtitle = None
node_title = None
else:
feed_id = sqlite.get_feed_id_by_entry_index(db_file, entry_id)
feed_id = feed_id[0]
node_id, node_title, node_subtitle = sqlite.get_feed_properties(db_file, feed_id)
print('THIS IS A TEST')
print(node_id)
print(node_title)
print(node_subtitle)
print('THIS IS A TEST')
xep = None
iq_create_node = XmppPubsub.create_node(
self, jid_bare, node_id, xep, node_title, node_subtitle)
@ -272,23 +283,25 @@ class XmppPubsubAction:
print(node_id)
entry_dict = Feed.pack_entry_into_dict(db_file, entry)
node_item = Feed.create_rfc4287_entry(entry_dict)
item_id = Utilities.hash_url_to_md5(entry_dict['link'])
entry_url = entry_dict['link']
item_id = Utilities.hash_url_to_md5(entry_url)
iq_create_entry = XmppPubsub.create_entry(
self, jid_bare, node_id, item_id, node_item)
await XmppIQ.send(self, iq_create_entry)
await sqlite.mark_as_read(db_file, entry_id)
# NOTE This value is returned for the sake of testing
return entry_dict['link']
report = entry_url
return report
async def send_unread_items(self, jid_bare):
async def send_unread_items(self, jid_bare, publish_type):
"""
Parameters
----------
jid_bare : str
Bare Jabber ID.
publish_type : str
To which type of PubSub ('pep' or 'pubsub').
Returns
-------
@ -309,28 +322,39 @@ class XmppPubsubAction:
feed_id = sqlite.get_feed_id(db_file, url)
feed_id = feed_id[0]
# Publish to node 'urn:xmpp:microblog:0' for own JID
# Publish to node based on feed identifier for PubSub service.
# node_id = feed_properties[2]
# node_title = feed_properties[3]
# node_subtitle = feed_properties[5]
node_id = sqlite.get_feed_identifier(db_file, feed_id)
node_id = node_id[0]
if not node_id:
counter = 0
while True:
identifier = String.generate_identifier(url, counter)
if sqlite.check_identifier_exist(db_file, identifier):
counter += 1
else:
break
await sqlite.update_feed_identifier(db_file, feed_id, identifier)
node_id = sqlite.get_feed_identifier(db_file, feed_id)
node_id = node_id[0]
node_title = sqlite.get_feed_title(db_file, feed_id)
node_title = node_title[0]
node_subtitle = sqlite.get_feed_subtitle(db_file, feed_id)
node_subtitle = node_subtitle[0]
match publish_type:
# XEP-0163: Personal Eventing Protocol
# 2.2 One Publisher Per Node¶
# The owner-publisher for every node is the bare JID of the account owner.
case 'pep':
node_id = 'urn:xmpp:microblog:0'
node_subtitle = None
node_title = None
case 'pubsub':
# node_id = feed_properties[2]
# node_title = feed_properties[3]
# node_subtitle = feed_properties[5]
node_id = sqlite.get_feed_identifier(db_file, feed_id)
node_id = node_id[0]
if not node_id:
counter = 0
while True:
identifier = String.generate_identifier(url, counter)
if sqlite.check_identifier_exist(db_file, identifier):
counter += 1
else:
break
await sqlite.update_feed_identifier(db_file, feed_id, identifier)
node_id = sqlite.get_feed_identifier(db_file, feed_id)
node_id = node_id[0]
node_title = sqlite.get_feed_title(db_file, feed_id)
node_title = node_title[0]
node_subtitle = sqlite.get_feed_subtitle(db_file, feed_id)
node_subtitle = node_subtitle[0]
print ([jid_bare, publish_type, node_id])
xep = None
#node_exist = await XmppPubsub.get_node_configuration(self, jid_bare, node_id)
nodes = await XmppPubsub.get_nodes(self, jid_bare)
@ -371,7 +395,7 @@ class XmppPubsubAction:
class XmppPubsubTask:
async def loop_task(self, jid_bare):
async def loop_task(self, jid_bare, publish_type):
db_file = config.get_pathname_to_database(jid_bare)
if jid_bare not in self.settings:
Config.add_settings_jid(self, jid_bare, db_file)
@ -388,7 +412,7 @@ class XmppPubsubTask:
.format(jid_bare))
logger.info('Starting tasks "publish" for JID {}'.format(jid_bare))
self.task_manager[jid_bare]['publish'] = asyncio.create_task(
XmppPubsubAction.send_unread_items(self, jid_bare))
XmppPubsubAction.send_unread_items(self, jid_bare, publish_type))
await asyncio.sleep(60 * 180)