# Path: event_store/models.py
# class Activist(models.Model):
#     hashed_email = models.CharField(max_length=64, null=True, blank=True,
#                                     help_text="sha256 hash hexdigest of the email address")
#     email = models.CharField(max_length=765, null=True, blank=True)
#     name = models.CharField(max_length=765, null=True, blank=True)
#     member_system_pk = models.CharField(max_length=765, null=True, blank=True)
#     member_system = models.ForeignKey('event_exim.EventSource', blank=True, null=True, db_index=True)
#     phone = models.CharField(max_length=75, null=True, blank=True)
# 
#     def __str__(self):
#         return self.name or 'Activist {}:{}'.format(str(self.member_system), self.member_system_pk)
# 
#     def hash(self_or_email, email=None):
#         """Should work as a class OR instance method"""
#         if email is None:
#             if hasattr(self_or_email, 'email'):
#                 email = getattr(self, 'email', None)
#                 if email is None:
#                     raise Exception("You need to set the email or send it as an argument")
#             else:
#                 email = self_or_email
#         return hashlib.sha256(email.encode('utf-8')).hexdigest()
# 
#     def likely_same(self, other):
#         eq_attrs = ('id', 'email', 'hashed_email', 'phone')
#         for attr in eq_attrs:
#             if getattr(self, attr) and getattr(self, attr)==getattr(other,attr,None):
#                 return True
#         if self.member_system and self.member_system_pk\
#            and self.member_system_id == getattr(other,'member_system_id', None)\
#            and self.member_system_pk == getattr(other,'member_system_pk', None):
#             return True
#         return False
# 
# CHOICES = {
#     'unknown': 0,
#     #venues
#     'private home': 1,
#     'public space': 2,
#     'target location (e.g. congressional district office)': 3,
#     'virtual': 4,
#     #ticket types
#     'open': 1,
#     'ticketed': 2,
#     #is_private
#     'public': 0,
#     'private': 1,
#     #is_searchable
#     'not searchable': 0,
#     'searchable': 1,
# }


import datetime
import json
import re
import time
import requests
from itertools import chain
from event_store.models import Activist, CHOICES
            'is_private': is_private,
            'is_approved': 1,
            'attendee_count': facebook_event.get('attending_count'),
            'max_attendees': None,
            'venue': facebook_event.get('place',{}).get('name',''),
            'public_description': facebook_event['description'],
            'directions': '',
            'note_to_attendees': '',
            'updated_at': datetime.datetime.strptime(facebook_event['updated_time'], DATE_FMT),
            'organization_official_event': TODO, # maybe if same org as page or is_owner
            'event_type': facebook_event.get('category'), # "EVENT_CAUSE", "CAUSES", "OTHER"
            'organization_host': self._convert_host(facebook_event), #TODO
            'organization_source': self.source,
            'organization_source_pk': facebook_event['id'],
            'organization': self.source.origin_organization,
            'organization_campaign': '', # maybe owner?
            'is_searchable': not is_private,
            'private_phone': '',
            'phone': '',
            'url': url,
            'slug': 'facebook-{}'.format(facebook_event['id']),
            'osdi_origin_system': 'facebook.com',
            # unknown unless we have a ticket uri
            'ticket_type': (CHOICES['ticketed']
                            if facebook_event.get('ticket_uri')
                            else CHOICES['unknown']),
            'share_url': url,
            'internal_notes': '',
            #e.g. NC cong district 2 = "ocd-division/country:us/state:nc/cd:2"
            'political_scope': None, #TODO: zip2district support

# Path: event_store/models.py
# class Activist(models.Model):
#     hashed_email = models.CharField(max_length=64, null=True, blank=True,
#                                     help_text="sha256 hash hexdigest of the email address")
#     email = models.CharField(max_length=765, null=True, blank=True)
#     name = models.CharField(max_length=765, null=True, blank=True)
#     member_system_pk = models.CharField(max_length=765, null=True, blank=True)
#     member_system = models.ForeignKey('event_exim.EventSource', blank=True, null=True, db_index=True)
#     phone = models.CharField(max_length=75, null=True, blank=True)
# 
#     def __str__(self):
#         return self.name or 'Activist {}:{}'.format(str(self.member_system), self.member_system_pk)
# 
#     def hash(self_or_email, email=None):
#         """Should work as a class OR instance method"""
#         if email is None:
#             if hasattr(self_or_email, 'email'):
#                 email = getattr(self, 'email', None)
#                 if email is None:
#                     raise Exception("You need to set the email or send it as an argument")
#             else:
#                 email = self_or_email
#         return hashlib.sha256(email.encode('utf-8')).hexdigest()
# 
#     def likely_same(self, other):
#         eq_attrs = ('id', 'email', 'hashed_email', 'phone')
#         for attr in eq_attrs:
#             if getattr(self, attr) and getattr(self, attr)==getattr(other,attr,None):
#                 return True
#         if self.member_system and self.member_system_pk\
#            and self.member_system_id == getattr(other,'member_system_id', None)\
#            and self.member_system_pk == getattr(other,'member_system_pk', None):
#             return True
#         return False
# 
# CHOICES = {
#     'unknown': 0,
#     #venues
#     'private home': 1,
#     'public space': 2,
#     'target location (e.g. congressional district office)': 3,
#     'virtual': 4,
#     #ticket types
#     'open': 1,
#     'ticketed': 2,
#     #is_private
#     'public': 0,
#     'private': 1,
#     #is_searchable
#     'not searchable': 0,
#     'searchable': 1,
# }


# Path: event_exim/connectors/facebook.py
import datetime
import json
import re
import time
import requests
from itertools import chain
from event_store.models import Activist, CHOICES

            'is_private': is_private,
            'is_approved': 1,
            'attendee_count': facebook_event.get('attending_count'),
            'max_attendees': None,
            'venue': facebook_event.get('place',{}).get('name',''),
            'public_description': facebook_event['description'],
            'directions': '',
            'note_to_attendees': '',
            'updated_at': datetime.datetime.strptime(facebook_event['updated_time'], DATE_FMT),
            'organization_official_event': TODO, # maybe if same org as page or is_owner
            'event_type': facebook_event.get('category'), # "EVENT_CAUSE", "CAUSES", "OTHER"
            'organization_host': self._convert_host(facebook_event), #TODO
            'organization_source': self.source,
            'organization_source_pk': facebook_event['id'],
            'organization': self.source.origin_organization,
            'organization_campaign': '', # maybe owner?
            'is_searchable': not is_private,
            'private_phone': '',
            'phone': '',
            'url': url,
            'slug': 'facebook-{}'.format(facebook_event['id']),
            'osdi_origin_system': 'facebook.com',
            # unknown unless we have a ticket uri
            'ticket_type': (CHOICES['ticketed']
                            if facebook_event.get('ticket_uri')
                            else CHOICES['unknown']),
            'share_url': url,
            'internal_notes': '',
            #e.g. NC cong district 2 = "ocd-division/country:us/state:nc/cd:2"
            'political_scope': None, #TODO: zip2district support

            'venue_category': CHOICES['unknown'],