-
Notifications
You must be signed in to change notification settings - Fork 9
Sourcery Starbot ⭐ refactored Style77/quantex #1
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,10 +23,7 @@ | |
|
|
||
| def get_chromedriver_path(): | ||
| current_directory = os.path.dirname(os.path.abspath(__file__)) | ||
| chromedriver_path = os.path.join( | ||
| current_directory, "driver", "chromedriver" | ||
| ) | ||
| return chromedriver_path | ||
| return os.path.join(current_directory, "driver", "chromedriver") | ||
|
|
||
|
|
||
| def convert_relative_timestamp(timestamp): | ||
|
|
@@ -48,22 +45,20 @@ def convert_relative_timestamp(timestamp): | |
| unit = timestamp[-1] | ||
|
|
||
| # Define the time delta based on the unit | ||
| 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 | ||
|
Comment on lines
-51
to
+61
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| class NewsScraper: | ||
|
|
@@ -419,7 +414,7 @@ def scrape(self, with_a: bool = True): | |
| } | ||
| results.append(data) | ||
|
|
||
| if len(results) > 0: | ||
| if results: | ||
|
Comment on lines
-422
to
+417
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.logger.info(f"Scraped {len(results)} articles") | ||
| else: | ||
| self.logger.warning("No articles scraped") | ||
|
|
@@ -511,12 +506,11 @@ def preconfigure(): | |
| if not user or not password: | ||
| raise Exception("Missing user or password") | ||
|
|
||
| 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 | ||
|
Comment on lines
-514
to
-518
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| @listener.on("unique_data") | ||
| def on_unique_data(item: list): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,9 +5,9 @@ | |
| class TelegramBot: | ||
| 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}/" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| 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) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return r.json() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,12 +33,12 @@ async def get_news(self, news_id: int) -> typing.List[NewsModelDTO]: | |
| """Get news by id.""" | ||
| query = select(NewsModel).where(NewsModel.id == news_id) | ||
| r = await self.session.execute(query) | ||
| 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)] | ||
|
Comment on lines
-36
to
-41
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| async def get_many_news( | ||
| self, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,7 +49,6 @@ def register_startup_event( | |
| @app.on_event("startup") | ||
| async def _startup() -> None: | ||
| _setup_db(app) | ||
| pass | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| return _startup | ||
|
|
||
|
|
@@ -68,6 +67,4 @@ def register_shutdown_event( | |
| async def _shutdown() -> None: | ||
| await app.state.db_engine.dispose() | ||
|
|
||
| pass | ||
|
|
||
|
Comment on lines
-71
to
-72
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return _shutdown | ||
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_pathrefactored with the following changes:inline-immediately-returned-variable)