+ {{ line|quotelink(links[post.id]) }}
{% else %} - {{ line|quotelink(post) }}
+ {{ line|quotelink(links[post.id]) }}
{% endif %} {% endfor %}
diff --git a/filters.py b/filters.py index d6f1fbd..28fa91b 100644 --- a/filters.py +++ b/filters.py @@ -4,13 +4,13 @@ Jinja2 template filters. """ import re -from markupsafe import Markup +from markupsafe import Markup, escape -def quotelink(line, post): +def quotelink(line, post_links): """Checks if the quotelink is valid and adds an anchor tag if so.""" links = re.findall(r'>>(\d+)', line) for link in links: - if int(link) in post['link_tos']: + if int(link) in post_links: span = f'>>{link}' else: span = f'>>{link}' diff --git a/scrape_quest.py b/scrape_quest.py index 8b74937..7ec9113 100644 --- a/scrape_quest.py +++ b/scrape_quest.py @@ -51,9 +51,9 @@ def scrape_posts(root_dir): # information gathering post_id = int(post.get('id')[2:]) name = post.find(class_='name').text - trip_code = post.find(class_='postertrip') - if trip_code: - trip_code = trip_code.text + tripcode = post.find(class_='postertrip') + if tripcode: + tripcode = tripcode.text subject = post.find(class_='subject') if subject: subject = subject.text @@ -73,6 +73,7 @@ def scrape_posts(root_dir): links = post.find_all(class_='quotelink') links = [l for l in links if l.get('href').startswith('#')] links = [int(link.text[2:]) for link in links] + links = list(set(links)) # heuristics tags = [] @@ -110,9 +111,9 @@ def scrape_posts(root_dir): # database insert cur.execute( - "INSERT INTO post VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", - (thread_id, post_id, name, trip_code, subject, - post_time, file_url, file_name, file_md5, post_body) + "INSERT INTO post VALUES (%s,%s,%s,%s,%s,%s,%s)", + (thread_id, post_id, name, tripcode, subject, + post_time, post_body) ) for link in links: cur.execute("INSERT INTO link VALUES (%s,%s)", @@ -122,6 +123,10 @@ def scrape_posts(root_dir): cur.execute("INSERT INTO tag VALUES (%s,%s)", (post_id, tag) ) + if file_text: + cur.execute("INSERT INTO file VALUES (%s,%s,%s)", + (file_url, file_name, file_md5) + ) if __name__ == '__main__': diff --git a/static/voyage.css b/static/voyage.css index 3cc940a..b2bd219 100644 --- a/static/voyage.css +++ b/static/voyage.css @@ -10,6 +10,14 @@ body { padding: 0.5em; } +.faded { + opacity: 0.33; +} + +.tag { + font-size: 0.8em; +} + .header { margin-bottom: 0.5em; } diff --git a/static/voyage.js b/static/voyage.js index e69de29..8c462e2 100644 --- a/static/voyage.js +++ b/static/voyage.js @@ -0,0 +1,45 @@ +function add_tag(input) { + post_id = input.closest('.post_container').id; + tag_name = input.children[0].value; + fetch(url_prefix + '/add_tag', { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify({ + 'post_id': post_id, + 'tag_name': tag_name, + }) + }).then(function(response) { + if(!response.ok) { throw new Error('Error adding tag!'); } + return response.json(); + }).then(function(json) { + if (!json.ok) { throw new Error('Could not add tag.') } + let tag = document.createElement('span'); + tag.innerText = tag_name; + tag.className = 'tag'; + let anchor = document.createElement('a'); + anchor.href = "javascript:void(0)"; + anchor.setAttribute('onlick', "remove_tag(this.closest('.tag'))"); + anchor.innerText = '-'; + tag.appendChild(anchor); + input.closest('.tags').insertBefore(tag, input); + }); +} + +function remove_tag(tag) { + post_id = tag.closest('.post_container').id; + tag_name = tag.innerText.replace(/ .*/, ''); + fetch(url_prefix + '/remove_tag', { + method: 'POST', + headers: {'Content-Type': 'application/json'}, + body: JSON.stringify({ + 'post_id': post_id, + 'tag_name': tag_name, + }) + }).then(function(response) { + if(!response.ok) { throw new Error('Error removing tag!'); } + return response.json(); + }).then(function(json) { + if (!json.ok) { throw new Error('Could not remove tag.') } + tag.remove(); + }); +} diff --git a/templates/thread.html b/templates/thread.html index d7d9528..e260464 100644 --- a/templates/thread.html +++ b/templates/thread.html @@ -3,6 +3,7 @@