Skip to content

Commit

Permalink
done trace log
Browse files Browse the repository at this point in the history
  • Loading branch information
south1907 committed Jan 10, 2023
1 parent 28553a4 commit 09f8c21
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ data/*
config.json
current_count.txt

data-log/*
!data-log/__init__
13 changes: 13 additions & 0 deletions add_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
root_path = os.path.dirname(os.path.abspath(__file__))
folder_session = root_path + '/session/'
folder_data = root_path + '/data/'
folder_data_log = root_path + '/data-log/'

accounts = config['accounts']

Expand Down Expand Up @@ -50,6 +51,10 @@
count_added = 0 # count added success (in 1 big round)
total_count_added = 0 # total count added success

# file save log processed
path_file_log = folder_data_log + '/' + str(group_target) + '.txt'
list_id_processed = read_log_processed(path_file_log)

assert len(accounts) > 0

# init TelegramClient
Expand Down Expand Up @@ -105,6 +110,11 @@
i += 1
logging.info('User ' + str(user['user_id']) + ' in target group, not add')
continue

if str(user['user_id']) in list_id_processed:
i += 1
logging.info('User ' + str(user['user_id']) + ' is processed previous')
continue

current_index = count_added % total_client
current_client = clients[count_added % total_client]
Expand All @@ -120,6 +130,9 @@
user_to_add = InputPeerUser(int(user[current_client['phone']]['user_id']), int(user[current_client['phone']]['access_hash']))
status_add = add_member_to_group(current_client['client'], current_client['group_target'], user_to_add)

list_id_processed.append(str(user['user_id']))
write_log_processed(path_file_log, list_id_processed)

logging.info("status_add: " + status_add)
if status_add == 'SUCCESS':
logging.info('Added member ' + str(user['user_id']) + ' successfully ;-)')
Expand Down
Empty file added data-log/__init__
Empty file.
27 changes: 27 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,33 @@ def update_count(path, current_index):
g.write(str(current_index))
g.close()

def write_log_processed(path, list_processed):
"""
:param path: path
:param list_processed: list_processed
:return: void
"""
with open(path, 'w') as g:
g.write('\n'.join(list_processed))
g.close()

def read_log_processed(path):
"""
:param path: path
:param current_index: current_index
:return: void
"""
result = []
try:
with open(path, encoding='utf-8') as f:
result = f.read().split('\n')
except Exception as e:
pass

return result

def read_data_member(path_data):
"""
:param client: path_data
Expand Down

0 comments on commit 09f8c21

Please sign in to comment.