MCPcopy
hub / github.com/gitcoinco/web / sync_profile

Function sync_profile

app/app/utils.py:175–217  ·  view source on GitHub ↗
(handle, user=None, hide_profile=True)

Source from the content-addressed store, hash-verified

173
174
175def sync_profile(handle, user=None, hide_profile=True):
176 handle = handle.strip().replace('@', '')
177 data = get_user(handle)
178 email = ''
179 is_error = 'name' not in data.keys()
180 if is_error:
181 print("- error main")
182 logger.warning('Failed to fetch github username', exc_info=True, extra={'handle': handle})
183 return None
184
185 defaults = {'last_sync_date': timezone.now(), 'data': data, 'hide_profile': hide_profile, }
186
187 if user and isinstance(user, User):
188 defaults['user'] = user
189 try:
190 defaults['github_access_token'] = user.social_auth.filter(provider='github').latest('pk').access_token
191 if user and user.email:
192 defaults['email'] = user.email
193 except UserSocialAuth.DoesNotExist:
194 pass
195
196 # store the org info in postgres
197 try:
198 profile, created = Profile.objects.update_or_create(handle=handle, defaults=defaults)
199 print("Profile:", profile, "- created" if created else "- updated")
200 except Exception as e:
201 logger.error(e)
202 return None
203
204 if user and user.email:
205 email = user.email
206 elif profile and profile.email:
207 email = profile.email
208
209 if email and profile:
210 get_or_save_email_subscriber(email, 'sync_profile', profile=profile)
211
212 if profile and not profile.github_access_token:
213 token = profile.get_access_token(save=False)
214 profile.github_access_token = token
215 profile.save()
216
217 return profile
218
219
220def fetch_last_email_id(email_id, password, host='imap.gmail.com', folder='INBOX'):

Callers 5

save_profileFunction · 0.90
settings_helper_get_authFunction · 0.90
record_bounty_activityFunction · 0.90
profile_helperFunction · 0.90
handleMethod · 0.90

Calls 7

get_userFunction · 0.90
replaceMethod · 0.80
nowMethod · 0.80
filterMethod · 0.80
get_access_tokenMethod · 0.80
saveMethod · 0.45

Tested by

no test coverage detected