Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
EinfachLeo authored and github-actions[bot] committed Jul 8, 2024
1 parent 7fc6870 commit 8e75b79
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/sharkey_crawler/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def to_snake_case(camel_case_str: str) -> str:
return ''.join(map(lambda e: '_' + e.lower() if e.isupper() else e, list(camel_case_str)))
return "".join(map(lambda e: "_" + e.lower() if e.isupper() else e, list(camel_case_str)))


def dict_keys_to_snake_case(data: T) -> T:
Expand Down
35 changes: 18 additions & 17 deletions src/sharkey_crawler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@

class SharkeyServer:
def __init__(self, base_url: str):
self.base_url = base_url.rstrip('/')
if not self.base_url.startswith('http://') and not self.base_url.startswith('https://'):
self.base_url = f'https://{self.base_url}'
self.base_url = base_url.rstrip("/")
if not self.base_url.startswith("http://") and not self.base_url.startswith("https://"):
self.base_url = f"https://{self.base_url}"

def user_notes(
self,
user_id: SharkeyId,
with_channel_notes: bool = False,
with_renotes: bool = True,
with_files: bool = False,
with_replies: bool = False,
limit: conint(ge=0, le=100) = 10,
allow_partial: bool = False,
since_date: int|None = None,
until_date: int|None = None,
since_id: SharkeyId|None = None,
until_id: SharkeyId|None = None
self,
user_id: SharkeyId,
with_channel_notes: bool = False,
with_renotes: bool = True,
with_files: bool = False,
with_replies: bool = False,
limit: conint(ge=0, le=100) = 10,
allow_partial: bool = False,
since_date: int | None = None,
until_date: int | None = None,
since_id: SharkeyId | None = None,
until_id: SharkeyId | None = None,
) -> list[Post]:
"""
This function returns the latest posts about a user.
Expand Down Expand Up @@ -70,7 +70,7 @@ def user_notes(
"withFiles": with_files,
"withReplies": with_replies,
"limit": limit,
"allowPartial": allow_partial
"allowPartial": allow_partial,
}
if since_date:
payload["sinceDate"] = since_date
Expand All @@ -81,13 +81,14 @@ def user_notes(
if until_id:
payload["untilId"] = until_id

response = requests.post(self.base_url + '/api/users/notes', json=payload)
response = requests.post(self.base_url + "/api/users/notes", json=payload)

data = response.json()

posts = []
for post in data:
from pprint import pprint

pprint(dict_keys_to_snake_case(post))
posts.append(Post.model_validate(dict_keys_to_snake_case(post)))

Expand Down
73 changes: 37 additions & 36 deletions src/sharkey_crawler/types/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,44 @@

class Post(BaseModel):
"""Represents a post as returned by Sharkey."""
model_config = ConfigDict(extra='forbid')

model_config = ConfigDict(extra="forbid")

id: SharkeyId
created_at: datetime
updated_at: datetime|None = None
deleted_at: datetime|None = None
text: str|None = None
cw: str|None = None
updated_at: datetime | None = None
deleted_at: datetime | None = None
text: str | None = None
cw: str | None = None
user_id: SharkeyId
user: UserLite
reply_id: SharkeyId|None = None
renote_id: SharkeyId|None = None
reply: Post|None = None
renote: Post|None = None
is_hidden: bool|None = None
reply_id: SharkeyId | None = None
renote_id: SharkeyId | None = None
reply: Post | None = None
renote: Post | None = None
is_hidden: bool | None = None
visibility: Visibility
mentions: list[SharkeyId] = []
visible_user_ids: list[SharkeyId] = []
file_ids: list[SharkeyId] = []
files: list[DriveFile] = []
tags: list[str] = []
poll: Poll|None = None
poll: Poll | None = None
emojis: dict[str, str] = {}
channel_id: SharkeyId|None = None
channel: Channel|None = None
local_only: bool|None = None
reaction_acceptance: str|None = None
channel_id: SharkeyId | None = None
channel: Channel | None = None
local_only: bool | None = None
reaction_acceptance: str | None = None
reaction_emojis: dict[str, str] = {}
reactions: dict[str, int] = {}
reaction_count: int = 0
renote_count: int = 0
replies_count: int = 0
uri: str|None = None
url: str|None = None
uri: str | None = None
url: str | None = None
reaction_and_user_pair_cache: list[str] = []
clipped_count: int|None = None
my_reaction: str|None = None
clipped_count: int | None = None
my_reaction: str | None = None


class Visibility(str, Enum):
Expand All @@ -69,37 +70,37 @@ class Visibility(str, Enum):

class DriveFile(BaseModel):
id: SharkeyId
created_at: datetime|None = None
created_at: datetime | None = None
name: str
type: str
md5: str
size: int|float
is_sensitive: bool|None = None
blurhash: str|None = None
properties: DriveFileProperties|None = None
size: int | float
is_sensitive: bool | None = None
blurhash: str | None = None
properties: DriveFileProperties | None = None
url: str
thumbnail_url: str|None = None
comment: str|None = None
folder_id: SharkeyId|None = None
folder: DriveFolder|None = None
user_id: SharkeyId|None = None
user: UserLite|None = None
thumbnail_url: str | None = None
comment: str | None = None
folder_id: SharkeyId | None = None
folder: DriveFolder | None = None
user_id: SharkeyId | None = None
user: UserLite | None = None


class DriveFolder(BaseModel):
id: SharkeyId
created_at: datetime
name: str
parent_id: SharkeyId|None = None
parent_id: SharkeyId | None = None
folders_count: int
files_count: int
parent: DriveFolder


class DriveFileProperties(BaseModel):
width: int|float
height: int|float
orientation: int|float|None = None
width: int | float
height: int | float
orientation: int | float | None = None
avg_color: str = None


Expand All @@ -109,11 +110,11 @@ class Channel(BaseModel):
color: str
is_sensitive: bool
allow_renote_to_external: bool
user_id: SharkeyId|None = None
user_id: SharkeyId | None = None


class Poll(BaseModel):
expires_at: datetime|None = None
expires_at: datetime | None = None
multiple: bool
choices: list[PollChoice] = []

Expand Down
44 changes: 22 additions & 22 deletions src/sharkey_crawler/types/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ class UserLite(BaseModel):
"""Represents a user lite as returned by Sharkey."""

id: SharkeyId
name: str|None = None
description: str|None = None
name: str | None = None
description: str | None = None
username: str
host: str|None = None
created_at: datetime|None = None
avatar_url: str|None = None
avatar_blurhash: str|None = None
host: str | None = None
created_at: datetime | None = None
avatar_url: str | None = None
avatar_blurhash: str | None = None
avatar_decorations: list[AvatarDecoration] = []
is_bot: bool|None = None
is_cat: bool|None = None
instance: Instance|None = None
is_bot: bool | None = None
is_cat: bool | None = None
instance: Instance | None = None
emojis: dict[str, str] = {}
online_status: OnlineStatus
badge_roles: list[BadgeRole] = []
Expand All @@ -53,25 +53,25 @@ class OnlineStatus(str, Enum):

class AvatarDecoration(BaseModel):
id: SharkeyId
angle: float|int|None = None
flip_h: bool|None = None
angle: float | int | None = None
flip_h: bool | None = None
url: str
offset_x: float|int|None = None
offset_y: float|int|None = None
offset_x: float | int | None = None
offset_y: float | int | None = None


class Instance(BaseModel):
id: SharkeyId|None = None
name: str|None = None
software_name: str|None = None
software_version: str|None = None
icon_url: str|None = None
favicon_url: str|None = None
theme_color: str|None = None
id: SharkeyId | None = None
name: str | None = None
software_name: str | None = None
software_version: str | None = None
icon_url: str | None = None
favicon_url: str | None = None
theme_color: str | None = None


class BadgeRole(BaseModel):
name: str
icon_url: str|None = None
icon_url: str | None = None
display_order: int
behavior: str|None = None
behavior: str | None = None
15 changes: 5 additions & 10 deletions tests/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,21 @@


def crawl_notes_on_waldbewohner_eu(user: str) -> list[Post]:
return SharkeyServer('waldbewohner.eu').user_notes(
user,
allow_partial=True,
with_channel_notes=True,
with_renotes=False,
with_replies=False
return SharkeyServer("waldbewohner.eu").user_notes(
user, allow_partial=True, with_channel_notes=True, with_renotes=False, with_replies=False
)


def crawl_varia() -> list[Post]:
return crawl_notes_on_waldbewohner_eu('9vdsx5h21yqo003k')
return crawl_notes_on_waldbewohner_eu("9vdsx5h21yqo003k")


def crawl_cero() -> list[Post]:
return crawl_notes_on_waldbewohner_eu('9svsbjf77hmg007e')
return crawl_notes_on_waldbewohner_eu("9svsbjf77hmg007e")


def crawl_yasu() -> list[Post]:
return crawl_notes_on_waldbewohner_eu('9st8kmrs7hmg0001')
return crawl_notes_on_waldbewohner_eu("9st8kmrs7hmg0001")


def test_can_crawl_users():
Expand All @@ -37,4 +33,3 @@ def test_can_crawl_users():
crawl_cero()
crawl_yasu()
crawl_varia()

0 comments on commit 8e75b79

Please sign in to comment.