-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtag_manager.py
More file actions
143 lines (111 loc) · 3.66 KB
/
Copy pathtag_manager.py
File metadata and controls
143 lines (111 loc) · 3.66 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
"""
Tag Manager Module for MEGA Account Generator
Handles account tagging and tag operations
"""
import os
import csv_utils
class TagManager:
"""Manage tags for accounts"""
@staticmethod
def get_account_tags(email):
"""
Get tags for a specific account.
Args:
email: Account email address
Returns:
list: Tags for the account
"""
if not csv_utils.csv_exists():
return []
rows = csv_utils.read_accounts()
for row in rows:
if row and row[0] == email:
# Tags are in column 5 (index 5)
if len(row) > 5 and row[5]:
return [tag.strip() for tag in row[5].split(',') if tag.strip()]
return []
return []
@staticmethod
def set_account_tags(email, tags):
"""
Set tags for an account.
Args:
email: Account email address
tags: List of tag strings
"""
if not csv_utils.csv_exists():
return False
rows = csv_utils.read_accounts()
if not rows:
return False
updated = False
for i in range(len(rows)):
if rows[i] and rows[i][0] == email:
# csv_utils.read_accounts ensures 8 columns
rows[i][5] = ','.join(tags)
updated = True
break
if updated:
csv_utils.write_accounts(rows)
return updated
@staticmethod
def add_tag(email, tag):
"""
Add a tag to an account.
Args:
email: Account email
tag: Tag to add
"""
current_tags = TagManager.get_account_tags(email)
if tag and tag not in current_tags:
current_tags.append(tag)
return TagManager.set_account_tags(email, current_tags)
return False
@staticmethod
def remove_tag(email, tag):
"""
Remove a tag from an account.
Args:
email: Account email
tag: Tag to remove
"""
current_tags = TagManager.get_account_tags(email)
if tag in current_tags:
current_tags.remove(tag)
return TagManager.set_account_tags(email, current_tags)
return False
@staticmethod
def get_all_tags():
"""
Get all unique tags across all accounts.
Returns:
list: Sorted list of unique tags
"""
if not csv_utils.csv_exists():
return []
tags_set = set()
rows = csv_utils.read_accounts()
for row in rows:
if row and len(row) > 5 and row[5]:
account_tags = [tag.strip() for tag in row[5].split(',') if tag.strip()]
tags_set.update(account_tags)
return sorted(list(tags_set))
@staticmethod
def get_accounts_by_tag(tag):
"""
Get all accounts that have a specific tag.
Args:
tag: Tag to search for
Returns:
list: Email addresses with the tag
"""
if not csv_utils.csv_exists():
return []
matching = []
rows = csv_utils.read_accounts()
for row in rows:
if row and len(row) > 5 and row[5]:
account_tags = [t.strip() for t in row[5].split(',') if t.strip()]
if tag in account_tags:
matching.append(row[0])
return matching