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 = 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)
)

View File

@ -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;
}

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;
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', {

View File

@ -14,12 +14,12 @@
</header>
<main>
{% 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">
{% 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 %}
<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 class="header">
{% if post.subject %}
@ -29,7 +29,7 @@
{% if post.tripcode %}
<span class="tripcode">{{ post.tripcode }}</span>
{% 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>
{% if backlinks.get(post.id) %}
<span class="backlinks">

View File

@ -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
);