-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored main branch #1
base: main
Are you sure you want to change the base?
Conversation
with open(path) as f: | ||
queries[path.stem] = f.read() | ||
queries[path.stem] = Path(path).read_text() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function load_queries
refactored with the following changes:
- Simplify basic file reads with
pathlib
(path-read
)
|
||
r = request_with_retries(self.session.get, self.home_url) | ||
json_regex = r'<script id="__NEXT_DATA__" type="application\/json">(.+?)</script>' | ||
json_text = re.search(json_regex, r.text).group(1) | ||
json_text = re.search(json_regex, r.text)[1] | ||
next_data = json.loads(json_text) | ||
|
||
self.formkey = next_data["props"]["formkey"] | ||
self.viewer = next_data["props"]["pageProps"]["payload"]["viewer"] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Client.get_next_data
refactored with the following changes:
- Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
)
if not "availableBots" in viewer: | ||
if "availableBots" not in viewer: | ||
raise RuntimeError("Invalid token.") | ||
bot_list = viewer["availableBots"] | ||
|
||
bots = {} | ||
for bot in bot_list: | ||
url = f'https://poe.com/_next/data/{self.next_data["buildId"]}/{bot["displayName"].lower()}.json' | ||
logger.info("Downloading "+url) | ||
logger.info(f"Downloading {url}") | ||
|
||
r = request_with_retries(self.session.get, url) | ||
|
||
chat_data = r.json()["pageProps"]["payload"]["chatOfBotDisplayName"] | ||
bots[chat_data["defaultBotObject"]["nickname"]] = chat_data | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Client.get_bots
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
return f'wss://{self.ws_domain}.tch.{channel["baseHost"]}/up/{channel["boxName"]}/updates'+query | ||
return f'wss://{self.ws_domain}.tch.{channel["baseHost"]}/up/{channel["boxName"]}/updates{query}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Client.get_websocket_url
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
if data["data"] == None: | ||
if data["data"] is None: | ||
logger.warn(f'{query_name} returned an error: {data["errors"][0]["message"]} | Retrying ({i+1}/20)') | ||
time.sleep(2) | ||
continue | ||
|
||
return r.json() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Client.send_query
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
)
#indicate that the response id is tied to the human message id | ||
elif key != "pending" and value == None and message["state"] != "complete": | ||
elif key != "pending" and value is None and message["state"] != "complete": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Client.on_message
refactored with the following changes:
- Use x is None rather than x == None (
none-compare
)
This removes the following comments ( why? ):
#indicate that the response id is tied to the human message id
if not type(message_ids) is list: | ||
if type(message_ids) is not list: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Client.delete_message
refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan
)
last_messages = self.get_message_history(chatbot, count=50)[::-1] | ||
while last_messages: | ||
while last_messages := self.get_message_history(chatbot, count=50)[::-1]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Client.purge_conversation
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Replace f-string with no interpolated values with string (
remove-redundant-fstring
)
Branch
main
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
main
branch, then run:Help us improve this pull request!