-
Notifications
You must be signed in to change notification settings - Fork 6
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 Starbot ⭐ refactored Style77/quantex #1
base: develop
Are you sure you want to change the base?
Conversation
news = r.scalars().first() | ||
if not news: | ||
if news := r.scalars().first(): | ||
return [NewsModelDTO.from_orm(news)] | ||
else: | ||
raise HTTPException( | ||
status_code=status.HTTP_404_NOT_FOUND, detail="News not found" | ||
) | ||
return [NewsModelDTO.from_orm(news)] |
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 NewsDAO.get_news
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Lift code into else after jump in control flow (
reintroduce-else
) - Swap if/else branches (
swap-if-else-branches
)
@@ -49,7 +49,6 @@ def register_startup_event( | |||
@app.on_event("startup") | |||
async def _startup() -> None: | |||
_setup_db(app) | |||
pass |
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 register_startup_event
refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass
)
pass | ||
|
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 register_shutdown_event
refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass
)
chromedriver_path = os.path.join( | ||
current_directory, "driver", "chromedriver" | ||
) | ||
return chromedriver_path | ||
return os.path.join(current_directory, "driver", "chromedriver") |
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 get_chromedriver_path
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if unit == "s": | ||
delta = timedelta(seconds=int(value)) | ||
elif unit == "m": | ||
delta = timedelta(minutes=int(value)) | ||
if unit == "d": | ||
delta = timedelta(days=int(value)) | ||
elif unit == "h": | ||
delta = timedelta(hours=int(value)) | ||
elif unit == "d": | ||
delta = timedelta(days=int(value)) | ||
elif unit == "m": | ||
delta = timedelta(minutes=int(value)) | ||
elif unit == "s": | ||
delta = timedelta(seconds=int(value)) | ||
elif unit == "w": | ||
delta = timedelta(weeks=int(value)) | ||
else: | ||
raise ValueError("Invalid timestamp unit") | ||
|
||
normal_datetime = datetime.now() - delta | ||
|
||
return normal_datetime | ||
return datetime.now() - delta |
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 convert_relative_timestamp
refactored with the following changes:
- Simplify conditional into switch-like form [×2] (
switch
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
if len(results) > 0: | ||
if results: |
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 NewsScraper.scrape
refactored with the following changes:
- Simplify sequence length comparison (
simplify-len-comparison
)
edenai_key = os.getenv("QUANTEX_EDENAI_API_KEY") | ||
if not edenai_key: | ||
if edenai_key := os.getenv("QUANTEX_EDENAI_API_KEY"): | ||
return user, password, edenai_key | ||
else: | ||
raise Exception("Missing EdenAI API key") | ||
|
||
return user, password, edenai_key |
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 preconfigure
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Lift code into else after jump in control flow (
reintroduce-else
) - Swap if/else branches (
swap-if-else-branches
)
self.api_url = "https://api.telegram.org/bot{}/".format(token) | ||
self.api_url = f"https://api.telegram.org/bot{token}/" |
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 TelegramBot.__init__
refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting
)
r = requests.post(self.api_url + "sendMessage", data=data) | ||
r = requests.post(f"{self.api_url}sendMessage", data=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 TelegramBot.send_message
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
develop
branch, then run: