diff --git a/README.md b/README.md index 09b3a5e..3bcbac9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # TeleInviter Invite members, from (many) `source_groups` to (one) `destination_group` -And avoid repetition from `destination_group` +and avoid repetition from `destination_group` # ENV - python3 @@ -10,11 +10,12 @@ And avoid repetition from `destination_group` - `pip3 install peewee` - `pip3 install colorama` - `pip3 install pprint` -- maybe some packages i forgot.. +- maybe some packages I forgot... # RUN - make a configuration file named `conf.py` - run `py main.py` +- init database `python3 db_init.py` - two confirmation during the processing # Developing diff --git a/db.py b/db.py index 20dbd2a..cbab683 100644 --- a/db.py +++ b/db.py @@ -59,3 +59,22 @@ def save_invite(u): invite.save() return invite + + +class KeyPosition(BaseModel): + pause_position = CharField(unique=True) + + +def get_create_or_update_pause_position(position=None): + # create + if position is None: + position = 0 + + key_position, created = KeyPosition.get_or_create(pause_position=position) + + # update + if position is not None and (position >= key_position.pause_position): + key_position.pause_position = position + key_position.save() + + return key_position.pause_position \ No newline at end of file diff --git a/db_init.py b/db_init.py index f0cda16..bd5fda1 100644 --- a/db_init.py +++ b/db_init.py @@ -3,6 +3,6 @@ db.connect() -db.create_tables([Invite]) +db.create_tables([Invite, KeyPosition]) print('Database: initialization complete!') diff --git a/main.py b/main.py index a232a30..606c3e4 100644 --- a/main.py +++ b/main.py @@ -113,9 +113,10 @@ def invite_user(u): except errors.rpcerrorlist.PeerFloodError as e: sys.stdout.write(colorama.Fore.LIGHTRED_EX + '\n error#9. PeerFloodError > ') sys.stdout.write(colorama.Fore.LIGHTMAGENTA_EX + '%s ' % e.message) - print('... Retry after 2 Mins ...') - time.sleep(120) - invite_user(u) + # Prepare to exit: record the position of job failed + db.get_create_or_update_pause_position(i) + # When PeerFloodError occurs, it should better not to use this client any more + sys.exit(0) else: print(colorama.Fore.GREEN + 'skipped') @@ -317,8 +318,9 @@ def is_user_status_offline_passed(t): # Start inviting print(colorama.Fore.LIGHTCYAN_EX + '\n\nStarting inviting:') -i = 0 -for u in participants[client_sessions[0]]: +# leave back or use the position you want to start from +i = db.get_create_or_update_pause_position() +for u in participants[client_sessions[0]][i:]: if u.bot is False: # skip bots if len(get_user_display_name(u)) > conf.filter_user_display_name_too_much_words_limit: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6050f9d --- /dev/null +++ b/requirements.txt @@ -0,0 +1,6 @@ +Telethon==1.1.1 +Telethon-sync==1.0.4 +PySocks==1.6.8 +peewee==3.6.4 +colorama==0.3.9 +pprint==0.1 \ No newline at end of file