-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinvites_parser.py
More file actions
47 lines (39 loc) · 1.41 KB
/
invites_parser.py
File metadata and controls
47 lines (39 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from dataclasses import asdict, dataclass
from time import sleep
from typing import Generator
from constants import TIMEDELTA
from interface_wrapper import IRepositoryAPI, Repository
from utils import logger
@dataclass(kw_only=True, frozen=True)
class InviteData:
repository_name: str = ''
invited_login: str = ''
invite_creation_date: str = ''
invitation_url: str = ''
def log_repository_invitations(
client: IRepositoryAPI, repository: Repository, csv_name: str
):
invitations = client.get_invites(repository)
for invite in invitations:
invite_data = InviteData(
repository_name=repository.name,
invited_login=invite.invitee.login,
invite_creation_date=invite.created_at.strftime("%d/%m/%Y, %H:%M:%S"),
invitation_url=invite.html_url,
)
invite_dict = asdict(invite_data)
logger.log_to_csv(csv_name, list(invite_dict.keys()), invite_dict)
logger.log_to_stdout(invite_dict)
sleep(TIMEDELTA)
def log_invitations(
binded_repos: Generator[tuple[IRepositoryAPI, Repository, str], None, None],
csv_name: str,
):
info = asdict(InviteData())
logger.log_to_csv(csv_name, list(info.keys()))
for client, repo, token in binded_repos:
logger.log_title(repo.name)
try:
log_repository_invitations(client, repo, csv_name)
except Exception as e:
print(e)