diff --git a/TODO b/TODO index c3f04ce..2f464c0 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,2 @@ - - -- GraphQL changes on backend to formalize gathering profile information. +- DB: convience methods like nuke and a CLI to interact with it? +- User: GraphQL changes on backend to formalize gathering profile information. diff --git a/src/replit/__init__.py b/src/replit/__init__.py index 7fdf5ee..a0f7bf9 100644 --- a/src/replit/__init__.py +++ b/src/replit/__init__.py @@ -1,15 +1,11 @@ """The Replit Python module.""" -from . import web -from . import termutils from .audio import Audio from .database import db -from .users import ReplitUser +from .users import User # Backwards compatibility. from .termutils import clear audio = Audio() - -# TODO: DB convience methods like nuke and a CLI to interact with it? diff --git a/src/replit/audio/__init__.py b/src/replit/audio/__init__.py index 3d8e4b3..44b8d74 100644 --- a/src/replit/audio/__init__.py +++ b/src/replit/audio/__init__.py @@ -331,7 +331,11 @@ class Audio: LoopCount=loop_count, Volume=volume, Type=str(ReaderType.tone), - Args=RequestArgs(WaveType=wave_type, Pitch=pitch, Seconds=duration,), + Args=RequestArgs( + WaveType=wave_type, + Pitch=pitch, + Seconds=duration, + ), ) with open("/tmp/audio", "w") as f: diff --git a/src/replit/database/jsonkey.py b/src/replit/database/jsonkey.py index 9921889..ede2b80 100644 --- a/src/replit/database/jsonkey.py +++ b/src/replit/database/jsonkey.py @@ -84,7 +84,10 @@ class AsyncJSONKey: return await self._error("Invalid JSON data read", read) if not self._is_valid_type(data): - return await self._error(self._type_mismatch_msg(data), read,) + return await self._error( + self._type_mismatch_msg(data), + read, + ) return data async def _error(self, error: str, read: str) -> JSON_TYPE: @@ -209,7 +212,10 @@ class JSONKey(AsyncJSONKey): data = read if not self._is_valid_type(data): - return self._error(self._type_mismatch_msg(data), read,) + return self._error( + self._type_mismatch_msg(data), + read, + ) return data def _error(self, error: str, read: str) -> JSON_TYPE: diff --git a/src/replit/termutils.py b/src/replit/termutils.py index 4fd858b..dff767e 100644 --- a/src/replit/termutils.py +++ b/src/replit/termutils.py @@ -126,14 +126,16 @@ class Bit: self.bg = f"\033[48;5;{value}m" -attributes = { # use only repl.it supported ansi codes. Codes such as blink do not work. - "reset": 0, - "bold": 1, - "faint": 2, - "italic": 3, - "underline": 4, - "highlight": 7, -} +attributes = ( + { # use only repl.it supported ansi codes. Codes such as blink do not work. + "reset": 0, + "bold": 1, + "faint": 2, + "italic": 3, + "underline": 4, + "highlight": 7, + } +) class Attr: diff --git a/src/replit/users/users.py b/src/replit/users.py similarity index 76% rename from src/replit/users/users.py rename to src/replit/users.py index f1b0e9c..a9bdca9 100644 --- a/src/replit/users/users.py +++ b/src/replit/users.py @@ -4,42 +4,39 @@ from requests_html import HTMLSession http = HTTPSession() html_http = HTMLSession() +# TODO: provide a way to list repls. + class ReplitUser: def __init__(self): - # validate_username=False - # self.user_id = None self.username = None self.name = None self.bio = None self.avatar_url = None self.languages = None - # self.roles = None - - # @classmethod - # def from_user_id(_class, user_id): - # # TODO: find a way to reverse username from user_id (ask eng?) - # pass @classmethod def from_username(_class, username): + """Creates a new ReplitUser object from a given Repl.it profile name.""" # TODO: catch non-existient users. url = _class._replit_url_from_username(username) return _class.from_replit_profile_url(url) @classmethod def from_replit_profile_url(_class, url): - # https://repl.it/@kennethreitz42 + """Creates a new ReplitUser object from a given Repl.it profile URL.""" + + # Fetch the profile from the web, and encapsulate its HTML. r = html_http.get(url=url) html = r.html + # Instantiate the class. user = _class() + # Populate the user instance from parsed HTML. user.name = user.__extract_name(html) user.bio = user.__extract_bio(html) user.avatar_url = user.__extract_avatar_url(html) - # user.languages = user.__extract_languages(html) - # user.roles = user.__extract_roles(html) return user @@ -71,13 +68,7 @@ class ReplitUser: return avatar_url - # def __extract_languages(self, html): - # pass - - # def __extract_roles(self, html): - # pass - - # list repls - +# Syntax suagar. +User = ReplitUser print(ReplitUser.from_username("kennethreitz42").avatar_content) diff --git a/src/replit/web/app.py b/src/replit/web/app.py index 79e0a74..176fbbb 100644 --- a/src/replit/web/app.py +++ b/src/replit/web/app.py @@ -93,7 +93,11 @@ class ReplitApp(flask.Flask): self.jinja_env.trim_blocks = True self.jinja_env.lstrip_blocks = True - def login_wall(self, exclude: Set[str] = ("/",), handler: Callable = None,) -> None: + def login_wall( + self, + exclude: Set[str] = ("/",), + handler: Callable = None, + ) -> None: """Require users to be logged-in on all pages. Args: