Compare commits
No commits in common. "c95a3c27e5e1d126059b3c086a4946b6aed644c4" and "50de741ec4254cbe48b8bdddc9d2a0dec777ef3e" have entirely different histories.
c95a3c27e5
...
50de741ec4
|
@ -1,5 +1,5 @@
|
||||||
cd /home/gamerdonkey/code/wiki-mad-libs/batch
|
cd /home/gamerdonkey/code/wiki-mad-libs/batch
|
||||||
. ../wiki-mad-libs-env/bin/activate
|
source ../wiki-mad-libs-env/bin/activate
|
||||||
python process_wiki_article.py
|
python process_wiki_article.py
|
||||||
cp article.js ./archive/$(date +%Y%m%dT%H%M%S).js
|
cp article.js ./archive/$(date +%Y%m%dT%H%M%S).js
|
||||||
mv article.js /home/gamerdonkey/public_html/waki-libs/
|
mv article.js /home/gamerdonkey/public_html/waki-libs/
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import hashlib
|
|
||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
@ -97,9 +96,7 @@ def adlibify(wiki_page, min_adlib_rest):
|
||||||
output_tokens.append(output_token)
|
output_tokens.append(output_token)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
url = wiki_page.canonicalurl
|
article = {'title': wiki_page.displaytitle, 'url': wiki_page.canonicalurl}
|
||||||
url_hash = hashlib.sha1(url.encode('utf-8')).hexdigest()[:8]
|
|
||||||
article = {'title': wiki_page.displaytitle, 'url': url, 'hash': url_hash}
|
|
||||||
article['tokens'] = output_tokens
|
article['tokens'] = output_tokens
|
||||||
|
|
||||||
return article
|
return article
|
||||||
|
|
|
@ -5,20 +5,6 @@
|
||||||
<title>WAKI-LIBS</title>
|
<title>WAKI-LIBS</title>
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
#error {
|
|
||||||
display: none;
|
|
||||||
color: red;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
#error::before {
|
|
||||||
content: '>> ';
|
|
||||||
}
|
|
||||||
|
|
||||||
#error::after {
|
|
||||||
content: ' <<';
|
|
||||||
}
|
|
||||||
|
|
||||||
#inputs {
|
#inputs {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-flow: column wrap;
|
flex-flow: column wrap;
|
||||||
|
@ -30,11 +16,6 @@
|
||||||
margin: 0.5em;
|
margin: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#inputs p label {
|
|
||||||
display: inline-block;
|
|
||||||
width: 10em;
|
|
||||||
}
|
|
||||||
|
|
||||||
#inputs p input {
|
#inputs p input {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +47,7 @@ button {
|
||||||
margin-right: 0.3em;
|
margin-right: 0.3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#article .link {
|
#article #link {
|
||||||
font-size: 10pt;
|
font-size: 10pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,15 +60,13 @@ button {
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>WAKI-LIBS: Wikipedia Ad-Libbed</h1>
|
<h1>WAKI-LIBS: Wikipedia Ad-Libbed</h1>
|
||||||
<div id="error"></div>
|
<div id="inputs"></div>
|
||||||
<div id="inputs"></div>
|
|
||||||
<p><button id="show-article">WAKI-LIB!</button>
|
<p><button id="show-article">WAKI-LIB!</button>
|
||||||
<div id="article">
|
<div id="article">
|
||||||
<div id="header">
|
<div id="header">
|
||||||
<span id="title"></span>
|
<span id="title"></span>
|
||||||
<span class="link">[ <a id="original-article-link" href="#">Original Article</a> ]</span>
|
<span id="link"></span>
|
||||||
<span class="link">[ <a id="sharable-link" href="#">Share your WAKI-LIBS!</a> ]</span>
|
|
||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<div id="summary"></div>
|
<div id="summary"></div>
|
||||||
|
|
|
@ -4,57 +4,15 @@ function createInputs(article) {
|
||||||
if(token.adlib_tag) {
|
if(token.adlib_tag) {
|
||||||
inputs += `
|
inputs += `
|
||||||
<p>
|
<p>
|
||||||
<label for="token-${token.id}">${token.adlib_tag}</label>
|
<label for="token_${token.id}">${token.adlib_tag}</label>
|
||||||
<input type="text" id="token-${token.id}" class="token-input" name="token-${token.id}">
|
<input type="text" id="token_${token.id}" name="token_${token.id}">
|
||||||
</p>
|
</p>
|
||||||
`
|
`
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
document.getElementById('inputs').innerHTML = inputs
|
document.getElementById('inputs').innerHTML = inputs
|
||||||
|
|
||||||
const urlParams = new URL(window.location.toLocaleString()).searchParams
|
|
||||||
if(urlParams.has('stored')) {
|
|
||||||
try {
|
|
||||||
let storedInputs = JSON.parse(atob(urlParams.get('stored')))
|
|
||||||
|
|
||||||
if(storedInputs.h !== article.hash) {
|
|
||||||
showError("Unable to use shared link because it's for an old article, and well, time makes fools of us all.")
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
document.querySelectorAll('.token-input').forEach(function(tokenInput) {
|
|
||||||
let index = tokenInput.id.split('-')[1]
|
|
||||||
tokenInput.value = storedInputs.i[index]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(err) {
|
|
||||||
showError("Unable to parse shared link.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function showError(errorMessage) {
|
|
||||||
errorDiv = document.getElementById('error')
|
|
||||||
errorDiv.innerHTML = errorMessage;
|
|
||||||
errorDiv.style.display = 'block'
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function makeSharableLink(article) {
|
|
||||||
let userInputs = {}
|
|
||||||
document.querySelectorAll('.token-input').forEach(function(tokenInput) {
|
|
||||||
let index = tokenInput.id.split('-')[1]
|
|
||||||
userInputs[index] = tokenInput.value
|
|
||||||
});
|
|
||||||
|
|
||||||
let storedInputs = {h: article.hash, i: userInputs}
|
|
||||||
let url = new URL(window.location.toLocaleString())
|
|
||||||
url.searchParams.set('stored', btoa(JSON.stringify(storedInputs)))
|
|
||||||
return(url.toLocaleString())
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function showArticle(article) {
|
function showArticle(article) {
|
||||||
const noSpaceBeforeTags = new Set(['.', ',', ')', ';', ':', '!', '?', "''", 'POS'])
|
const noSpaceBeforeTags = new Set(['.', ',', ')', ';', ':', '!', '?', "''", 'POS'])
|
||||||
const noSpaceBeforeTokens = new Set(["n't", ']'])
|
const noSpaceBeforeTokens = new Set(["n't", ']'])
|
||||||
|
@ -62,7 +20,7 @@ function showArticle(article) {
|
||||||
const noSpaceAfterTokens = new Set(['['])
|
const noSpaceAfterTokens = new Set(['['])
|
||||||
|
|
||||||
document.getElementById('title').innerHTML = article.title
|
document.getElementById('title').innerHTML = article.title
|
||||||
document.getElementById('original-article-link').href = article.url
|
document.getElementById('link').innerHTML = `[ <a href='${article.url}'>Original Article</a> ]`
|
||||||
|
|
||||||
let output = ''
|
let output = ''
|
||||||
let spaceBefore = false
|
let spaceBefore = false
|
||||||
|
@ -72,7 +30,7 @@ function showArticle(article) {
|
||||||
}
|
}
|
||||||
spaceBefore = true
|
spaceBefore = true
|
||||||
|
|
||||||
let adlibInput = document.getElementById(`token-${token.id}`);
|
let adlibInput = document.getElementById(`token_${token.id}`);
|
||||||
if(adlibInput && adlibInput.value) {
|
if(adlibInput && adlibInput.value) {
|
||||||
output += `<strong>${adlibInput.value}</strong>`
|
output += `<strong>${adlibInput.value}</strong>`
|
||||||
}
|
}
|
||||||
|
@ -86,12 +44,10 @@ function showArticle(article) {
|
||||||
})
|
})
|
||||||
|
|
||||||
document.getElementById('summary').innerHTML = output
|
document.getElementById('summary').innerHTML = output
|
||||||
document.getElementById('sharable-link').href = makeSharableLink(article)
|
|
||||||
|
|
||||||
document.getElementById('article').classList.add('visible')
|
document.getElementById('article').classList.add('visible')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
createInputs(article)
|
createInputs(article)
|
||||||
|
|
||||||
document.addEventListener('click', function (event) {
|
document.addEventListener('click', function (event) {
|
||||||
|
|
Loading…
Reference in New Issue