Skip to content

Commit

Permalink
Fix linting errors and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
shrir committed Dec 11, 2024
1 parent e469749 commit 84be082
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/app/domain/companies/schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from datetime import date, datetime
from datetime import date, datetime # noqa: TCH003
from uuid import UUID # noqa: TCH003

import msgspec
Expand Down
26 changes: 11 additions & 15 deletions src/app/domain/companies/services.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

from datetime import UTC, datetime, timedelta
from typing import TYPE_CHECKING, Any

import structlog
Expand Down Expand Up @@ -36,7 +35,7 @@ def __init__(self, **repo_kwargs: Any) -> None:
self.repository: CompanyRepository = self.repository_type(**repo_kwargs)
self.model_type = self.repository.model_type

async def create(
async def create( # noqa: PLR0915
self,
data: ModelDictT[Company],
*,
Expand All @@ -51,7 +50,8 @@ async def create(
elif isinstance(data, Company):
obj = data
else:
raise ValueError("CompanyService.create can only take a dict or Company object.")
error_msg = "CompanyService.create can only take a dict or Company object."
raise TypeError(error_msg)

filters = []
if obj.url:
Expand All @@ -64,17 +64,14 @@ async def create(
)

if not filters:
raise Exception("Unable to find company without url or linkedin_profile_url.")
error_msg = "Unable to find company without url or linkedin_profile_url."
raise ValueError(error_msg)

filters.append(LimitOffset(limit=1, offset=0))
results, count = await self.list_and_count(*filters)

now = datetime.now(UTC)
fiftytwo_weeks_ago = now - timedelta(weeks=52)

if count > 0:
# TODO: Uncomment after upsert is fixed
# if count > 0 and results[0].updated_at > fiftytwo_weeks_ago:
# TODO: Check the record is older than 4 weeks, refetch
await logger.ainfo("Company already exists", id=results[0].id, url=results[0].url)
return results[0]

Expand All @@ -85,7 +82,7 @@ async def create(
region=company_details.get("location", {}).get("region"),
city=company_details.get("location", {}).get("locality"),
)
except Exception as e:
except (KeyError, TypeError, IndexError, LookupError) as e:
await logger.awarn("Error getting company details", exc_info=e)
company_details = {}
location = None
Expand All @@ -99,8 +96,7 @@ async def create(
obj.url = company_details.get("website") or obj.url
obj.linkedin_profile_url = company_details.get("linkedin_url") or obj.linkedin_profile_url
obj.hq_location = location
# TODO: Enable Premium field
# obj.org_size = OrgSize(**company_details.get("employee_count_by_role", {}))
# TODO: Fetch and set org size

if obj.url:
# Get investor names and last funding round name
Expand All @@ -112,15 +108,15 @@ async def create(
announced_date=funding_data["announced_date"],
investors=funding_data["investors"],
)
except Exception as e:
except (KeyError, TypeError, IndexError, LookupError) as e:
obj.last_funding = Funding()
await logger.awarn("Failed to get company funding data", url=obj.url, exc_info=e)

# Get app store urls
try:
obj.ios_app_url = await get_ios_app_url(obj.url)
obj.android_app_url = await get_android_app_url(obj.name, obj.url)
except Exception as e:
except (KeyError, TypeError, IndexError, LookupError) as e:
await logger.awarn("Failed to get app store data", url=obj.url, exc_info=e)

# Get data from company homepage
Expand All @@ -134,7 +130,7 @@ async def create(
obj.discord_url = company_homepage_data.get("discord_url")
obj.slack_url = company_homepage_data.get("slack_url")
obj.twitter_url = company_homepage_data.get("twitter_url")
except Exception as e:
except (KeyError, TypeError, IndexError, LookupError) as e:
await logger.awarn("Failed to extract links from company homepage", url=obj.url, exc_info=e)

# TODO: Fix upsert
Expand Down
4 changes: 2 additions & 2 deletions src/app/domain/people/schemas.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from __future__ import annotations

from datetime import date, datetime # noqa: TCH003
from uuid import UUID # noqa: TCH003
from datetime import date, datetime

import msgspec

from app.lib.schema import CamelizedBaseStruct, Location, WorkExperience, SocialActivity
from app.lib.schema import CamelizedBaseStruct, Location, SocialActivity, WorkExperience


class Person(CamelizedBaseStruct):
Expand Down

0 comments on commit 84be082

Please sign in to comment.