コード例 #1
0
 def test_contactlist_search(self):
     self.assertEqual(len(Contact.all_contacts.search('John')), 0)
     contact1 = Contact("Some Body", "*****@*****.**")
     contact2 = Contact("Sandor Brody", "*****@*****.**")
     contact3 = Contact("Elek Benedek", "*****@*****.**")
     self.assertEqual(len(Contact.all_contacts.search('John')), 0)
     self.assertEqual(len(Contact.all_contacts.search('Benedek')), 1)
コード例 #2
0
def main():
    # create list
    l = List()
    list_name = 'My First List'
    list_name = add_my_list(l, list_name)

    for resp_val in json.loads(l.list().text):
        if resp_val.isdigit():
            # print(json.loads(l.list().text)[resp_val]['name'], list_name)
            if json.loads(l.list().text)[resp_val]['name'] == list_name:
                new_list_id = json.loads(l.list().text)[resp_val]['id']
                # print(new_list_id)

    c = Contact()
    contacts_file = os.path.dirname(os.path.realpath(__file__)) + '/contacts.csv'
    with open(contacts_file, 'r') as f:
        for line in f.readlines():
                resp = c.add(line, new_list_id)
                if json.loads(resp.text)['result_code'] == 1:
                    print(line, 'successfully added!')
                else:
                    print(line, "didn't get added. Message was: ", json.loads(resp.text)['result_message'])


    addr = Address()
    resp = addr.add('Kevin Inc', new_list_id)
    print(json.loads(resp.text)['result_message'])

    camp = Campaign()
    resp = camp.add('My Campaign', new_list_id)
    print(json.loads(resp.text)['result_message'])
コード例 #3
0
 def test_all_contacts(self):
     contact1 = Contact("Some Body", "*****@*****.**")
     self.assertEqual(len(contact1.all_contacts), 1)
     contact2 = Contact("Sandor Brody", "*****@*****.**")
     self.assertEqual(len(Contact.all_contacts), 2)
     contact3 = Contact("Elek Benedek", "*****@*****.**")
     self.assertEqual(len(Contact.all_contacts), 3)
コード例 #4
0
ファイル: contact_test.py プロジェクト: SamNgigi/Contact-List
 def test_save_multiple_contacts(self):
     # Saving our setUp contact
     self.new_contact.save_contact()
     # Adding another contact
     self.added_contact = Contact("Ethan", "Hunt", "0786474",
                                  "*****@*****.**")
     # Saving our new contact
     self.added_contact.save_contact()
     # Checking to see if the length of our array has increased.
     self.assertEqual(len(Contact.contact_list), 2)
コード例 #5
0
ファイル: contact_test.py プロジェクト: SamNgigi/Contact-List
    def setUp(self):
        """  
      Set up method to run before each test case.

      We create our contact object instance that we will use to conduct to test different aspects of our Contact class.
    """

        # Create an object instance new_contact of class Contact
        self.new_contact = Contact("James", "Bond", "007007007",
                                   "*****@*****.**")
コード例 #6
0
ファイル: contact_test.py プロジェクト: SamNgigi/Contact-List
    def test_copy_email(self):
        """  
      Testing to see if our copying function is able to copy email address from a found contact.
    """

        self.new_contact.save_contact()
        Contact.copy_email("007007007")
        """  
      pyperclip.paste returns whatever is copied on the machine's clipboard at that time.
    """
        self.assertEqual(self.new_contact.email, pyperclip.paste())
コード例 #7
0
ファイル: interface.py プロジェクト: dibyendu/WayToSms
 def add_contacts(self):
     database = DataBase()
     for contacts in self.__contact_box.get_children():
         contacts.hide_all()
         self.__contact_box.remove(contacts)
         contacts.destroy()
     for contacts in database.select_rows('contacts'):
         from contacts import Contact
         contact = Contact(contacts)
         contact.connect('toggle', self._append_number_to_receivers)
         self.__contact_box.pack_start(contact, False, False)
     self.__contact_box.show_all()
コード例 #8
0
ファイル: contact_test.py プロジェクト: SamNgigi/Contact-List
 def test_delete_contact(self):
     #Saving our setUp contact
     self.new_contact.save_contact()
     # Adding another contact
     self.added_contact = Contact("Ethan", "Hunt", "0786474",
                                  "*****@*****.**")
     # Saving our new contact
     self.added_contact.save_contact()
     # Calling our delete_contact function
     self.new_contact.delete_contact()
     # Checking to see if the length of our array has reduced
     self.assertEqual(len(Contact.contact_list), 1)
コード例 #9
0
ファイル: contact_test.py プロジェクト: SamNgigi/Contact-List
    def test_contact_exists(self):
        """  
      Tests if the contact_exists will return a boolean depending on
      whether or not a contact is found when a number is passed.
    """
        self.new_contact.save_contact()

        self.added_contact = Contact("Ethan", "Hunt", "0786474",
                                     "*****@*****.**")
        self.added_contact.save_contact()
        existing_contact = Contact.contact_exists("007007007")
        """  
      Here we use the assertTrue method for a change. that should return a boolean
    """
        self.assertTrue(existing_contact)
コード例 #10
0
 def __init__(self, *args, **kwargs):
     super(MainWindow, self).__init__(*args, **kwargs)
     self.setupUi(self)
     self.pushButton_addCon.clicked.connect(self.setup_contact)
     self.contact = Contact(self)
     self.contacts = self.contact.query.all()
     self.populateList(self.contacts)
コード例 #11
0
def update_entry(uuid):
    """Update contact information and return uuid of person
    on success, otherwise error code with description.
    Request format (first two fields are obligatory):
    {"name": <name>, "surname": <surname>, "country": <country>, ...}
    """
    return Contact().update_contact(uuid, **request.json)
コード例 #12
0
def get_entry(uuid):
    """Get person's details by person's uuid and return responce with
    all set fields on success, otherwise corresponding error code with
    description. Reply format:
    {"name": <name>, "surname": <surname>, "country": <country>, ...}
    """
    return Contact().get_contact(uuid)
コード例 #13
0
def main(argv):

    parser = make_argparser()
    args = parser.parse_args(argv[1:])

    logging.basicConfig(stream=args.log,
                        level=args.volume,
                        format='%(message)s')

    book = get_contacts(args.contacts)

    if args.get:
        key, value = args.get
        if not key.endswith('s'):
            logging.warning(
                f'Warning: --get keys must be plural. Saw: {key!r}')
        if key == 'phones':
            value = Contact.normalize_phone(value)
        for contact in book.get_all(key, value):
            print(contact.format())
    else:
        for contact in book:
            if args.name:
                if contact.name and contact.name.lower() == args.name.lower():
                    print(contact.format())
            else:
                print(contact)
コード例 #14
0
ファイル: run.py プロジェクト: SamNgigi/Contact-List
def create(first_name, last_name, phone_number, email_address):
    """  
    Function to create new contact
  """

    new_contact = Contact(first_name, last_name, phone_number, email_address)
    return new_contact
コード例 #15
0
    def testSaveLoad(self):
        contactsList = ContactList()

        self.assertEqual({}, contactsList.contacts)
        contactsList.addContact(Contact('name1', "1234"))
        contactsList.addContact(Contact('name2', "2345"))
        contactsList.addContact(Contact('name3', "3456"))

        contactsList.save('contactsTest.csv')

        contactListLoaded = ContactList()
        contactListLoaded.load('contactsTest.csv')

        self.assertEqual(3, len(contactListLoaded.contacts))
        self.assertEqual('1234', contactListLoaded.contacts['name1'])
        self.assertEqual('2345', contactListLoaded.contacts['name2'])
        self.assertEqual('3456', contactListLoaded.contacts['name3'])
コード例 #16
0
    def testMergeLists(self):
        contactList1 = ContactList()
        contactList1.addContact(Contact('name1', "1234"))
        contactList1.addContact(Contact('name2', "2345"))
        contactList1.addContact(Contact('name3', "3456"))

        contactList2 = ContactList()
        contactList2.addContact(Contact('name1', "6789"))
        contactList2.addContact(Contact('name2', "6789"))
        contactList2.addContact(Contact('name3', "6789"))

        contactList1.mergeContacts(contactList2)
        self.assertEqual(3, len(contactList1.contacts))
        self.assertEqual('1234', contactList1.contacts['name1'])
        self.assertEqual('2345', contactList1.contacts['name2'])
        self.assertEqual('3456', contactList1.contacts['name3'])

        contactList2.addContact(Contact('name4', "6789"))

        contactList1.mergeContacts(contactList2)
        self.assertEqual(4, len(contactList1.contacts))
        self.assertEqual('1234', contactList1.contacts['name1'])
        self.assertEqual('2345', contactList1.contacts['name2'])
        self.assertEqual('3456', contactList1.contacts['name3'])
        self.assertEqual('6789', contactList1.contacts['name4'])
コード例 #17
0
def create_entry():
    """Add person. Operation generates uuid for person and returns it
       on success, otherwise error code with description.
       Request format (first two fields are obligatory):
       {"name": <name>, "surname": <surname>, "country": <country>, ...}
    """
    uuid = helpers.getuuid(request.json['name'], request.json['surname'])

    return Contact().add_contact(uuid, **request.json)
コード例 #18
0
def get_contacts_dict(directory):
    contacts.database.init(directory + "wa.db")
    contacts_dict = {}

    query = Contact.select()
    for contact in query:
        contacts_dict[contact.jid] = contact

    return contacts_dict
コード例 #19
0
def participant_to_contact(participant, book):
  if participant is None:
    raise ValueError(f'No participant!')
  name = participant.name
  phone = Contact.normalize_phone(participant.phone)
  gaia_id = participant.gaia_id
  # Check if the contact already exists.
  # First, try looking it up by name:
  name_results = book.get_all('names', name)
  for result in name_results:
    # If we found results, add the phone number and gaia_id.
    if phone and phone not in result['phones']:
      result['phones'].add(phone)
    if gaia_id and gaia_id not in result['gaia_ids']:
      result['gaia_ids'].add(gaia_id)
  # Then try looking up by phone number:
  phone_results = book.get_all('phones', phone)
  for result in phone_results:
    # If we found results, add the name and gaia_id.
    if name and not result.name:
      result.name = name
    if gaia_id and gaia_id not in result['gaia_ids']:
      result['gaia_ids'].add(gaia_id)
  # Finally, try looking up by gaia_id:
  gaia_results = book.get_all('gaia_ids', gaia_id)
  for result in gaia_results:
    # If we found results, add the name and phone number.
    if name and not result.name:
      result.name = name
    if phone and phone not in result['phones']:
      result['phones'].add(phone)
  # Return the first name result, first gaia result, first phone result, or if no hits,
  # make and add a new Contact.
  if name_results:
    return name_results[0]
  elif gaia_results:
    return gaia_results[0]
  elif phone_results:
    return phone_results[0]
  else:
    contact = Contact(name=name, phone=phone, gaia_id=gaia_id)
    book.add(contact)
    return contact
コード例 #20
0
ファイル: contact_test.py プロジェクト: SamNgigi/Contact-List
    def test_find_contact_by_number(self):
        """ 
      Test find_contact by number method that is meant to return a
      contact when given a number.
    """

        self.new_contact.save_contact()

        self.added_contact = Contact("Ethan", "Hunt", "0786474",
                                     "*****@*****.**")

        self.added_contact.save_contact()

        found_contact = Contact.find_by_number("0786474")
        """  
      Since we know that add_contact number is 0786474 with email
      [email protected], found contact method should return the same email.
    """
        self.assertEqual(found_contact.email, self.added_contact.email)
コード例 #21
0
def get_entries():
    """Get list of persons with available information on success,
    otherwise corresponding error code with description. Reply format:
    {<uuid>: {"name": <name>, "surname": <surname>, "country": <country>,...}}.

    Request format:
    {"limit": <limit>, "offset": <offset>}
    Parameter "offset" is optional.
    """
    return Contact().get_contacts(**request.json)
コード例 #22
0
def parse_aliases(aliases_str, contacts):
  if not aliases_str:
    return
  for keyvalue in aliases_str.split(','):
    try:
      alias, name = keyvalue.split('=')
    except ValueError:
      continue
    if re.search(r'^\d{19,23}$', alias):
      contact = Contact(name=name, gaia_id=alias)
      contact['gaia_id'].indexable = True
    elif re.search(r'[0-9+() -]{7,25}', alias) and 7 <= len(re.sub(r'[^0-9]', '', alias)) <= 18:
      phone = Contact.normalize_phone(alias)
      contact = Contact(name=name, phone=phone)
    elif re.search(r'[^:/]+@[a-zA-Z0-9.-]+', alias):
      contact = Contact(name=name, email=alias)
    else:
      fail('Unrecognized alias type: {!r}'.format(alias))
    contacts.add_or_merge(contact)
コード例 #23
0
def get_contacts(csv_file):
    #TODO: Allow adding to existing ContactBook.
    book = ContactBook()
    #TODO: Some special handling for phone numbers, emails, addresses to put the preferred one first.
    for row in read_csv(csv_file):
        contact = Contact()
        # Name
        if row.get('Name'):
            contact.name = row['Name']
        elif row.get('Organization 1 - Name'):
            contact.name = row['Organization 1 - Name']
        # Phone numbers
        parse_values(row,
                     contact,
                     'phones',
                     'Phone',
                     converter=Contact.normalize_phone)
        # Emails
        parse_values(row, contact, 'emails', 'E-mail')
        # Addresses
        parse_values(row,
                     contact,
                     'addresses',
                     'Address',
                     value_label='Formatted')
        # Organization
        parse_values(row,
                     contact,
                     'organizations',
                     'Organization',
                     value_label='Name')
        # Relationship
        # Note: There are instances where there's no Type, but there is a Value.
        # But currently no instances where there's a Value but no Type.
        parse_values(row, contact, 'relations', 'Relation')
        # Note
        if row.get('Note'):
            contact['notes'].add(row['Notes'])
        book.add(contact)
    return book
コード例 #24
0
def by_name(name):
    print(name)
    output = '''
    <h1>Info about name_var</h1>
    <ul>
        <li>Food: food_var</li>
        <li>Game: game_var</li>
    </ul>
    '''
    found_contact = Contact.find_contact(name)
    output = output.replace('name_var', found_contact.name_attr)
    output = output.replace('food_var', found_contact.food_attr)
    output = output.replace('game_var', found_contact.game_attr)
    return output
コード例 #25
0
    def addContact(self):
        fName = self.lineEdit.text()
        lName = self.lineEdit_2.text()
        email = self.lineEdit_2.text()
        mobile = self.lineEdit_2.text()
        address = self.textEdit.toPlainText()
        # print(address)
        # print(type(address))
        # data_holder = Contact()
        cont = Contact(fName, lName, email, mobile, address)
        db_session.add(cont)
        db_session.commit()

        print("human contact added to db")
        self.close()
コード例 #26
0
def by_id(contact_id):
    print(contact_id)

    output = '''
    <ul>
        <li>Food: food_var</li>
        <li>Game: game_var</li>
    </ul>
    '''

    found_contact = Contact.find_by_id(contact_id)
    output = output.replace('name_var', found_contact.name_attr)
    output = output.replace('food_var', found_contact.food_attr)
    output = output.replace('game_var', found_contact.game_attr)
    return output
コード例 #27
0
    def testMergeListsWithCollisionsResolving(self):
        contactList1 = ContactList()
        contactList1.addContact(Contact('name1', "1234"))
        contactList1.addContact(Contact('name2', "2345"))
        contactList1.addContact(Contact('name3', "3456"))

        contactList2 = ContactList()
        contactList2.addContact(Contact('name1', "6789"))
        contactList2.addContact(Contact('name2', "6789"))
        contactList2.addContact(Contact('name3', "6789"))

        resolvedCollisions = ContactList()
        resolvedCollisions.addContact(Contact('name1', "1234"))
        resolvedCollisions.addContact(Contact('name2', "6789"))
        resolvedCollisions.addContact(Contact('name3', "6789"))

        contactList1.mergeContacts(contactList2, resolvedCollisions)
        self.assertEqual(3, len(contactList1.contacts))
        self.assertEqual('1234', contactList1.contacts['name1'])
        self.assertEqual('6789', contactList1.contacts['name2'])
        self.assertEqual('6789', contactList1.contacts['name3'])
コード例 #28
0
def parse_mynumbers(mynumbers_str, contacts):
  if mynumbers_str is None:
    return
  mynumbers = [Contact.normalize_phone(number) for number in mynumbers_str.split(',')]
  if contacts.me is None:
    for phone in mynumbers:
      result = contacts.get('phones', phone)
      if result:
        result.is_me = True
        contacts.me = result
        break
  if contacts.me is None:
    return
  for phone in mynumbers:
    if phone not in contacts.me['phones']:
      contacts.me['phones'].add(phone)
コード例 #29
0
ファイル: skylibprotocol.py プロジェクト: sgricci/digsby
 def OnPropertyChange(self, prop):
     print self, prop, getattr(self.skyacct, prop)
     if prop == 'status' and self.skyacct.status in ('LOGGED_IN', 7):
         self.change_state(self.Statuses.LOADING_CONTACT_LIST)
         self.self_buddy = SkypeBuddy(
             self.skylib.GetContact(self.skyacct.skypename), self)
         d = {self.self_buddy.name: self.self_buddy}
         g = []
         for c in self.skylib.GetHardwiredContactGroup(
                 'SKYPE_BUDDIES').GetContacts():
             b = SkypeBuddy(c, self)
             d[b.name] = b
             g.append(Contact(b, b.name))
         self.buddies.update(d)
         with self.root_group.frozen():
             self.root_group[:] = g
         self.cs = []
         for c in self.skylib.GetConversationList('ALL_CONVERSATIONS'):
             c.OnMessage = self.a_message
             self.cs.append(c)
         self.change_state(self.Statuses.ONLINE)
     if prop == 'status' and self.skyacct.status == 'LOGGED_OUT':
         print self.skyacct.logoutreason
         self.set_offline(getattr(self.Reasons, self.skyacct.logoutreason))
コード例 #30
0
    def testFindCollisions(self):
        contactList1 = ContactList()
        contactList1.addContact(Contact('name1', "1234"))
        contactList1.addContact(Contact('name2', "2345"))
        contactList1.addContact(Contact('name3', "3456"))

        contactList2 = ContactList()

        self.assertEqual(0, len(contactList1.findCollisions(contactList2)))

        contactList2.addContact(Contact('name1', "6789"))
        contactList2.addContact(Contact('name2', "2345"))
        contactList2.addContact(Contact('name4', "1234"))

        collisions = contactList1.findCollisions(contactList2)
        self.assertEqual(1, len(collisions))
        self.assertEqual("name1", collisions[0].name)
        self.assertEqual("1234", collisions[0].phoneNumber1)
        self.assertEqual("6789", collisions[0].phoneNumber2)
コード例 #31
0
 def test_contact_entries(self):
     contact = Contact("Some Body", "*****@*****.**")
     self.assertEqual(hasattr(contact, 'name'), True)
     self.assertEqual(hasattr(contact, 'email'), True)
     self.assertEqual(contact.name, "Some Body")
     self.assertEqual(contact.email, "*****@*****.**")
コード例 #32
0
ファイル: SSIItem.py プロジェクト: niterain/digsby
 def __init__(self, *a, **k):
     Contact.__init__(self, *a, **k)
     self.ssis = self.protocol.ssimanager.ssis
     self.remote_alias  # side effects on buddy
コード例 #33
0
ファイル: SSIItem.py プロジェクト: niterain/digsby
 def rename_gui(self):
     s = Contact.rename_gui(self)
     if s is not None:
         self.remote_alias = s
コード例 #34
0
ファイル: yahoobuddy.py プロジェクト: AlexUlrich/digsby
 def unblock(self, *a,**k):
     return Contact.unblock(self, *a, **k)
コード例 #35
0
ファイル: yahoobuddy.py プロジェクト: AlexUlrich/digsby
 def block(self, *a,**k):
     return Contact.block(self, *a, **k)
コード例 #36
0
ファイル: yahoobuddy.py プロジェクト: AlexUlrich/digsby
 def __init__(self, buddy, group):
     Contact.__init__(self, buddy, (group, buddy.name))
     self.group = group
コード例 #37
0
ファイル: items.py プロジェクト: HackLinux/chandler-1
 def getCurrentMeContact(self, view):
     """
       Lookup the current "me" Contact.
     """
     from contacts import Contact
     return Contact.getCurrentMeContact(view)
コード例 #38
0
ファイル: test.py プロジェクト: stryder25/contacts
contact1info["home"] = "4567"
contact1info["work"] = "4567"
contact1info["cell"] = "4567"
contact1info["group"] = groups

groups = ["This"]
contact2info = {}
contact2info["first"] = "Andrew"
contact2info["last"] = "Gardner"
contact2info["home"] = "4567"
contact2info["work"] = "4567"
contact2info["cell"] = "4567"
contact2info["group"] = groups

contact1 = Contact(contact1info)
contact2 = Contact(contact2info)

print(contact1)

print(contact2.print_details())


groupA = Group("theName")
groupA.add(contact1)
groupA.add(contact2)

print(groupA)
print("".join([str(l) for l in groupA.search("first", "ndrew")]))
print("".join([str(l) for l in groupA.search("last", "Gardner")]))
print("".join([str(l) for l in groupA.search("home", "4567")]))
print("".join([str(l) for l in groupA.search("work", "4567")]))