Skip to content

Commit

Permalink
Further 2.0 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
OperaVaria committed Mar 26, 2024
1 parent 7606668 commit 78402b2
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install Flask Flask-Minify flask-talisman PyYAML requests
pip install pylint Flask Flask-Minify flask-talisman PyYAML requests
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py' '*.pyw')
20 changes: 11 additions & 9 deletions collect_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ def scrape(animal_name, query, subreddits, keys):
"""Call collecting functions and assemble pickle file form retuned lists."""
# Reddit
reddit_list = reddit_collect(subreddits, keys)
# "Sand cat" results are problematic, therefore skip most sites.
# Pexels
pexels_list = pexels_collect(query, keys)
# Pixabay
pixabay_list = pixabay_collect(query, keys)
# Unsplash
unsplash_list = unsplash_collect(query, keys)
# Join lists.
# Sand cat and manul results are problematic, therefore skip sites.
if animal_name == "sand_cat":
post_list = reddit_list
elif animal_name == "manul":
post_list = reddit_list + pixabay_list + unsplash_list
else:
# Pexels
pexels_list = pexels_collect(query, keys)
# Pixabay
pixabay_list = pixabay_collect(query, keys)
# Unsplash
unsplash_list = unsplash_collect(query, keys)
# Join lists.
post_list = reddit_list + pexels_list + pixabay_list + unsplash_list
# Pickle data.
pfile_path = Path(__file__).parents[0].resolve() / f"data/{animal_name}_data.p"
Expand All @@ -53,7 +55,7 @@ def main():
# Collect hedgehog content.
scrape("hedgehog", "hedgehog", "Hedgehog+Hedgehogs+HedgehogsAreLiquid", keys)
# Collect manul content.
scrape("manul", "'pallas's cat' manul", "PallasCats+manuls", keys)
scrape("manul", "manul", "PallasCats+manuls", keys)
# Collect sand cat content.
scrape("sand_cat","'sand cat'", "sandcats", keys)
# Print final message.
Expand Down
5 changes: 3 additions & 2 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
"connect-src": ["'self'"],
"script-src": [
"'self'",
# Add hashes.
"'sha256-/Nhp/0Mc72DYgT/sMpiOn5EDx8z4guopcViJmqvMUy0='",
"https://gc.kis.v2.scr.kaspersky-labs.com",
],
"style-src": ["'self'"],
"img-src": ["'self'"],
"img-src": ["*"],
"font-src": ["'self'"],
"object-src": ["'none'"],
"base-uri": ["'none'"],
"form-action": ["'self'"],
Expand Down
4 changes: 2 additions & 2 deletions scraping/pixabay_scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def pixabay_collect(query, keys):
pixab_list = []
# Scrape response, create Post objects, append to list.
for hit in res_json_data["hits"]:
hit = Post(f"Pixabay image (id: {hit["id"]})",
hit = Post(f"Pixabay image (id: {hit['id']})",
"Pixabay", hit["user"], "https://pixabay.com/",
f"https://pixabay.com/users/{hit["user"]}-{hit["user_id"]}/",
f"https://pixabay.com/users/{hit['user']}-{hit['user_id']}/",
hit["pageURL"], hit["largeImageURL"])
pixab_list.append(hit)
# Return list.
Expand Down
2 changes: 1 addition & 1 deletion scraping/post_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@dataclass(frozen=True)
class Post:
"""Class to store data for a singe image post in a standardized way."""
title: str = "No title"
title: str
source: str
author: str
src_url: str
Expand Down
26 changes: 25 additions & 1 deletion static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ img.icon:hover {
opacity: 0.5;
}


/* Clickable */

.clickable-pic {
cursor: pointer;
opacity: 0.6;
Expand All @@ -135,6 +135,30 @@ img.icon:hover {
opacity: 1;
}

.custom-link:link {
background-color: transparent;
color: #b6b8bc;
text-decoration: none;
}

.custom-link:visited {
color: #b6b8bc;
background-color: transparent;
text-decoration: none;
}

.custom-link:hover {
background-color: transparent;
color: #b6b8bc;
text-decoration: underline;
}

.custom-link:active {
color: #b6b8bc;
background-color: transparent;
text-decoration: underline;
}

/* Other */

.underl {
Expand Down
9 changes: 5 additions & 4 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
<hr class="ln-bottom">
<!-- Footer, part of body, on every page. -->
<footer>
<p>&copy; OperaVaria, {{current_year}}</span>
<p>Version - {{version}}</p>
</p>Contact: <a href="mailto:lcs_it@proton.me">lcs_it@proton.me</a></p>
<p role="none">&copy; OperaVaria, {{current_year}}</p>
<p role="none">Version - {{version}}</p>
<p role="none">Contact: <a class="custom-link"
href="mailto:lcs_it@proton.me">lcs_it@proton.me</a></p>
<img id="github-btn" class="icon" src="{{ url_for('static', filename='img/github.svg') }}"
alt="Link button to source code"></img>
alt="Link button to source code"></img>
</footer>
<!-- Javascript file. -->
<script src="{{ url_for('static', filename='js/script.js') }}"></script>
Expand Down
10 changes: 5 additions & 5 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="title" role="none">
<h1>Instant Serotonin</h1>
</div>
<hr class="ln-top">
<hr class="ln-top" role="none">
<div class="subtitle" role="none">
<h2>Choose your source</h2>
</div>
Expand All @@ -15,7 +15,7 @@ <h2>Choose your source</h2>
<h3 id="capybara-title">Capybara</h3>
<a href="{{ url_for('result', animal='capybara') }}">
<img
class="normal clickable_pic"
class="normal clickable-pic"
src="{{ url_for('static', filename='img/base_capybara.jpg') }}"
alt="Get random capybara picture"
/>
Expand All @@ -26,7 +26,7 @@ <h3 id="capybara-title">Capybara</h3>
<h3 id="manul-title">Manul</h3>
<a href="{{ url_for('result', animal='manul') }}">
<img
class="normal clickable_pic"
class="normal clickable-pic"
src="{{ url_for('static', filename='img/base_manul.jpg') }}"
alt="Get random capybara picture"
/>
Expand All @@ -37,7 +37,7 @@ <h3 id="manul-title">Manul</h3>
<h3 id="sand-cat-title">Sand Cat</h3>
<a href="{{ url_for('result', animal='sand_cat') }}">
<img
class="normal clickable_pic"
class="normal clickable-pic"
src="{{ url_for('static', filename='img/base_sand_cat.jpg') }}"
alt="Get random capybara picture"
/>
Expand All @@ -48,7 +48,7 @@ <h3 id="sand-cat-title">Sand Cat</h3>
<h3 id="hedgehog-title">Hedgehog</h3>
<a href="{{ url_for('result', animal='hedgehog') }}">
<img
class="normal clickable_pic"
class="normal clickable-pic"
src="{{ url_for('static', filename='img/base_hedgehog.jpg') }}"
alt="Get random capybara picture"
/>
Expand Down
20 changes: 14 additions & 6 deletions templates/result.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<!-- Result page -->
{% extends "base.html" %}
{% block body %}
{% if post.title is none %}
{% set img_title = "Untitled" %}
{% else %}
{% set img_title = post.title %}
{% endif %}
<main class="container">
<!-- Page title. -->
<div class="title" role="none">
Expand All @@ -9,16 +14,19 @@ <h1>Random {{title_var}}</h1>
<!-- Picture with image title under it. -->
<section class="subtitle" title="Random image result">
<img class="normal" src="{{post.img_url}}" alt="Random {{title_var}} image">
<h2 title="Image title">{{post.title}}</h2>
<h2 title="Image title">"{{img_title}}"</h2>
</section>
<!-- Source data. -->
<section class="item full-wide" title="Result details">
<h3>
Form: <a href="{{post.src_url}}" target="_blank">{{post.source}}</a>
<br>
Uploaded by: <a href="{{post.auth_url}}" target="_blank">{{post.author}}</a>
<br>
<a href="{{post.post_url}}" target="_blank">Link to original</a>
Form: <a class="custom-link" href="{{post.src_url}}"
target="_blank" title="Source website">{{post.source}}</a>
<br role="none">
Uploaded by: <a class="custom-link" href="{{post.auth_url}}"
target="_blank" title="Uploader profile">{{post.author}}</a>
<br role="none">
<a class="custom-link" href="{{post.post_url}}"
target="_blank" title="Original post">Link to original</a>
</h3>
</section>
<!-- New and Back buttons. -->
Expand Down

0 comments on commit 78402b2

Please sign in to comment.