def extend_conversations(conversations_collection, data, only_new=False): if only_new: only_new_filter = lambda x: not TinderDb.match_exists(x['id']) conversations_collection.extend([{'id': m['id'], 'name': m['person']['name']} for m in data['data']['matches'] if only_new_filter(m)]) else: conversations_collection.extend([{'id': m['id'], 'name': m['person']['name']} for m in data['data']['matches']])
def handle(tinder_client, match_id): if TinderDb.match_exists(match_id=match_id): return replicas_for_tinder = MessageProvider.messages_for_tinder() girl_responses, my_requests, whole_conversation = tinder_client.get_messages( match_id) match_id = whole_conversation[0]['match_id'] replicas_sent_quantity = ConversationHandler._count_my_replicas_sent( whole_conversation, tinder_client) if replicas_sent_quantity == 0: tinder_client.send_message(match_id, replicas_for_tinder[0]) StatisticsDb.increase_new_matches( ) # i did not send anything but conversation exists, so she was first return my_last_replica_replied = ConversationHandler._replica_was_replied( whole_conversation, tinder_client, replicas_sent_quantity) if my_last_replica_replied: if replicas_sent_quantity >= MessageProvider.notification_threshold( ): if NotificationQueue.try_add(tinder_client, match_id, girl_responses, whole_conversation): return if (replicas_sent_quantity + 1) <= len(replicas_for_tinder): '''replica indexes starts from 0 and if we already sent one replica, then we should send second replica, which index will be 1''' tinder_client.send_message( match_id, replicas_for_tinder[replicas_sent_quantity])