diff --git a/image/script/generate_annotations.py b/image/script/generate_annotations.py
index 5e50348..072be85 100644
--- a/image/script/generate_annotations.py
+++ b/image/script/generate_annotations.py
@@ -1,33 +1,17 @@
import json
import uuid
-import aiohttp
-import asyncio
-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):
+def process_line(line):
folder_name, x, y, _, _, _ = line.strip().split()
annotation_id = str(uuid.uuid4())
- post_data = await get_post_data(session, folder_name)
- if post_data:
- annotation_text = f'🖼️ {post_data["post"]["title"]}
👤 @{post_data["post"]["profile"]["username"]}'
- else:
- annotation_text = "Data not available"
-
annotation = {
"@context": "http://www.w3.org/ns/anno.jsonld",
"id": f"#{annotation_id}",
"type": "Annotation",
"body": [{
"type": "TextualBody",
- "value": annotation_text,
+ "value": folder_name,
"format": "text/html",
"language": "en"
}],
@@ -43,19 +27,13 @@ async def process_line(session, line):
print(f"Appended annotation for {folder_name}")
return annotation
-async def main():
- annotations = []
- async with aiohttp.ClientSession() as session:
- with open('image.txt', 'r') as file:
- lines = file.readlines()
+annotations = []
+with open('../image.txt', 'r') as file:
+ lines = file.readlines()
+ for line in lines:
+ annotations.append(process_line(line))
- tasks = [process_line(session, line) for line in lines]
- annotations = await asyncio.gather(*tasks)
+with open('../../annotations/annotations.w3c.json', 'w') as output_file:
+ json.dump(annotations, output_file, indent=2)
- 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())
+print("Annotations JSON file created.")
diff --git a/script/annotations.js b/script/annotations.js
index cab4f46..24f99f6 100644
--- a/script/annotations.js
+++ b/script/annotations.js
@@ -2,5 +2,46 @@ const anno = OpenSeadragon.Annotorious(viewer);
anno.readOnly = true;
anno.loadAnnotations('annotations/annotations.w3c.json');
+function sendMessageToServer(message) {
+ return new Promise((resolve, reject) => {
+ socket.addEventListener('message', (event) => {
+ if (event.data.toString().length > 5) {
+ let card = JSON.parse(event.data);
+ resolve(card);
+ } else {
+ reject('Invalid response from server');
+ }
+ });
+ socket.send(message);
+ });
+}
+anno.on('clickAnnotation', async function(annotation) {
+ let annotationText = annotation.body[0].value;
+
+ if (!annotationText.includes("sketchersunited.org/")) {
+ try {
+ let newAnnotation = annotation;
+ newAnnotation.body[0].value = "🔁 Downloading label...";
+ anno.updateSelected(newAnnotation);
+
+ let response = await sendMessageToServer(annotationText);
+
+ let trueValueAnnotation = newAnnotation;
+
+ let site = "https://sketchersunited.org"
+ let post_id = response.post.id
+ let post_name = response.post.title
+ let poster_id = response.post.profile.id
+ let poster_name = response.post.profile.username
+ let poster_avatar = response.post.profile.profile_image_url_thumb
+
+ trueValueAnnotation.body[0].value = `