import blogs
import root
from datetime import datetime
activity_pub_path = f"/socialweb"
domain = "deadvey.com"
url = f"https://{domain}"
images_url = f"{url}/images"
username = "blog"
account_path = f"{url}/@{username}"
description = "Linux, tech and film reviews"
for index, current_blog in enumerate(blogs.blogs_array):
with open(f"{root.path}/{activity_pub_path}/notes/{index}", "w") as current_note_file:
post = f"{current_blog[0]}:
{current_blog[1]}"
for image in current_blog[3]:
post += f'
'
post = post.replace("\\", "\\\\").replace('"', '\\"').replace("\n", "
").replace("\t", " ")
content = f'''
{{
"@context": "https://www.w3.org/ns/activitystreams",
"id": "{url}/{activity_pub_path}/notes/{index}",
"type": "Note",
"hash": "{index}",
"content": "{post}",
"url": "{url}/blog/{index}.html",
"attributedTo": "{account_path}",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [],
"published": "{current_blog[2]}",
"replies": {{
"id": "https://deadvey.com/socialweb/replies/{index}",
"type": "Collection",
"first": {{
"type": "CollectionPage",
"next": "https://deadvey.com/socialweb/replies/{index}?page=true",
"partOf": "https://deadvey.com/socialweb/replies/{index}",
"items": []
}}
}},
"tag": [
'''
for index, x in enumerate(current_blog[4]):
content += f'''
{{
"Type": "Hashtag",
"Href": "{url}/blog/{x.replace("/","per")}.html",
"Name": "#{x}"
}}'''
if index != len(current_blog[4])-1:
content += ''','''
content += '''
]
}'''
current_note_file.write(content)
with open(f"{root.path}/{activity_pub_path}/outbox","w") as outbox_file:
content = f'''
{{
"@context": "https://www.w3.org/ns/activitystreams",
"id": "{url}/{activity_pub_path}/outbox",
"type": "OrderedCollection",
"summary": "{description}",
"totalItems": {len(blogs.blogs_array)},
"orderedItems": ['''
for current_blog_index in range(len(blogs.blogs_array)-1, -1, -1):
post = f"{blogs.blogs_array[current_blog_index][0]}:
{blogs.blogs_array[current_blog_index][1]}"
for image in blogs.blogs_array[current_blog_index][3]:
post += f'
'
post = post.replace("\\", "\\\\").replace('"', '\\"').replace("\n", "
").replace("\t", " ")
content += f'''
{{
"@context": "https://www.w3.org/ns/activitystreams",
"id": "{url}/{activity_pub_path}/notes/{current_blog_index}",
"type": "Note",
"hash": "{current_blog_index}",
"actor": "{account_path}",
"to": [
"https://www.w3.org/ns/activitystreams#Public"
],
"cc": [],
"published": "{blogs.blogs_array[current_blog_index][2]}",
"tag": ['''
for index2, x in enumerate(blogs.blogs_array[current_blog_index][4]):
content += f'''
{{
"Type": "Hashtag",
"Href": "{url}/blog/{x.replace("/","per")}.html",
"Name": "#{x}"
}}'''
if index2 != len(blogs.blogs_array[current_blog_index][4])-1:
content += ''','''
content += '''
]
}'''
if current_blog_index != 0:
content += ''','''
content += '''
]
}
'''
outbox_file.write(content)