Skip to content

Instantly share code, notes, and snippets.

@Himstar8
Created January 10, 2020 09:32
Show Gist options
  • Save Himstar8/54528fb23357b47f7a6fc43efd66ef59 to your computer and use it in GitHub Desktop.
Save Himstar8/54528fb23357b47f7a6fc43efd66ef59 to your computer and use it in GitHub Desktop.
def main():
key_path = os.path.join(settings.INTERNAL_FILES, 'crm2', 'service_account_secrets.json')
credentials = get_api_credentials(key_path=key_path)
if not credentials:
logger.info("No credential found, so stopping")
return
active_users = User.objects.filter(is_active=True)
for user in active_users:
email = user.email
signature_template = ''
try:
expert = Expert.objects.get(user=user)
signature_template = expert.signature
except Expert.DoesNotExist:
# Not an Expert, get signature_template from user
ctx = create_layout_context_from_user(user)
signature_template = get_signature(ctx)
retry_count = 0
while retry_count < 3:
try:
update_signature(user_email=email, template=signature_template, credentials=credentials, live=True)
break
except (RefreshError,TransportError) as e:
retry_count += 1
logger.info("Error encountered for: {0}, retrying (attempt {1}). Error was: {2}".format(user.username, retry_count, e))
time.sleep(2)
continue
except Exception as e:
raise
else:
logger.info("Failed to update {0}'s signature".format(user.username))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment