def save_topics(y_dict): y_dict['step'] = 4 y_dict['message'] = "Saving topics to DB." y_json = json.dumps(y_dict) yield 'data: ' + y_json + '\n\n' try: user = Entity() user.PartitionKey = microsoft.get( 'organization').data['value'][0]['id'] user.RowKey = microsoft.get('me').data['id'] confirmed = ",".join(y_dict['topicsRefined']) if len( y_dict['topicsRefined']) > 0 else '' suggested = ",".join( y_dict['topics']) if len(y_dict['topics']) > 0 else '' user.confirmedSkills = json.dumps(confirmed) user.suggestedSkills = json.dumps(suggested) table_service.insert_or_merge_entity('users', user) y_dict['message'] = "Sucessfully saved topics to DB!" y_json = json.dumps(y_dict) yield 'data: ' + y_json + '\n\n' except Exception as e: y_dict['step'] = 0 y_dict['message'] = "We ran into a problem saving to DB: " + str(e) y_json = json.dumps(y_dict) yield 'data: ' + y_json + '\n\n'
def get_parse_emails(payload, y_dict, size): y_dict['step'] = 1 y_dict['count'] = 0 y_dict['message'] = "Setting up to get emails." y_json = json.dumps(y_dict) yield 'data: ' + y_json + '\n\n' #30 MB Limit (using 1mb to test) sizeLimit = size * 1024 * 1024 full = False first_loop = True next_link = '' while not full: if first_loop: sent_mail = microsoft.get( 'me/MailFolders/SentItems/messages?$top=20&$select=subject,uniqueBody' ) first_loop = False else: sent_mail = microsoft.get(next_link) if '@odata.nextLink' in sent_mail.data: next_link = sent_mail.data['@odata.nextLink'] else: full = True objectLists = jsonParser(sent_mail.data) filteredEmails = cleanList(objectLists) #print("Email cleanup:", len(objectLists), len(filteredEmails)) for mail in filteredEmails: if sys.getsizeof(str(payload)) < sizeLimit: id = str(mail['id']) text = str(mail['text']) payload['documents'].append({'id': id, 'text': text}) y_dict['count'] += 1 y_dict['message'] = text y_json = json.dumps(y_dict) yield 'data: ' + y_json + '\n\n' else: del payload['documents'][-1] full = True y_dict['message'] = "Finished Collecting Emails" y_json = json.dumps(y_dict) print("Get emails output:", y_dict) yield 'data: ' + y_json + '\n\n' break if len(payload['documents']) == 0: y_dict['step'] == 0 y_dict[ 'message'] = "No emails collected. Try signing out and signing back in again." y_json = json.dumps(y_dict) yield 'data: ' + y_json + '\n\n'
def home(): me = microsoft.get('me') user = Entity() user.PartitionKey = microsoft.get('organization').data['value'][0]['id'] user.RowKey = microsoft.get('me').data['id'] try: user = table_service.get_entity('users', user.PartitionKey, user.RowKey) if len(user.suggestedSkills) < 3: print("No suggested skills found, redirecting to sent mail", user.suggestedSkills) return redirect('/sentMail') else: print("Skills found, redirecting to the skills page") return redirect('/skills') except: print("No user was found in Azure tables, redirecting to sent mail") return redirect('/sentMail')
def showskills(): if request.method == 'GET': user = Entity() user.PartitionKey = microsoft.get( 'organization').data['value'][0]['id'] user.RowKey = microsoft.get('me').data['id'] user = table_service.get_entity('users', user.PartitionKey, user.RowKey) print(user.confirmedSkills, user) confirmed = remove_quotes(user.confirmedSkills) confirmed_list = confirmed.split(",") if len(confirmed) > 0 else [] other = remove_quotes(user.suggestedSkills) other_list = other.split(",") if len(user.suggestedSkills) > 0 else [] print("Got skills from Azure Tables:", confirmed) return render_template('showskills.html', confirmed=confirmed_list, other=other_list) if request.method == 'POST': print(request.content_type, request.json) data = request.json confirmed_data = data['confirmed'] other_data = data['other'] pub_choices = data['pubChoices'] try: user = Entity() user.PartitionKey = microsoft.get( 'organization').data['value'][0]['id'] user.RowKey = microsoft.get('me').data['id'] confirmed = ",".join( confirmed_data) if len(confirmed_data) > 0 else '' suggested = ",".join(other_data) if len(other_data) > 0 else '' user.confirmedSkills = json.dumps(confirmed) user.suggestedSkills = json.dumps(suggested) table_service.insert_or_merge_entity('users', user) except: return json.dumps({'success': False}), 500, { 'ContentType': 'application/json' } else: return json.dumps({'success': True}), 200, { 'ContentType': 'application/json' }