Skip to content

Commit

Permalink
clean up text readability code
Browse files Browse the repository at this point in the history
Prepare for more complex readability computation
  • Loading branch information
vankesteren committed Dec 17, 2023
1 parent f3957ee commit 7651b36
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions ghrepo.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Module containing GitHubRepo data class and functions to perform api calls"""
from dataclasses import dataclass
from datetime import datetime
import re
from typing import Literal
from base64 import b64decode
from textstat import flesch_reading_ease as readability
import textstat
import httpx

Severity = Literal["ok", "low", "high"]
Criteria = tuple[str, Severity]


@dataclass
class GitHubRepo:
"""Class that contains all relevant info about a GitHub repository"""
Expand Down Expand Up @@ -107,8 +107,7 @@ async def from_api_response(cls, response: dict):
license=response["license"]["name"] if response["license"] else None,
updated=datetime.fromisoformat(response["updated_at"]),
readme=readme_txt,
# TODO: strip markdown before computing readability
readability=readability(readme_txt) if readme_txt is not None else None,
readability=compute_readability(readme_txt) if readme_txt is not None else None,
)


Expand All @@ -123,6 +122,10 @@ async def get_readme(full_name: str, token: str | None = None) -> str | None:
readme_b64 = readme_response.json().get("content")
return b64decode(readme_b64).decode()

def compute_readability(readme_txt: str):
"""Compute readability from readme markdown text."""
# TODO: strip markdown before computing readability
return textstat.textstat.flesch_reading_ease(readme_txt)

async def get_org_repos(org: str, token: str | None = None) -> list[GitHubRepo]:
"""Get all the public repos for an organisation."""
Expand Down

0 comments on commit 7651b36

Please sign in to comment.