From 34b512e3f212c06f0996f442091172f7bcb06b4f Mon Sep 17 00:00:00 2001 From: beucismis Date: Wed, 6 Mar 2024 16:23:15 +0300 Subject: [PATCH] General fixes --- ozgursozluk/__init__.py | 2 +- ozgursozluk/configs.py | 4 +--- ozgursozluk/scraper.py | 7 ++++++- ozgursozluk/templates/author.html | 4 +--- ozgursozluk/templates/donate.html | 19 +++++++------------ ozgursozluk/templates/macros.html | 8 +++++++- ozgursozluk/templates/settings.html | 22 ++++++++++------------ ozgursozluk/utils.py | 18 +++++------------- ozgursozluk/views.py | 3 +-- 9 files changed, 39 insertions(+), 48 deletions(-) diff --git a/ozgursozluk/__init__.py b/ozgursozluk/__init__.py index b54d571..72f2739 100644 --- a/ozgursozluk/__init__.py +++ b/ozgursozluk/__init__.py @@ -3,7 +3,7 @@ from flask import Flask from ozgursozluk.configs import SECRET_KEY -__version__ = "0.7.5" +__version__ = "0.8.0" __source_code__ = "https://github.com/beucismis/ozgursozluk" __description__ = "a free and open source alternative ekşi sözlük front-end" diff --git a/ozgursozluk/configs.py b/ozgursozluk/configs.py index e4f8b09..4766017 100644 --- a/ozgursozluk/configs.py +++ b/ozgursozluk/configs.py @@ -3,9 +3,7 @@ from typing import Final SECRET_KEY: Final = environ.get("OZGURSOZLUK_SECRET_KEY", "") -EKSI_SOZLUK_BASE_URL: Final = environ.get( - "EKSI_SOZLUK_BASE_URL", "https://eksisozluk1923.com" -) +EKSI_SOZLUK_BASE_URL: Final = environ.get("EKSI_SOZLUK_BASE_URL", "https://eksisozluk.com") DEFAULT_THEME: Final = "light" DEFAULT_DISPLAY_PINNED_TOPICS: Final = "true" diff --git a/ozgursozluk/scraper.py b/ozgursozluk/scraper.py index ee19a57..8fe51d8 100644 --- a/ozgursozluk/scraper.py +++ b/ozgursozluk/scraper.py @@ -58,6 +58,11 @@ class EksiSozluk: "SearchForm.SortOrder": "Count", } response = self.request("GET", "/basliklar/ara", payload) + total_topic = response.find("p", class_="topic-list-description") + + if not bool(int(total_topic.text.split(" ")[0])): + abort(404) + topic_list = response.find("ul", class_="topic-list").find_all("a", href=True) for topic in topic_list: @@ -152,6 +157,6 @@ class EksiSozluk: for topic in topic_list: yield Debe( - int(topic["href"].split("/")[-1]), + int(topic["href"].split("/")[-1].split("?")[0]), topic.find("span", class_="caption").text, ) diff --git a/ozgursozluk/templates/author.html b/ozgursozluk/templates/author.html index c7b460f..86212a9 100644 --- a/ozgursozluk/templates/author.html +++ b/ozgursozluk/templates/author.html @@ -21,9 +21,7 @@ - {{ author.user_following_count }} following

- - if available go author topic - + author topic {% if author.biography %} diff --git a/ozgursozluk/templates/donate.html b/ozgursozluk/templates/donate.html index 55d9458..a71a22b 100644 --- a/ozgursozluk/templates/donate.html +++ b/ozgursozluk/templates/donate.html @@ -5,19 +5,14 @@ {% endblock %} {% block main %} -
-

donate to the developer

+ {% endblock %} diff --git a/ozgursozluk/templates/macros.html b/ozgursozluk/templates/macros.html index 9f4dbab..a8d823c 100644 --- a/ozgursozluk/templates/macros.html +++ b/ozgursozluk/templates/macros.html @@ -1,7 +1,13 @@ {% macro render_entry(entry, clickable_date) %}
{{ entry.content_html|safe }} -
+ {% if + (request.cookies.get('display_entry_favorite_count') == 'true') or + (request.cookies.get('display_entry_author') == 'true') or + (request.cookies.get('display_entry_datetime') == 'true') + %} +
+ {% endif %}
{% if request.cookies.get('display_entry_favorite_count') == 'true' %} {{ entry.favorite_count }} favorites diff --git a/ozgursozluk/templates/settings.html b/ozgursozluk/templates/settings.html index 10d1f69..37cfcc4 100644 --- a/ozgursozluk/templates/settings.html +++ b/ozgursozluk/templates/settings.html @@ -62,26 +62,24 @@ {% endfor %}
-
+
-
- note: settings are saved in browser cookies, clearing your cookies will reset them. +
+ note: settings are saved in browser cookies, clearing your cookies will reset them. also this website does not have an official affiliation with eksisozluk.com.

- v{{ version }} + v{{ version }} - - last commit: - {{ last_commit[:8] }} + last commit(s): + {% if last_commit == None %} + go + {% else %} + {{ last_commit[:8] }} + {% endif %} - made with <3 on the t61 -

- contributors: - {% for contributor in contributors %} - {{ contributor['username'] }} - ({{ contributor['total-commit'] }}) - {% endfor %}
{% endblock %} diff --git a/ozgursozluk/utils.py b/ozgursozluk/utils.py index 15fc6ad..9320274 100644 --- a/ozgursozluk/utils.py +++ b/ozgursozluk/utils.py @@ -2,6 +2,8 @@ from datetime import datetime, timedelta import requests +import ozgursozluk + def expires() -> datetime: """One year later.""" @@ -14,18 +16,8 @@ def last_commit() -> str: request = requests.get("https://api.github.com/repos/beucismis/ozgursozluk/commits") + if request.status_code == 403: + return None + return request.json()[0]["sha"] - -def contributors() -> list: - """Get GitHub contributors.""" - - request = requests.get( - "https://api.github.com/repos/beucismis/ozgursozluk/contributors" - ) - - for contributor in request.json(): - yield { - "username": contributor["login"], - "total-commit": contributor["contributions"], - } diff --git a/ozgursozluk/views.py b/ozgursozluk/views.py index 9666f75..798df3d 100644 --- a/ozgursozluk/views.py +++ b/ozgursozluk/views.py @@ -4,7 +4,7 @@ from flask import url_for, redirect, request, render_template import ozgursozluk from ozgursozluk.scraper import EksiSozluk -from ozgursozluk.utils import last_commit, expires, contributors +from ozgursozluk.utils import last_commit, expires from ozgursozluk.configs import THEMES, DEFAULT_COOKIES @@ -18,7 +18,6 @@ def global_template_variables(): return dict( themes=THEMES, last_commit=last_commit(), - contributors=contributors(), version=ozgursozluk.__version__, source_code=ozgursozluk.__source_code__, description=ozgursozluk.__description__,