Compare commits

...

6 Commits

  1. 2
      ozgursozluk/__init__.py
  2. 4
      ozgursozluk/configs.py
  3. 1
      ozgursozluk/models.py
  4. 18
      ozgursozluk/scraper.py
  5. 2
      ozgursozluk/static/style.css
  6. 9
      ozgursozluk/utils.py
  7. 12
      ozgursozluk/views.py
  8. 2
      pyproject.toml
  9. 2
      tests.py

@ -3,7 +3,7 @@ from flask import Flask
from ozgursozluk.configs import SECRET_KEY
__version__ = "0.7.4"
__version__ = "0.7.5"
__source_code__ = "https://github.com/beucismis/ozgursozluk"
__description__ = "a free and open source alternative ekşi sözlük front-end"

@ -3,7 +3,9 @@ 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://eksisozluk1923.com"
)
DEFAULT_THEME: Final = "light"
DEFAULT_DISPLAY_PINNED_TOPICS: Final = "true"

@ -54,6 +54,7 @@ class Debe:
id: int
title: str
@dataclass
class SearchResult:
title: str

@ -24,7 +24,9 @@ class EksiSozluk:
"""Make a request."""
response = self.session.request(
method, f"{self.base_url}{path}", params=params,
method,
f"{self.base_url}{path}",
params=params,
)
if response.status_code != 200:
@ -33,7 +35,7 @@ class EksiSozluk:
return BeautifulSoup(response.content, "html.parser")
def entrys(self, response: BeautifulSoup) -> Iterator[Entry]:
"""Get entrys for the given topic."""
"""Get entrys with given topic."""
entry_items = response.find_all("li", id="entry-item")
@ -48,7 +50,7 @@ class EksiSozluk:
)
def search_topic(self, keywords: str) -> Iterator[SearchResult]:
"""Search topic for the given keywords."""
"""Return titles that match the query parameters."""
payload = {
"SearchForm.Keywords": keywords,
@ -66,7 +68,7 @@ class EksiSozluk:
)
def get_topic(self, path: str, page: int = 1, a: Optional[str] = None) -> Topic:
"""Get topic for the given path."""
"""Get topic with given path."""
if a is None:
response = self.request("GET", f"/{path}", {"p": page})
@ -86,7 +88,7 @@ class EksiSozluk:
)
def get_entry(self, id: int) -> EntryTopic:
"""Get entry for the given ID."""
"""Get entry with given ID."""
response = self.request("GET", f"/entry/{id}")
h1 = response.find("h1", id="title")
@ -105,7 +107,7 @@ class EksiSozluk:
)
def get_author(self, nickname: str) -> Author:
"""Get author for the give nickname."""
"""Get author with given nickname."""
response = self.request("GET", f"/biri/{nickname}")
muted = response.find("p", class_="muted")
@ -124,7 +126,7 @@ class EksiSozluk:
def get_gundem(self, page: int = 1) -> Iterator[Gundem]:
"""
Get gündem page.
Return latest news titles.
https://eksisozluk.com/basliklar/gundem
"""
@ -141,7 +143,7 @@ class EksiSozluk:
def get_debe(self) -> Iterator[Debe]:
"""
Get debe page.
Return highly rated titles from yesterday.
https://eksisozluk.com/debe
"""

@ -119,9 +119,9 @@ form input, form select, form button {
}
.entry_wrapper {
gap: 1rem;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 0.5rem;
}
.entry_wrapper .entry {

@ -12,9 +12,7 @@ def expires() -> datetime:
def last_commit() -> str:
"""Return the last commit ID."""
request = requests.get(
"https://api.github.com/repos/beucismis/ozgursozluk/commits"
)
request = requests.get("https://api.github.com/repos/beucismis/ozgursozluk/commits")
return request.json()[0]["sha"]
@ -27,4 +25,7 @@ def contributors() -> list:
)
for contributor in request.json():
yield {"username": contributor["login"], "total-commit": contributor["contributions"]}
yield {
"username": contributor["login"],
"total-commit": contributor["contributions"],
}

@ -3,7 +3,7 @@ from random import randint
from flask import url_for, redirect, request, render_template
import ozgursozluk
from ozgursozluk.api import EksiSozluk
from ozgursozluk.scraper import EksiSozluk
from ozgursozluk.utils import last_commit, expires, contributors
from ozgursozluk.configs import THEMES, DEFAULT_COOKIES
@ -88,12 +88,16 @@ def search():
@ozgursozluk.app.route("/random")
def random():
return redirect(url_for("entry", id=randint(1, 300_000_000)))
"""Random entry route."""
return redirect(url_for("entry", id=randint(1, 300_000_000)))
@ozgursozluk.app.route("/donate")
def donate():
return render_template("donate.html")
"""Donate route."""
return render_template("donate.html")
@ozgursozluk.app.route("/settings", methods=["GET", "POST"])
@ -120,6 +124,6 @@ def settings():
@ozgursozluk.app.errorhandler(404)
def page_not_found(error):
"""Error handler."""
"""Error handler route."""
return render_template("404.html"), 404

@ -6,7 +6,6 @@ build-backend = "setuptools.build_meta"
name = "ozgursozluk"
authors = [{name = "beucismis", email = "beucismis@tutamail.com"}]
description = "A free and open source alternative ekşi sözlük front-end"
readme = "README.md"
requires-python = ">=3.8"
keywords = [
"alternative", "flask", "front-end", "eksisozluk", "self-hosted",
@ -21,6 +20,7 @@ classifiers = [
dynamic = ["version", "dependencies"]
[tool.poetry]
readme = "README.md"
include = ["ozgursozluk/static/*", "ozgursozluk/templates/*"]
[tool.setuptools.dynamic]

@ -1,6 +1,6 @@
import unittest
from ozgursozluk.api import EksiSozluk
from ozgursozluk.scraper import EksiSozluk
es = EksiSozluk()

Loading…
Cancel
Save