__filename__ = "webinterface.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "0.0.1"
__maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net"
__status__ = "Production"
import json
def htmlHeader(lang='en') -> str:
htmlStr= \
'\n' \
'\n' \
' \n' \
' \n' \
'
\n'
return htmlStr
def htmlFooter() -> str:
htmlStr= \
' \n' \
'\n'
return htmlStr
def htmlProfile(profileJson: {}) -> str:
"""Show the profile page as html
"""
return htmlHeader()+"Profile page
"+htmlFooter()
def htmlFollowing(followingJson: {}) -> str:
"""Show the following collection as html
"""
return htmlHeader()+"Following collection
"+htmlFooter()
def htmlFollowers(followersJson: {}) -> str:
"""Show the followers collection as html
"""
return htmlHeader()+"Followers collection
"+htmlFooter()
def individualPostAsHtml(postJsonObject: {}) -> str:
avatarPosition=''
containerClass='container'
timeClass='time-right'
if postJsonObject['object']['inReplyTo']:
containerClass='container darker'
avatarPosition=' class="right"'
timeClass='time-left'
attachmentStr=''
if postJsonObject['object']['attachment']:
if isinstance(postJsonObject['object']['attachment'], list):
attachmentCtr=0
for attach in postJsonObject['object']['attachment']:
if attach.get('mediaType') and attach.get('url'):
mediaType=attach['mediaType']
imageDescription=''
if attach.get('name'):
imageDescription=attach['name']
if mediaType=='image/png' or \
mediaType=='image/jpeg' or \
mediaType=='image/gif':
if attach['url'].endswith('.png') or \
attach['url'].endswith('.jpg') or \
attach['url'].endswith('.jpeg') or \
attach['url'].endswith('.gif'):
if attachmentCtr>0:
attachmentStr+='
'
attachmentStr+= \
'' \
'\n'
attachmentCtr+=1
return \
'\n' \
'
' \
'\n'+ \
postJsonObject['object']['content']+'\n'+ \
attachmentStr+ \
'
'+postJsonObject['object']['published']+'\n'+ \
'
\n'
def htmlTimeline(timelineJson: {}) -> str:
"""Show the timeline as html
"""
if not timelineJson.get('orderedItems'):
return ""
tlStr=htmlHeader()
for item in timelineJson['orderedItems']:
if item['type']=='Create':
tlStr+=individualPostAsHtml(item)
tlStr+=htmlFooter()
return tlStr
def htmlInbox(inboxJson: {}) -> str:
"""Show the inbox as html
"""
return htmlTimeline(inboxJson)
def htmlOutbox(outboxJson: {}) -> str:
"""Show the Outbox as html
"""
return htmlTimeline(outboxJson)
def htmlIndividualPost(postJsonObject: {}) -> str:
"""Show an individual post as html
"""
return htmlHeader()+ \
individualPostAsHtml(postJsonObject)+ \
htmlFooter()
def htmlPostReplies(postJsonObject: {}) -> str:
"""Show the replies to an individual post as html
"""
return htmlHeader()+"Replies
"+htmlFooter()