Modularize code;
Add packaging instructions; Add modules to handle Gemini file type (no Gemini server yet); Improve handling of configuration.
This commit is contained in:
parent
84e54085b5
commit
766e51af4c
46 changed files with 2359 additions and 663 deletions
38
json/index.py
Normal file
38
json/index.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import json
|
||||
import os
|
||||
from rivista.xmpp.utilities import XmppUtilities
|
||||
|
||||
class JsonIndex:
|
||||
|
||||
def generate_json(iq, directory_cache_json):
|
||||
"""Create a JSON file from node items."""
|
||||
json_data = []
|
||||
pubsub = iq['from'].bare
|
||||
node = iq['pubsub']['items']['node']
|
||||
entries = iq['pubsub']['items']
|
||||
for entry in entries:
|
||||
item_id = entry['id']
|
||||
item_payload = entry['payload']
|
||||
namespace = '{http://www.w3.org/2005/Atom}'
|
||||
title = item_payload.find(namespace + 'title')
|
||||
title_text = '*** No Title ***' if title == None else title.text
|
||||
# updated = item.find(namespace + 'updated')
|
||||
# updated = None if updated == None else updated.text
|
||||
# if updated: updated = datetime.datetime.fromisoformat(updated)
|
||||
link_href = XmppUtilities.form_an_item_link(pubsub, node, item_id)
|
||||
# link = item.find(namespace + 'link')
|
||||
# link_href = '' if link == None else link.attrib['href']
|
||||
json_data_entry = {'title' : title_text,
|
||||
'link' : link_href}
|
||||
json_data.append(json_data_entry)
|
||||
#if len(json_data) > 6: break
|
||||
directory = os.path.join(directory_cache_json, pubsub)
|
||||
if not os.path.exists(directory):
|
||||
os.mkdir(directory)
|
||||
filename = os.path.join(directory_cache_json, pubsub, node)
|
||||
|
||||
with open(filename, 'w', encoding='utf-8') as f:
|
||||
json.dump(json_data, f, ensure_ascii=False, indent=4)
|
Loading…
Add table
Add a link
Reference in a new issue