Added the ability to give scheduled weight to accounts
This commit is contained in:
parent
4af16f2e52
commit
18419916ca
38
igmirror.py
38
igmirror.py
|
@ -62,15 +62,41 @@ def update_igaccount_async(acc_id, profileset=True):
|
|||
threading.Thread(target=update_igaccount, args=(acc_id, profileset,)).start()
|
||||
|
||||
def update_igaccount(acc_id, profileset=True):
|
||||
accdata = db_get('accounts', acc_id)
|
||||
|
||||
# Some IG might post faster than others, so we want to asign simple scheduling
|
||||
# to alter the way accounts are updated depending on how much you want 1 account to update
|
||||
if 'sched' in accdata:
|
||||
sched_err_msg = 'E| User schedule is not configured correctly, for "{}": {}'.format(acc_id, accdata['sched'])
|
||||
if not re.match(r'^\d+$', accdata['sched']):
|
||||
print(sched_err_msg)
|
||||
return 1
|
||||
|
||||
times = int(accdata['sched'])
|
||||
scnow = random.randint(1, times)
|
||||
if 'sched_now' in accdata:
|
||||
scnow = int(accdata['sched_now'])
|
||||
|
||||
if scnow == times:
|
||||
scnow = 1
|
||||
else:
|
||||
scnow += 1
|
||||
|
||||
accdata['sched_now'] = str(scnow)
|
||||
db_set('accounts', acc_id, accdata)
|
||||
if scnow != times:
|
||||
print('I| Skipping user "{}" according to configured schedule: {} of {}'.format(\
|
||||
acc_id, scnow, times))
|
||||
return 1
|
||||
|
||||
# if account does not exist, we stop the update process
|
||||
if not account_exists(acc_id):
|
||||
print('E| User "'+acc_id+'" has not been created yet, maybe you wanted to call /<username>/add ?')
|
||||
return 1
|
||||
return 2
|
||||
|
||||
data = getig_user_data(acc_id)
|
||||
if profileset:
|
||||
# update the fullname of the user on local DB
|
||||
accdata = db_get('accounts', acc_id)
|
||||
accdata['name'] = getig_user_fullname(data)
|
||||
db_set('accounts', acc_id, accdata)
|
||||
|
||||
|
@ -81,6 +107,7 @@ def update_igaccount(acc_id, profileset=True):
|
|||
|
||||
# sincronize posts (images/videos/stories...)
|
||||
pixelfed_dlposts(acc_id, data['graphql']['user'])
|
||||
return 0
|
||||
|
||||
def update_allaccounts_async():
|
||||
threading.Thread(target=update_allaccounts).start()
|
||||
|
@ -94,9 +121,10 @@ def update_allaccounts():
|
|||
for acc_id in accounts:
|
||||
i += 1
|
||||
print('I| mirroring account "{}"...'.format(acc_id))
|
||||
update_igaccount(acc_id)
|
||||
print('I| {} of {} completed. Waiting {} seconds'.format(i, len(accounts), sleeptime))
|
||||
time.sleep(sleeptime)
|
||||
ret = update_igaccount(acc_id)
|
||||
if ret == 0:
|
||||
print('I| {} of {} completed. Waiting {} seconds'.format(i, len(accounts), sleeptime))
|
||||
time.sleep(sleeptime)
|
||||
print()
|
||||
print('I| done updating all accounts')
|
||||
|
||||
|
|
Loading…
Reference in New Issue