<commit_before><commit_msg>automated profile updating from DB or file<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json
from pymongo import MongoClient
from onename_register import update_name
import os 

MONGODB_URI = os.environ['MONGODB_URI']
HEROKU_APP = os.environ['HEROKU_APP'] 
remote_client = MongoClient(MONGODB_URI)
users = remote_client[HEROKU_APP].user

#-----------------------------------
def update_profile(username,profile):
 
	onename_username = 'u/' + username

	print onename_username
	print json.dumps(profile)
	
	#update_name does json.dumps internally
	#update_name(onename_username,profile)

#-----------------------------------
def update_profile_from_DB(username):

	entry = users.find_one({'username':username})
	profile = json.loads(entry['profile'])

	update_profile(username,profile)

#-----------------------------------
def update_profile_from_file(username,file_name='tools/json_profile.json'):

	json_data=open(file_name)
	profile = json.load(json_data)

	update_profile(username,profile)

#-----------------------------------
if __name__ == '__main__':

	username = 'danshipper'
	update_profile_from_DB(username)
	#update_profile_from_file(username)
{'fraction_non_alphanumeric': 0.21262458471760798, 'fraction_numerical': 0.0008305647840531562, 'mean_word_length': 3.413919413919414, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2324754', 'n_tokens_mistral': 381, 'n_tokens_neox': 368, 'n_words': 64}