fourth commit

This commit is contained in:
iou1name 2019-12-17 18:46:54 -05:00
parent 7f025abd5b
commit 715fc2af8e
5 changed files with 45 additions and 27 deletions

View File

@ -60,14 +60,12 @@ def scrape_posts(root_dir):
post_time = int(post.find(class_='dateTime').get('data-utc')) post_time = int(post.find(class_='dateTime').get('data-utc'))
post_time = datetime.datetime.utcfromtimestamp(post_time) post_time = datetime.datetime.utcfromtimestamp(post_time)
post_time = post_time.replace(tzinfo=datetime.timezone.utc) post_time = post_time.replace(tzinfo=datetime.timezone.utc)
file_url = None chan_file_name = None
file_name = None file_name = None
file_md5 = None
file_text = post.find(class_='fileText') file_text = post.find(class_='fileText')
if file_text: if file_text:
file_url = file_text.a.get('href') chan_file_name =file_text.a.get('href').rpartition('/')[2]
file_name = file_text.a.text original_file_name = file_text.a.text
file_md5 =post.find(class_='fileThumb').img.get('data-md5')
post_body = post.find(class_='postMessage').get_text('\n') post_body = post.find(class_='postMessage').get_text('\n')
links = post.find_all(class_='quotelink') links = post.find_all(class_='quotelink')
@ -95,19 +93,26 @@ def scrape_posts(root_dir):
# dropped trip doesn't necessarily mean story_post # dropped trip doesn't necessarily mean story_post
tags.append('dropped_trip') tags.append('dropped_trip')
if len(links) > 1: if len(links) > 1:
tags.append('vote_tally_post') tags.append('tally_post')
# also counts Q&A posts # also counts Q&A posts
try: if 'story_post' in tags:
tags.remove('story_post') tags.remove('story_post')
except ValueError:
pass
if posts.index(post) == 0: if posts.index(post) == 0:
tags.append('op_post') tags.append('op_post')
if "Welcome to Banished Quest!" in post_body: if "Welcome to Banished Quest!" in post_body:
try: if 'story_post' in tags:
tags.remove('story_post') tags.remove('story_post')
except ValueError: if re.search(r'ro+l+ me', post_body.lower()):
pass 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 # database insert
cur.execute( cur.execute(
@ -125,7 +130,7 @@ def scrape_posts(root_dir):
) )
if file_text: if file_text:
cur.execute("INSERT INTO file VALUES (%s,%s,%s)", cur.execute("INSERT INTO file VALUES (%s,%s,%s)",
(file_url, file_name, file_md5) (post_id, chan_file_name, original_file_name)
) )

View File

@ -18,6 +18,16 @@ body {
font-size: 0.8em; font-size: 0.8em;
} }
.tag_button {
color: blue;
font-size: 1em;
}
.tag_button:hover {
color: red;
cursor: pointer;
}
.header { .header {
margin-bottom: 0.5em; margin-bottom: 0.5em;
} }

View File

@ -1,4 +1,5 @@
function add_tag(input) { function add_tag(event) {
input = event.target.closest('.tag');
post_id = input.closest('.post_container').id; post_id = input.closest('.post_container').id;
tag_name = input.children[0].value; tag_name = input.children[0].value;
fetch(url_prefix + '/add_tag', { fetch(url_prefix + '/add_tag', {
@ -16,16 +17,18 @@ function add_tag(input) {
let tag = document.createElement('span'); let tag = document.createElement('span');
tag.innerText = tag_name; tag.innerText = tag_name;
tag.className = 'tag'; tag.className = 'tag';
let anchor = document.createElement('a'); let span = document.createElement('span');
anchor.href = "javascript:void(0)"; span.className = 'tag_button';
anchor.setAttribute('onlick', "remove_tag(this.closest('.tag'))"); span.addEventListener('click', remove_tag);
anchor.innerText = '-'; span.innerText = '-';
tag.appendChild(anchor); tag.appendChild(span);
input.closest('.tags').insertBefore(tag, input); 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; post_id = tag.closest('.post_container').id;
tag_name = tag.innerText.replace(/ .*/, ''); tag_name = tag.innerText.replace(/ .*/, '');
fetch(url_prefix + '/remove_tag', { fetch(url_prefix + '/remove_tag', {

View File

@ -14,12 +14,12 @@
</header> </header>
<main> <main>
{% for post in posts %} {% for post in posts %}
<div id="{{ post.id }}" class="post_container{% if tags[post.id] %} {{ ' '.join(tags[post.id]) }}{% endif %}{% if 'story_post' not in tags[post.id] %} faded{% endif %}"> <div id="{{ post.id }}" class="post_container{% if tags[post.id] %} {{ ' '.join(tags[post.id]) }}{% endif %}{% if 'qm_post' not in tags[post.id] %} faded{% endif %}">
<div class="tags"> <div class="tags">
{% for tag in tags.get(post.id, []) %} {% for tag in tags.get(post.id, []) %}
<span class="tag">{{ tag }} <a href="javascript:void(0)" onclick="remove_tag(this.closest('.tag'))">-</a></span> <span class="tag">{{ tag }} <span class="tag_button" onclick="remove_tag(event)">-</span></span>
{% endfor %} {% endfor %}
<span class="tag"><input type="text"><a href="javascript:void(0)" onclick="add_tag(this.closest('.tag'))">+</a></span> <span class="tag"><input type="text"><span class="tag_button" onclick="add_tag(event)">+</span></span>
</div> </div>
<div class="header"> <div class="header">
{% if post.subject %} {% if post.subject %}
@ -29,7 +29,7 @@
{% if post.tripcode %} {% if post.tripcode %}
<span class="tripcode">{{ post.tripcode }}</span> <span class="tripcode">{{ post.tripcode }}</span>
{% endif %} {% endif %}
<span class="time">{{ post.time.strftime('%Y-%m-%d %H:%M') }}</span> <span class="time">{{ post.time.astimezone().strftime('%Y-%m-%d %H:%M') }}</span>
<span class="id">No.{{ post.id }}</span> <span class="id">No.{{ post.id }}</span>
{% if backlinks.get(post.id) %} {% if backlinks.get(post.id) %}
<span class="backlinks"> <span class="backlinks">

View File

@ -27,7 +27,7 @@ CREATE TABLE IF NOT EXISTS tag (
); );
CREATE TABLE IF NOT EXISTS file ( CREATE TABLE IF NOT EXISTS file (
file_url TEXT, post_id INTEGER REFERENCES post(id) ON DELETE CASCADE NOT NULL,
file_name TEXT, chan_file_name TEXT,
file_md5 TEXT original_file_name TEXT
); );