예제 #1
0
 def test_friends_with_incomplete_bdate_field(self):
     response = [
         {'id': 1, 'first_name': '', 'last_name': '', 'bdate': '15.1', 'online': 0},
         {'id': 2, 'first_name': '', 'last_name': '', 'bdate': '3.9', 'online': 0},
     ]
     with patch('age.get_friends', return_value=response):
         predicted_age = age_predict(user_id=1)
         self.assertEqual(predicted_age, None)
예제 #2
0
 def test_friends_with_bdate_field(self):
     today = dt.date.today()
     yesterday = dt.date(day=today.day-1, month=today.month, year=1996).strftime('%d.%m.%Y')
     tomorrow = dt.date(day=today.day+1, month=today.month + 1, year=1992).strftime('%d.%m.%Y')
     response = [
         {'id': 1, 'first_name': '', 'last_name': '', 'bdate': yesterday, 'online': 0},
         {'id': 2, 'first_name': '', 'last_name': '', 'bdate': tomorrow, 'online': 0},
         {'id': 3, 'first_name': '', 'last_name': '', 'bdate': '11.11', 'online': 0},
         {'id': 4, 'first_name': '', 'last_name': '', 'online': 0},
     ]
     with patch('age.get_friends', return_value=response):
         predicted_age = age_predict(user_id=1)
         self.assertEqual(predicted_age, 23.5)
예제 #3
0
 def test_empty_response(self):
     response = []
     with patch('age.get_friends', return_value=response):
         predicted_age = age_predict(user_id=1)
         self.assertEqual(predicted_age, None)
예제 #4
0
from network import get_network, plot_graph
from api import get_friends, get_wall
from age import age_predict
from api_models import normalize

print('test age_predict')
print(age_predict(125483792))

print('test graph')
friends = get_friends(125483792, 'id')['response']
users_ids = []
names = []
k = 0
for friend in friends['items']:
    users_ids.append(friend['id'])
    names.append(friend['first_name'] + ' ' + friend['last_name'])
    k += 1
    if k == 50:
        break
edges = get_network(users_ids, as_edgelist=True)
plot_graph(edges, names)
'''
with open('1.txt', 'w') as f:
    post_list = get_wall(domain='pn6', count=5)
    f.writelines(normalize(post_list))
'''
예제 #5
0
파일: My.py 프로젝트: Henk0/cs102
from age import age_predict
from api import messages_get_history, get_friends
from messages import count_dates_from_messages, plotly_messages_freq
from api_models import Message
from network import get_network, plot_graph

print(age_predict(155393609))
history = messages_get_history(155393609, count=300)
mlist = [Message(**mes) for mes in history]
dates = count_dates_from_messages(mlist)
plotly_messages_freq(dates[0], dates[1])

friends = get_friends(155393609, fields='bdate')['response']['items']
ids = []
names = []
for friend in friends:
    ids.append(friend['id'])
    names.append(friend['first_name'] + ' ' + friend['last_name'])
edges = get_network(ids)
plot_graph(edges, names)