This repository was archived by the owner on Jul 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.py
More file actions
144 lines (119 loc) · 5.42 KB
/
Copy pathdashboard.py
File metadata and controls
144 lines (119 loc) · 5.42 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import os
import json
from rich.console import Console
from rich.table import Table
from datetime import datetime
status_file = 'status.json'
log_file = 'upload_log.txt'
random_upload_time_file = 'random-upload-times.json'
random_waits_file = 'random-waits.json'
downloads_dir = 'downloads'
console = Console()
def read_status():
if not os.path.exists(status_file):
console.print("[bold red]Status file not found.[/bold red]")
return {}
with open(status_file, 'r') as f:
status = json.load(f)
return status
def read_upload_log():
if not os.path.exists(log_file):
console.print("[bold red]Upload log file not found.[/bold red]")
return []
with open(log_file, 'r') as f:
uploads = f.readlines()
return [upload.strip() for upload in uploads]
def read_random_upload_times():
if not os.path.exists(random_upload_time_file):
console.print("[bold red]Random upload times file not found.[/bold red]")
return []
with open(random_upload_time_file, 'r') as f:
random_times = json.load(f)
return random_times
def read_random_waits():
if not os.path.exists(random_waits_file):
console.print("[bold red]Random waits file not found.[/bold red]")
return []
try:
with open(random_waits_file, 'r') as f:
random_times = json.load(f)
except json.JSONDecodeError as e:
console.print(f"[bold red]Error reading random waits file: {e}[/bold red]")
return []
return random_times
def get_file_counts():
if not os.path.exists(downloads_dir):
console.print("[bold red]Downloads directory not found.[/bold red]")
return 0, 0, 0, 0
total_files = [f for f in os.listdir(downloads_dir) if f.endswith('.mp4')]
upload_log = read_upload_log()
uploaded_files = [f for f in total_files if f.rsplit('.', 1)[0] in upload_log]
unuploaded_files = [f for f in total_files if f not in uploaded_files]
folder_size = sum(os.path.getsize(os.path.join(downloads_dir, f)) for f in os.listdir(downloads_dir)) / (1024 * 1024) # size in MB
return len(total_files), len(uploaded_files), len(unuploaded_files), folder_size
def format_time(timestamp):
if not timestamp or timestamp == 'None':
return "N/A"
try:
return datetime.fromtimestamp(float(timestamp)).strftime('%Y-%m-%d %H:%M:%S')
except Exception:
return "Invalid timestamp"
def main():
status = read_status()
if not status:
return
uploads = read_upload_log()
random_upload_times = read_random_upload_times()
random_waits = read_random_waits()
total_files, uploaded_files, unuploaded_files, folder_size = get_file_counts()
console.print("=" * 80, justify="left")
console.print("[bold yellow]Instagram Thefty Poster Dashboard[/bold yellow]", justify="left")
console.print("=" * 80, justify="left")
# Scrape and Upload Status Table
table = Table(show_header=True, header_style="bold magenta")
table.add_column("Scrape Status", justify="center")
table.add_column("Upload Status", justify="center")
table.add_row(
f"Last Scrape Time: {format_time(status.get('last_scrape_time'))}\nNext Scrape Time: {format_time(status.get('next_scrape_time'))}",
f"Last Upload Time: {format_time(status.get('last_upload_time'))}\nNext Upload Time: {format_time(status.get('next_upload_time'))}"
)
console.print(table)
# File Counts Table
file_table = Table(show_header=True, header_style="bold magenta")
file_table.add_column("Metric", justify="center")
file_table.add_column("Value", justify="center")
file_table.add_row("Total .mp4 Files", str(total_files))
file_table.add_row("Uploaded .mp4 Files", str(uploaded_files))
file_table.add_row("Unuploaded .mp4 Files", str(unuploaded_files))
file_table.add_row("Downloads Folder Size (MB)", f"{folder_size:.2f}")
console.print(file_table)
# Last 10 Uploads
console.print("[bold]Last 10 Uploads[/bold]")
for upload in uploads[-10:]:
console.print(f"- {upload}")
# Reels Scraped
console.print("[bold]Reels Scraped[/bold]")
for reel in status.get('reels_scraped', []):
console.print(f"- {reel}")
# Random Upload Times
console.print("[bold]Random Upload Times (seconds)[/bold]")
for upload_time in random_upload_times[-10:]:
console.print(f"- {upload_time}")
# Random Wait Times
console.print("[bold]Random Wait Times (seconds)[/bold]")
for wait_time in random_waits[-10:]:
console.print(f"- {wait_time}")
# Story Upload and Deletion Status Table
table2 = Table(show_header=True, header_style="bold magenta")
table2.add_column("Story Upload Status", justify="center")
table2.add_column("Deletion Status", justify="center")
table2.add_row(
f"Last Story Upload Time: {format_time(status.get('last_story_upload_time'))}\nNext Story Upload Time: {format_time(status.get('next_story_upload_time'))}",
f"Last Deletion Time: {format_time(status.get('last_delete_time'))}\nNext Deletion Time: {format_time(status.get('next_delete_time'))}"
)
console.print(table2)
# Next file to upload
next_file = status.get('next_file_to_upload', 'N/A')
console.print(f"[bold]Next File to Upload:[/bold] {next_file}")
if __name__ == "__main__":
main()