implement categories/tags listing
This commit is contained in:
parent
c7ea1bc1c8
commit
1fdfbe54af
108
example.py
108
example.py
|
@ -10,7 +10,7 @@ import yaml
|
|||
from slugify import slugify
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from xml.etree import ElementTree
|
||||
from flask import Flask, request, url_for, Response
|
||||
from requests import api
|
||||
from flask_micropub import MicropubClient
|
||||
|
@ -110,25 +110,26 @@ def req():
|
|||
if 'photo' in doc:
|
||||
|
||||
if os.environ.get('MICROPUB_IMAGE_STRATEGY') == 'copy':
|
||||
# download the photo
|
||||
r = requests.get(doc['photo'])
|
||||
# download the photo
|
||||
r = requests.get(doc['photo'])
|
||||
|
||||
# generate local filename
|
||||
filename = os.path.join(os.environ.get('MICROPUB_MEDIA_PATH'), now.strftime("%Y/%m/%d"), str(now_ts) + ".jpg")
|
||||
photo_url = os.path.join(os.environ.get('MICROPUB_MEDIA_URL_PREFIX'), now.strftime("%Y/%m/%d"), str(now_ts) + ".jpg")
|
||||
# generate local filename
|
||||
filename = os.path.join(os.environ.get(
|
||||
'MICROPUB_MEDIA_PATH'), now.strftime("%Y/%m/%d"), str(now_ts) + ".jpg")
|
||||
photo_url = os.path.join(os.environ.get(
|
||||
'MICROPUB_MEDIA_URL_PREFIX'), now.strftime("%Y/%m/%d"), str(now_ts) + ".jpg")
|
||||
|
||||
# make directory if needed
|
||||
if not os.path.exists(os.path.dirname(filename)):
|
||||
os.makedirs(os.path.dirname(filename))
|
||||
# make directory if needed
|
||||
if not os.path.exists(os.path.dirname(filename)):
|
||||
os.makedirs(os.path.dirname(filename))
|
||||
|
||||
with open(filename, 'wb') as f:
|
||||
f.write(r.content)
|
||||
with open(filename, 'wb') as f:
|
||||
f.write(r.content)
|
||||
|
||||
# elif os.environ.get('MICROPUB_IMAGE_STRATEGY') == 'gitea':
|
||||
|
||||
else:
|
||||
photo_url = doc['photo']
|
||||
|
||||
photo_url = doc['photo']
|
||||
|
||||
docstr = f"![image]({photo_url}) \n\n {doc['content']}"
|
||||
else:
|
||||
|
@ -155,42 +156,61 @@ def req():
|
|||
# return {"hello": "world"}
|
||||
|
||||
|
||||
def parse_categories():
|
||||
|
||||
strategy = os.environ.get('MICROPUB_CATEGORY_LIST_STRATEGY')
|
||||
|
||||
if strategy == 'feed':
|
||||
tree = ElementTree.parse(os.environ.get('MICROPUB_CATEGORY_LIST_FILE'))
|
||||
tags = tree.findall('.//item/title')
|
||||
|
||||
|
||||
return {"categories": [tag.text for tag in tags] }
|
||||
|
||||
|
||||
def generate_config_json():
|
||||
return {
|
||||
"media-endpoint": "/micropub/media",
|
||||
"syndicate-to": [
|
||||
{
|
||||
"uid": "mastodon",
|
||||
"name": "Mastodon"
|
||||
}
|
||||
],
|
||||
"post-types": [
|
||||
{
|
||||
"type": "note",
|
||||
"name": "Note"
|
||||
},
|
||||
{
|
||||
"type": "article",
|
||||
"name": "Blog Post"
|
||||
},
|
||||
{
|
||||
"type": "photo",
|
||||
"name": "Photo"
|
||||
},
|
||||
{
|
||||
"type": "reply",
|
||||
"name": "Reply"
|
||||
},
|
||||
{
|
||||
"type": "bookmark",
|
||||
"name": "Bookmark"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@app.route("/", methods=['GET'])
|
||||
@authed_endpoint
|
||||
def index():
|
||||
|
||||
if request.args.get('q') == 'config':
|
||||
return {
|
||||
"media-endpoint": "/micropub/media",
|
||||
"syndicate-to": [
|
||||
{
|
||||
"uid": "mastodon",
|
||||
"name": "Mastodon"
|
||||
}
|
||||
],
|
||||
"post-types": [
|
||||
{
|
||||
"type": "note",
|
||||
"name": "Note"
|
||||
},
|
||||
{
|
||||
"type": "article",
|
||||
"name": "Blog Post"
|
||||
},
|
||||
{
|
||||
"type": "photo",
|
||||
"name": "Photo"
|
||||
},
|
||||
{
|
||||
"type": "reply",
|
||||
"name": "Reply"
|
||||
},
|
||||
{
|
||||
"type": "bookmark",
|
||||
"name": "Bookmark"
|
||||
}
|
||||
]
|
||||
}
|
||||
return generate_config_json()
|
||||
|
||||
elif request.args.get('q') == 'category':
|
||||
return parse_categories()
|
||||
|
||||
|
||||
@app.route('/form', methods=['GET'])
|
||||
|
|
Loading…
Reference in New Issue