teddy suffering
This commit is contained in:
parent
1db9bd33cb
commit
35838d8081
|
@ -1,17 +1,33 @@
|
||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
|
import aiohttp
|
||||||
|
import asyncio
|
||||||
|
|
||||||
def process_line(line):
|
async def get_post_data(session, folder_name):
|
||||||
|
url = f"https://sketchersunited.org/posts/{folder_name.split('by')[0]}"
|
||||||
|
headers = {"Accept": "text/json"}
|
||||||
|
async with session.get(url, headers=headers) as response:
|
||||||
|
if response.status == 200:
|
||||||
|
return await response.json()
|
||||||
|
return None
|
||||||
|
|
||||||
|
async def process_line(session, line):
|
||||||
folder_name, x, y, _, _, _ = line.strip().split()
|
folder_name, x, y, _, _, _ = line.strip().split()
|
||||||
annotation_id = str(uuid.uuid4())
|
annotation_id = str(uuid.uuid4())
|
||||||
|
|
||||||
|
post_data = await get_post_data(session, folder_name)
|
||||||
|
if post_data:
|
||||||
|
annotation_text = f'🖼️ <a href="https://sketchersunited.org/posts/{post_data["post"]["id"]}">{post_data["post"]["title"]}</a> <br>👤 <a href="https://sketchersunited.org/users/{post_data["post"]["profile"]["id"]}">@{post_data["post"]["profile"]["username"]}</a>'
|
||||||
|
else:
|
||||||
|
annotation_text = "Data not available"
|
||||||
|
|
||||||
annotation = {
|
annotation = {
|
||||||
"@context": "http://www.w3.org/ns/anno.jsonld",
|
"@context": "http://www.w3.org/ns/anno.jsonld",
|
||||||
"id": f"#{annotation_id}",
|
"id": f"#{annotation_id}",
|
||||||
"type": "Annotation",
|
"type": "Annotation",
|
||||||
"body": [{
|
"body": [{
|
||||||
"type": "TextualBody",
|
"type": "TextualBody",
|
||||||
"value": folder_name,
|
"value": annotation_text,
|
||||||
"format": "text/html",
|
"format": "text/html",
|
||||||
"language": "en",
|
"language": "en",
|
||||||
"tag": folder_name
|
"tag": folder_name
|
||||||
|
@ -28,13 +44,19 @@ def process_line(line):
|
||||||
print(f"Appended annotation for {folder_name}")
|
print(f"Appended annotation for {folder_name}")
|
||||||
return annotation
|
return annotation
|
||||||
|
|
||||||
annotations = []
|
async def main():
|
||||||
with open('image.txt', 'r') as file:
|
annotations = []
|
||||||
lines = file.readlines()
|
async with aiohttp.ClientSession() as session:
|
||||||
for line in lines:
|
with open('image.txt', 'r') as file:
|
||||||
annotations.append(process_line(line))
|
lines = file.readlines()
|
||||||
|
|
||||||
with open('../annotations/annotations.w3c.json', 'w') as output_file:
|
tasks = [process_line(session, line) for line in lines]
|
||||||
json.dump(annotations, output_file, indent=2)
|
annotations = await asyncio.gather(*tasks)
|
||||||
|
|
||||||
print("Annotations JSON file created.")
|
with open('../annotations/annotations.w3c.json', 'w') as output_file:
|
||||||
|
json.dump(annotations, output_file, indent=2)
|
||||||
|
|
||||||
|
print("Annotations JSON file created.")
|
||||||
|
|
||||||
|
# Run the asynchronous code
|
||||||
|
asyncio.run(main())
|
||||||
|
|
Loading…
Reference in New Issue