from collections import Counter
from models.person import Person
import json

ids_json = open('ids_for_clustring.json').read()
ids = json.loads(ids_json)

person = Person.find(5)
all_tweets = person.tweets.all()

tweets = [t for t in all_tweets if t.tweet_id in ids]

all_hashtags = set()

clusters = {}
clusters_tweets = {}

for tweet in tweets:
    hashtags = tweet.hashtags()
    all_hashtags.update(hashtags)

    assigned_cluster = False

    for cluster in clusters:
        cluster_hashes = clusters.get(cluster)

        if set(hashtags) == set(cluster_hashes):
            clusters_tweets[cluster].append(tweet)
            assigned_cluster = True
            break