From 715fc2af8e1938ba011ba54e8b12a83ffe78a325 Mon Sep 17 00:00:00 2001 From: iou1name Date: Tue, 17 Dec 2019 18:46:54 -0500 Subject: [PATCH] fourth commit --- scrape_quest.py | 31 ++++++++++++++++++------------- static/voyage.css | 10 ++++++++++ static/voyage.js | 17 ++++++++++------- templates/thread.html | 8 ++++---- voyage.sql | 6 +++--- 5 files changed, 45 insertions(+), 27 deletions(-) diff --git a/scrape_quest.py b/scrape_quest.py index 7ec9113..06a03fc 100644 --- a/scrape_quest.py +++ b/scrape_quest.py @@ -60,14 +60,12 @@ def scrape_posts(root_dir): post_time = int(post.find(class_='dateTime').get('data-utc')) post_time = datetime.datetime.utcfromtimestamp(post_time) post_time = post_time.replace(tzinfo=datetime.timezone.utc) - file_url = None + chan_file_name = None file_name = None - file_md5 = None file_text = post.find(class_='fileText') if file_text: - file_url = file_text.a.get('href') - file_name = file_text.a.text - file_md5 =post.find(class_='fileThumb').img.get('data-md5') + chan_file_name =file_text.a.get('href').rpartition('/')[2] + original_file_name = file_text.a.text post_body = post.find(class_='postMessage').get_text('\n') links = post.find_all(class_='quotelink') @@ -95,19 +93,26 @@ def scrape_posts(root_dir): # dropped trip doesn't necessarily mean story_post tags.append('dropped_trip') if len(links) > 1: - tags.append('vote_tally_post') + tags.append('tally_post') # also counts Q&A posts - try: + if 'story_post' in tags: tags.remove('story_post') - except ValueError: - pass if posts.index(post) == 0: tags.append('op_post') if "Welcome to Banished Quest!" in post_body: - try: + if 'story_post' in tags: tags.remove('story_post') - except ValueError: - pass + if re.search(r'ro+l+ me', post_body.lower()): + tags.append('dice_call') + if 'story_post' in tags: + tags.remove('story_post') + if 'final destination' in post_body.lower(): + tags.append('final_destination') + if 'story_post' in tags: + tags.remove('story_post') + if 'story_post' in tags: + if len(re.findall(r'\n>', post_body)) > 1: + tags.append('vote_choices') # database insert cur.execute( @@ -125,7 +130,7 @@ def scrape_posts(root_dir): ) if file_text: cur.execute("INSERT INTO file VALUES (%s,%s,%s)", - (file_url, file_name, file_md5) + (post_id, chan_file_name, original_file_name) ) diff --git a/static/voyage.css b/static/voyage.css index b2bd219..a83c800 100644 --- a/static/voyage.css +++ b/static/voyage.css @@ -18,6 +18,16 @@ body { font-size: 0.8em; } +.tag_button { + color: blue; + font-size: 1em; +} + +.tag_button:hover { + color: red; + cursor: pointer; +} + .header { margin-bottom: 0.5em; } diff --git a/static/voyage.js b/static/voyage.js index 8c462e2..fd7125a 100644 --- a/static/voyage.js +++ b/static/voyage.js @@ -1,4 +1,5 @@ -function add_tag(input) { +function add_tag(event) { + input = event.target.closest('.tag'); post_id = input.closest('.post_container').id; tag_name = input.children[0].value; fetch(url_prefix + '/add_tag', { @@ -16,16 +17,18 @@ function add_tag(input) { 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); + let span = document.createElement('span'); + span.className = 'tag_button'; + span.addEventListener('click', remove_tag); + span.innerText = '-'; + tag.appendChild(span); input.closest('.tags').insertBefore(tag, input); }); } -function remove_tag(tag) { +function remove_tag(event) { + console.log(event); + tag = event.target.closest('.tag'); post_id = tag.closest('.post_container').id; tag_name = tag.innerText.replace(/ .*/, ''); fetch(url_prefix + '/remove_tag', { diff --git a/templates/thread.html b/templates/thread.html index e260464..8b506f7 100644 --- a/templates/thread.html +++ b/templates/thread.html @@ -14,12 +14,12 @@
{% for post in posts %} -
+
{% for tag in tags.get(post.id, []) %} - {{ tag }} - + {{ tag }} - {% endfor %} - + + +
{% if post.subject %} @@ -29,7 +29,7 @@ {% if post.tripcode %} {{ post.tripcode }} {% endif %} - {{ post.time.strftime('%Y-%m-%d %H:%M') }} + {{ post.time.astimezone().strftime('%Y-%m-%d %H:%M') }} No.{{ post.id }} {% if backlinks.get(post.id) %} diff --git a/voyage.sql b/voyage.sql index 9db64f5..e36ec8a 100644 --- a/voyage.sql +++ b/voyage.sql @@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS tag ( ); CREATE TABLE IF NOT EXISTS file ( - file_url TEXT, - file_name TEXT, - file_md5 TEXT + post_id INTEGER REFERENCES post(id) ON DELETE CASCADE NOT NULL, + chan_file_name TEXT, + original_file_name TEXT );