mirror of
https://github.com/kennethreitz/replit-py.git
synced 2026-06-05 23:10:18 +00:00
black, etc.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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?
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
+10
-8
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user