ough yaaeaaa
This commit is contained in:
parent
8a4e14d818
commit
96e378fd77
|
@ -1,33 +1,17 @@
|
||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
import aiohttp
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
async def get_post_data(session, folder_name):
|
def process_line(line):
|
||||||
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": annotation_text,
|
"value": folder_name,
|
||||||
"format": "text/html",
|
"format": "text/html",
|
||||||
"language": "en"
|
"language": "en"
|
||||||
}],
|
}],
|
||||||
|
@ -43,19 +27,13 @@ async def process_line(session, line):
|
||||||
print(f"Appended annotation for {folder_name}")
|
print(f"Appended annotation for {folder_name}")
|
||||||
return annotation
|
return annotation
|
||||||
|
|
||||||
async def main():
|
annotations = []
|
||||||
annotations = []
|
with open('../image.txt', 'r') as file:
|
||||||
async with aiohttp.ClientSession() as session:
|
|
||||||
with open('image.txt', 'r') as file:
|
|
||||||
lines = file.readlines()
|
lines = file.readlines()
|
||||||
|
for line in lines:
|
||||||
|
annotations.append(process_line(line))
|
||||||
|
|
||||||
tasks = [process_line(session, line) for line in lines]
|
with open('../../annotations/annotations.w3c.json', 'w') as output_file:
|
||||||
annotations = await asyncio.gather(*tasks)
|
|
||||||
|
|
||||||
with open('../annotations/annotations.w3c.json', 'w') as output_file:
|
|
||||||
json.dump(annotations, output_file, indent=2)
|
json.dump(annotations, output_file, indent=2)
|
||||||
|
|
||||||
print("Annotations JSON file created.")
|
print("Annotations JSON file created.")
|
||||||
|
|
||||||
# Run the asynchronous code
|
|
||||||
asyncio.run(main())
|
|
||||||
|
|
|
@ -2,5 +2,46 @@ const anno = OpenSeadragon.Annotorious(viewer);
|
||||||
anno.readOnly = true;
|
anno.readOnly = true;
|
||||||
anno.loadAnnotations('annotations/annotations.w3c.json');
|
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 = `<div class = "profile-container"><div class="profileimg"><img src = "${poster_avatar}"></div><div class="profile"><a href = "${site}/posts/${post_id}" class="rainbow">${post_name}</a><br><a href = "${site}/users/${poster_id}">@${poster_name}</a></div></div>`;
|
||||||
|
|
||||||
|
anno.updateSelected(trueValueAnnotation);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
@ -1,21 +1,11 @@
|
||||||
let dictionaries = []
|
let dictionaries = []
|
||||||
const imagePromises = [];
|
|
||||||
let image_count = 0
|
let image_count = 0
|
||||||
|
|
||||||
function load_image(image) {
|
function load_image(image) {
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
viewer.addTiledImage({
|
viewer.addTiledImage({
|
||||||
tileSource: image.tileSource,
|
tileSource: image.tileSource,
|
||||||
x: image.x,
|
x: image.x,
|
||||||
y: image.y,
|
y: image.y,
|
||||||
opacity: 1,
|
|
||||||
success: () => {
|
|
||||||
resolve();
|
|
||||||
},
|
|
||||||
error: (err) => {
|
|
||||||
reject(err);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,10 +32,9 @@ fetch('image/image.txt')
|
||||||
blue: parseInt(parts[5]),
|
blue: parseInt(parts[5]),
|
||||||
};
|
};
|
||||||
|
|
||||||
const promise = load_image(dictionary);
|
load_image(dictionary);
|
||||||
|
|
||||||
dictionaries.push(dictionary);
|
dictionaries.push(dictionary);
|
||||||
imagePromises.push(promise);
|
|
||||||
image_count++;
|
image_count++;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
21
style.css
21
style.css
|
@ -151,6 +151,27 @@ a {
|
||||||
color: transparent;
|
color: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.profile-container {
|
||||||
|
display:flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profileimg {
|
||||||
|
flex: 0 0 20%; /* 10% of the container's width, not flexible, not growing, not shrinking */
|
||||||
|
max-height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profileimg img {
|
||||||
|
width: 100%; /* Make sure the image fills its container */
|
||||||
|
height: auto; /* Maintain aspect ratio */
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.profile {
|
||||||
|
flex: 1; /* Take up remaining space */
|
||||||
|
padding-left: 1rem; /* Add some space between image and text */
|
||||||
|
}
|
||||||
|
|
||||||
#close-button {
|
#close-button {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
font-size: 3rem;
|
font-size: 3rem;
|
||||||
|
|
Loading…
Reference in New Issue