-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·79 lines (66 loc) · 2.7 KB
/
main.py
File metadata and controls
executable file
·79 lines (66 loc) · 2.7 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
from fetch import get_filtered_threads
from session import login
import argparse
from dotenv import dotenv_values
from rich.console import Console # type: ignore
from rich.theme import Theme # type: ignore
from rich.panel import Panel
from rich.text import Text
from rich.markdown import Markdown
custom_theme = Theme({
"title": "red",
"you": "cyan",
"other": "yellow",
"link": "blue",
"dim": "dim",
})
console = Console(theme=custom_theme)
config = dotenv_values("/home/pranshu/insta-cli/.env")
user = config["USERNAME"]
pwd = config["PASSWORD"]
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--unread", action="store_true")
parser.add_argument("--thread", type=int, default=5)
parser.add_argument("--messages", type=int, default=5)
args = parser.parse_args()
client = login()
threads = get_filtered_threads(
client,
amount=args.thread,
useful_limit=args.messages,
selected_filter="unread" if args.unread else ""
)
for thread in threads:
# Title box for each thread
thread_title = Text(thread.thread_title, style="title")
console.print(Panel(thread_title, expand=False, border_style="title"))
# Message list
for message in thread.messages:
sender_id = message.user_id
sender_name = next(
(user.username for user in thread.users if user.pk == sender_id),
"You"
)
is_you = sender_name == "You"
name_style = "you" if is_you else "other"
name_label = Text(sender_name, style=name_style)
# Construct message content
if message.clip is not None:
content = f"https://www.instagram.com/reel/{message.clip.code}"
console.print(Panel(Text(content, style="link"), title=name_label, expand=False))
elif message.text is not None:
console.print(Panel(Text(message.text), title=name_label, expand=False))
elif message.xma_share is not None:
content=str(message.xma_share.video_url).split('/?')[0]
console.print(Panel(Text(content, style="link"), title=name_label, expand=False))
elif message.reel_share:
code = message.reel_share.media.code
content = f"https://www.instagram.com/reel/{code}"
console.print(Panel(Text(content, style="link"), title=name_label, expand=False))
else:
console.print(Panel(Text(f"[{message.item_type}]", style="dim"), title=name_label, expand=False))
console.print() # Empty line between threads
if __name__ == "__main__":
main()