-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweetAuthor.py
More file actions
29 lines (24 loc) · 840 Bytes
/
TweetAuthor.py
File metadata and controls
29 lines (24 loc) · 840 Bytes
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
import json
from constants import BASE_URL
class TweetAuthor:
def __init__(self, author_id: str or int, name: str, username: str):
if not isinstance(author_id, str):
author_id = str(author_id)
self.author_id = author_id
self.name = name
self.username = username
self.formatted_name = f'{self.name} (@{self.username})'
self.url = f'{BASE_URL}{self.username}'
def __str__(self):
return json.dumps(self.as_json())
def __repr__(self):
return json.dumps(self.as_json())
def as_json(self):
return {
"_id": str(self.author_id),
"author_id": self.author_id,
"name": self.name,
"username": self.username,
"formatted": self.formatted_name,
"author_url": self.url
}