mirror of https://gitlab.com/bashrc2/epicyon
Snake case
parent
651c0d2069
commit
752a44c5d5
22
tox.py
22
tox.py
|
@ -44,22 +44,22 @@ def get_tox_address(actor_json: {}) -> str:
|
||||||
def set_tox_address(actor_json: {}, tox_address: str) -> None:
|
def set_tox_address(actor_json: {}, tox_address: str) -> None:
|
||||||
"""Sets an tox address for the given actor
|
"""Sets an tox address for the given actor
|
||||||
"""
|
"""
|
||||||
notToxAddress = False
|
not_tox_address = False
|
||||||
|
|
||||||
if len(tox_address) != 76:
|
if len(tox_address) != 76:
|
||||||
notToxAddress = True
|
not_tox_address = True
|
||||||
if tox_address.upper() != tox_address:
|
if tox_address.upper() != tox_address:
|
||||||
notToxAddress = True
|
not_tox_address = True
|
||||||
if '"' in tox_address:
|
if '"' in tox_address:
|
||||||
notToxAddress = True
|
not_tox_address = True
|
||||||
if ' ' in tox_address:
|
if ' ' in tox_address:
|
||||||
notToxAddress = True
|
not_tox_address = True
|
||||||
if '.' in tox_address:
|
if '.' in tox_address:
|
||||||
notToxAddress = True
|
not_tox_address = True
|
||||||
if ',' in tox_address:
|
if ',' in tox_address:
|
||||||
notToxAddress = True
|
not_tox_address = True
|
||||||
if '<' in tox_address:
|
if '<' in tox_address:
|
||||||
notToxAddress = True
|
not_tox_address = True
|
||||||
|
|
||||||
if not actor_json.get('attachment'):
|
if not actor_json.get('attachment'):
|
||||||
actor_json['attachment'] = []
|
actor_json['attachment'] = []
|
||||||
|
@ -77,7 +77,7 @@ def set_tox_address(actor_json: {}, tox_address: str) -> None:
|
||||||
break
|
break
|
||||||
if property_found:
|
if property_found:
|
||||||
actor_json['attachment'].remove(property_found)
|
actor_json['attachment'].remove(property_found)
|
||||||
if notToxAddress:
|
if not_tox_address:
|
||||||
return
|
return
|
||||||
|
|
||||||
for property_value in actor_json['attachment']:
|
for property_value in actor_json['attachment']:
|
||||||
|
@ -92,9 +92,9 @@ def set_tox_address(actor_json: {}, tox_address: str) -> None:
|
||||||
property_value['value'] = tox_address
|
property_value['value'] = tox_address
|
||||||
return
|
return
|
||||||
|
|
||||||
newToxAddress = {
|
new_tox_address = {
|
||||||
"name": "Tox",
|
"name": "Tox",
|
||||||
"type": "PropertyValue",
|
"type": "PropertyValue",
|
||||||
"value": tox_address
|
"value": tox_address
|
||||||
}
|
}
|
||||||
actor_json['attachment'].append(newToxAddress)
|
actor_json['attachment'].append(new_tox_address)
|
||||||
|
|
108
video.py
108
video.py
|
@ -22,22 +22,22 @@ def convert_video_to_note(base_dir: str, nickname: str, domain: str,
|
||||||
a Note, so that it can then be displayed in a timeline
|
a Note, so that it can then be displayed in a timeline
|
||||||
"""
|
"""
|
||||||
# check that the required fields are present
|
# check that the required fields are present
|
||||||
requiredFields = (
|
required_fields = (
|
||||||
'type', '@context', 'id', 'published', 'to', 'cc',
|
'type', '@context', 'id', 'published', 'to', 'cc',
|
||||||
'attributedTo', 'commentsEnabled', 'content', 'sensitive',
|
'attributedTo', 'commentsEnabled', 'content', 'sensitive',
|
||||||
'name', 'url'
|
'name', 'url'
|
||||||
)
|
)
|
||||||
for fieldName in requiredFields:
|
for field_name in required_fields:
|
||||||
if not post_json_object.get(fieldName):
|
if not post_json_object.get(field_name):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if post_json_object['type'] != 'Video':
|
if post_json_object['type'] != 'Video':
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# who is this attributed to ?
|
# who is this attributed to ?
|
||||||
attributedTo = None
|
attributed_to = None
|
||||||
if isinstance(post_json_object['attributedTo'], str):
|
if isinstance(post_json_object['attributedTo'], str):
|
||||||
attributedTo = post_json_object['attributedTo']
|
attributed_to = post_json_object['attributedTo']
|
||||||
elif isinstance(post_json_object['attributedTo'], list):
|
elif isinstance(post_json_object['attributedTo'], list):
|
||||||
for entity in post_json_object['attributedTo']:
|
for entity in post_json_object['attributedTo']:
|
||||||
if not isinstance(entity, dict):
|
if not isinstance(entity, dict):
|
||||||
|
@ -48,28 +48,28 @@ def convert_video_to_note(base_dir: str, nickname: str, domain: str,
|
||||||
continue
|
continue
|
||||||
if not entity.get('id'):
|
if not entity.get('id'):
|
||||||
continue
|
continue
|
||||||
attributedTo = entity['id']
|
attributed_to = entity['id']
|
||||||
break
|
break
|
||||||
if not attributedTo:
|
if not attributed_to:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# get the language of the video
|
# get the language of the video
|
||||||
postLanguage = system_language
|
post_language = system_language
|
||||||
if post_json_object.get('language'):
|
if post_json_object.get('language'):
|
||||||
if isinstance(post_json_object['language'], dict):
|
if isinstance(post_json_object['language'], dict):
|
||||||
if post_json_object['language'].get('identifier'):
|
if post_json_object['language'].get('identifier'):
|
||||||
postLanguage = post_json_object['language']['identifier']
|
post_language = post_json_object['language']['identifier']
|
||||||
|
|
||||||
# check that the attributed actor is not blocked
|
# check that the attributed actor is not blocked
|
||||||
postNickname = get_nickname_from_actor(attributedTo)
|
post_nickname = get_nickname_from_actor(attributed_to)
|
||||||
if not postNickname:
|
if not post_nickname:
|
||||||
return None
|
return None
|
||||||
postDomain, postDomainPort = get_domain_from_actor(attributedTo)
|
post_domain, post_domain_port = get_domain_from_actor(attributed_to)
|
||||||
if not postDomain:
|
if not post_domain:
|
||||||
return None
|
return None
|
||||||
postDomainFull = get_full_domain(postDomain, postDomainPort)
|
post_domain_full = get_full_domain(post_domain, post_domain_port)
|
||||||
if is_blocked(base_dir, nickname, domain,
|
if is_blocked(base_dir, nickname, domain,
|
||||||
postNickname, postDomainFull, blocked_cache):
|
post_nickname, post_domain_full, blocked_cache):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# check that the content is valid
|
# check that the content is valid
|
||||||
|
@ -89,90 +89,90 @@ def convert_video_to_note(base_dir: str, nickname: str, domain: str,
|
||||||
content += '<p>' + post_json_object['license']['name'] + '</p>'
|
content += '<p>' + post_json_object['license']['name'] + '</p>'
|
||||||
content += post_json_object['content']
|
content += post_json_object['content']
|
||||||
|
|
||||||
conversationId = remove_id_ending(post_json_object['id'])
|
conversation_id = remove_id_ending(post_json_object['id'])
|
||||||
|
|
||||||
mediaType = None
|
media_type = None
|
||||||
mediaUrl = None
|
media_url = None
|
||||||
mediaTorrent = None
|
media_torrent = None
|
||||||
mediaMagnet = None
|
media_magnet = None
|
||||||
for mediaLink in post_json_object['url']:
|
for media_link in post_json_object['url']:
|
||||||
if not isinstance(mediaLink, dict):
|
if not isinstance(media_link, dict):
|
||||||
continue
|
continue
|
||||||
if not mediaLink.get('mediaType'):
|
if not media_link.get('mediaType'):
|
||||||
continue
|
continue
|
||||||
if not mediaLink.get('href'):
|
if not media_link.get('href'):
|
||||||
continue
|
continue
|
||||||
if mediaLink['mediaType'] == 'application/x-bittorrent':
|
if media_link['mediaType'] == 'application/x-bittorrent':
|
||||||
mediaTorrent = mediaLink['href']
|
media_torrent = media_link['href']
|
||||||
if mediaLink['href'].startswith('magnet:'):
|
if media_link['href'].startswith('magnet:'):
|
||||||
mediaMagnet = mediaLink['href']
|
media_magnet = media_link['href']
|
||||||
if mediaLink['mediaType'] != 'video/mp4' and \
|
if media_link['mediaType'] != 'video/mp4' and \
|
||||||
mediaLink['mediaType'] != 'video/ogv':
|
media_link['mediaType'] != 'video/ogv':
|
||||||
continue
|
continue
|
||||||
if not mediaUrl:
|
if not media_url:
|
||||||
mediaType = mediaLink['mediaType']
|
media_type = media_link['mediaType']
|
||||||
mediaUrl = mediaLink['href']
|
media_url = media_link['href']
|
||||||
|
|
||||||
if not mediaUrl:
|
if not media_url:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
attachment = [{
|
attachment = [{
|
||||||
'mediaType': mediaType,
|
'mediaType': media_type,
|
||||||
'name': post_json_object['content'],
|
'name': post_json_object['content'],
|
||||||
'type': 'Document',
|
'type': 'Document',
|
||||||
'url': mediaUrl
|
'url': media_url
|
||||||
}]
|
}]
|
||||||
|
|
||||||
if mediaTorrent or mediaMagnet:
|
if media_torrent or media_magnet:
|
||||||
content += '<p>'
|
content += '<p>'
|
||||||
if mediaTorrent:
|
if media_torrent:
|
||||||
content += '<a href="' + mediaTorrent + '">⇓</a> '
|
content += '<a href="' + media_torrent + '">⇓</a> '
|
||||||
if mediaMagnet:
|
if media_magnet:
|
||||||
content += '<a href="' + mediaMagnet + '">🧲</a>'
|
content += '<a href="' + media_magnet + '">🧲</a>'
|
||||||
content += '</p>'
|
content += '</p>'
|
||||||
|
|
||||||
newPostId = remove_id_ending(post_json_object['id'])
|
new_post_id = remove_id_ending(post_json_object['id'])
|
||||||
newPost = {
|
new_post = {
|
||||||
'@context': post_json_object['@context'],
|
'@context': post_json_object['@context'],
|
||||||
'id': newPostId + '/activity',
|
'id': new_post_id + '/activity',
|
||||||
'type': 'Create',
|
'type': 'Create',
|
||||||
'actor': attributedTo,
|
'actor': attributed_to,
|
||||||
'published': post_json_object['published'],
|
'published': post_json_object['published'],
|
||||||
'to': post_json_object['to'],
|
'to': post_json_object['to'],
|
||||||
'cc': post_json_object['cc'],
|
'cc': post_json_object['cc'],
|
||||||
'object': {
|
'object': {
|
||||||
'id': newPostId,
|
'id': new_post_id,
|
||||||
'conversation': conversationId,
|
'conversation': conversation_id,
|
||||||
'type': 'Note',
|
'type': 'Note',
|
||||||
'summary': None,
|
'summary': None,
|
||||||
'inReplyTo': None,
|
'inReplyTo': None,
|
||||||
'published': post_json_object['published'],
|
'published': post_json_object['published'],
|
||||||
'url': newPostId,
|
'url': new_post_id,
|
||||||
'attributedTo': attributedTo,
|
'attributedTo': attributed_to,
|
||||||
'to': post_json_object['to'],
|
'to': post_json_object['to'],
|
||||||
'cc': post_json_object['cc'],
|
'cc': post_json_object['cc'],
|
||||||
'sensitive': post_json_object['sensitive'],
|
'sensitive': post_json_object['sensitive'],
|
||||||
'atomUri': newPostId,
|
'atomUri': new_post_id,
|
||||||
'inReplyToAtomUri': None,
|
'inReplyToAtomUri': None,
|
||||||
'commentsEnabled': post_json_object['commentsEnabled'],
|
'commentsEnabled': post_json_object['commentsEnabled'],
|
||||||
'rejectReplies': not post_json_object['commentsEnabled'],
|
'rejectReplies': not post_json_object['commentsEnabled'],
|
||||||
'mediaType': 'text/html',
|
'mediaType': 'text/html',
|
||||||
'content': content,
|
'content': content,
|
||||||
'contentMap': {
|
'contentMap': {
|
||||||
postLanguage: content
|
post_language: content
|
||||||
},
|
},
|
||||||
'attachment': attachment,
|
'attachment': attachment,
|
||||||
'tag': [],
|
'tag': [],
|
||||||
'replies': {
|
'replies': {
|
||||||
'id': newPostId + '/replies',
|
'id': new_post_id + '/replies',
|
||||||
'type': 'Collection',
|
'type': 'Collection',
|
||||||
'first': {
|
'first': {
|
||||||
'type': 'CollectionPage',
|
'type': 'CollectionPage',
|
||||||
'partOf': newPostId + '/replies',
|
'partOf': new_post_id + '/replies',
|
||||||
'items': []
|
'items': []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newPost
|
return new_post
|
||||||
|
|
Loading…
Reference in New Issue