Sourcery Starbot ⭐ refactored Style77/quantex - #1
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.
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)
| @app.on_event("startup") | ||
| async def _startup() -> None: | ||
| _setup_db(app) | ||
| pass |
There was a problem hiding this comment.
Function register_startup_event refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass)
| pass | ||
|
|
There was a problem hiding this comment.
Function register_shutdown_event refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass)
| current_directory, "driver", "chromedriver" | ||
| ) | ||
| return chromedriver_path | ||
| return os.path.join(current_directory, "driver", "chromedriver") |
There was a problem hiding this comment.
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.
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.
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.
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)
| def __init__(self, token): | ||
| self.token = token | ||
| 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.
Function TelegramBot.__init__ refactored with the following changes:
- Replace call to format with f-string (
use-fstring-for-formatting)
| def send_message(self, chat: str, text: str): | ||
| data = {"chat_id": chat, "text": text, "parse_mode": "markdown"} | ||
| 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.
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
developbranch, then run: