Ejemplo n.º 1
0
    def test_dates_and_frequencies(self):
        message = {
            'id': 1,
            'peer_id': 123456,
            'from_id': 123456,
            'text': 'Test message',
            'random_id': 17,
            'important': False
        }

        random.seed(17)
        messages = []
        for n in range(10):
            delta_ts = random.randint(86400, 604800)
            ts = int(1543611600 + delta_ts * random.choice([1, -1]))
            date = {'date': ts}
            messages.append(Message(**{**message, **date}))

        dates, freq = count_dates_from_messages(messages)
        self.assertEqual(sorted(freq), [1, 1, 1, 2, 2, 3])
        self.assertEqual(
            set(dates), {
                dt.date(2018, 11, 24),
                dt.date(2018, 11, 25),
                dt.date(2018, 11, 26),
                dt.date(2018, 11, 28),
                dt.date(2018, 12, 2),
                dt.date(2018, 12, 3)
            })
Ejemplo n.º 2
0
 def test_empty_history(self):
     dates, freq = count_dates_from_messages([])
     self.assertEqual(dates, [])
     self.assertEqual(freq, [])
Ejemplo n.º 3
0
from api import messages_get_history
from api_models import Message
from messages import count_dates_from_messages, plotly_messages_freq

messages = messages_get_history(505540783, offset=10, count=50)
messages_list = [Message(**mes) for mes in messages]
dates_freqs = count_dates_from_messages(messages_list)
plotly_messages_freq(dates_freqs[0], dates_freqs[1])
Ejemplo n.º 4
0
Archivo: My.py Proyecto: 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)