Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions quantex-scraper/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Copy link
Copy Markdown
Author

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:



def convert_relative_timestamp(timestamp):
Expand All @@ -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

Copy link
Copy Markdown
Author

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:



class NewsScraper:
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Author

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:

self.logger.info(f"Scraped {len(results)} articles")
else:
self.logger.warning("No articles scraped")
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Author

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:



@listener.on("unique_data")
def on_unique_data(item: list):
Expand Down
4 changes: 2 additions & 2 deletions quantex-scraper/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}/"

Copy link
Copy Markdown
Author

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:


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)

Copy link
Copy Markdown
Author

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:

return r.json()
6 changes: 3 additions & 3 deletions quantex/database/dao/news_dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Author

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:


async def get_many_news(
self,
Expand Down
3 changes: 0 additions & 3 deletions quantex/web/lifetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def register_startup_event(
@app.on_event("startup")
async def _startup() -> None:
_setup_db(app)
pass

Copy link
Copy Markdown
Author

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:


return _startup

Expand All @@ -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

Copy link
Copy Markdown
Author

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:

return _shutdown