Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import happybase
- connection = happybase.Connection('localhost')
- new_id = raw_input('Enter id: \n')
- mytable = connection.table('mytable')
- d = mytable.row(new_id)
- def show():
- ems='';ps=''
- name = mytable.cells(new_id,'personal:name',1)
- age = mytable.cells(new_id,'personal:age',1)
- email = mytable.cells(new_id,'personal:email',2)
- phones = mytable.cells(new_id,'professional:contact',2)
- for val in email: ems=ems+val+','
- for val in phones: ps=ps+val+','
- ems=ems[0:len(ems)-1];ps=ps[0:len(ps)-1]
- if len(email)==0: ems='NA'
- print('Name: '+name[0]+'\n'+'Age: '+age[0]+'\n'+'Email-ID(s): '+ems+'\n'+'Contact No(s): '+ps)
- def delete():
- ans = raw_input('(1) Name\n(2) Age\n(3) Email\n(4) Contact No.\n')
- if ans == '1':
- mytable.delete(new_id,['personal:name'])
- elif ans == '2':
- mytable.delete(new_id,['personal:age'])
- elif ans == '3':
- mytable.delete(new_id,['personal:email'])
- elif ans == '4':
- mytable.delete(new_id,['professional:contact'])
- else: print('Wrong Choice. Exiting...')
- def update():
- ans = raw_input('(1) Name\n(2) Age\n(3) Email\n(4) Contact No.\n')
- if ans == '1':
- name = raw_input('Enter New Name: \n')
- mytable.put(new_id,{'personal:name':name})
- elif ans == '2':
- age = raw_input('Enter New Age: \n')
- mytable.put(new_id,{'personal:age':age})
- elif ans == '3':
- email = raw_input('Enter New Email: \n')
- mytable.put(new_id,{'personal:email':email})
- elif ans == '4':
- phone = raw_input('Enter New Contact No.: \n')
- mytable.put(new_id,{'professional:contact':phone})
- else: print('Wrong Choice. Exiting...')
- if len(d)!=0:
- print('ID already exists')
- ans = raw_input('Actions: \n(1) UPDATE\n(2) DELETE\n(3) SHOW\n(4) EXIT\n')
- if ans=='1': update()
- elif ans=='2': delete()
- elif ans=='3':show()
- else: pass
- else:
- name = raw_input('Enter your name:\n')
- age = raw_input('Enter your age:\n')
- email = raw_input('Enter your email:\n')
- phone = raw_input('Enter your contact:\n')
- families = {
- 'personal:name':name,
- 'personal:age':age,
- 'personal:email':email,
- 'professional:contact':phone,
- }
- mytable.put(new_id,families)
- connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement