Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Project 1
- #
- # Sample data file
- # ----
- # Name: Carol
- # Gender: F
- # Country: USA
- # Acceptable_country: Singapore, China
- # Age: 23
- # Acceptable_age_range: 23-50
- # Likes: Chicken rice,hotpot, Carrot cake, chilli crab, roses, movies
- # Dislikes: football, hunting, swimming
- #
- # Books:
- # Christian reflections
- # The red tent
- # The God who is there
- # God in the Dock: Essays on Theology and Ethics
- # Total truth: liberating christianity from its cultural captivity
- # Redeeming love
- # ----
- # Keys:
- # 1. Name
- # 2. Gender
- # 3. Country
- # 4. Acceptable_country
- # 5. Age
- # 6. Acceptable_age_range
- # 7. Likes
- # 8. Dislikes
- # 9. Books
- # ----
- # how the dict should look like (please verify)
- # *not complete information
- # studentprofiles = {
- # "student1" : {
- # 'name' : 'Angela White',
- # 'gender' : 'F'
- # 'country' : ['Singapore', 'China', 'USA'],
- # 'age' : 22,
- # 'books' : ['xxx111', 'yyy222', 'zzz333']
- # },
- # "student2" : {
- # 'name' : 'Bobby Brown',
- # 'gender' : 'M'
- # 'country' : ['Singapore', 'China'],
- # 'age' : 24,
- # 'books' : ['Fat cat', 'Zack and Cody', 'Journey to the West']
- # }
- # }
- # Regex
- # This regex will sort each key pair value Country
- # Odd Number is Key, Even Number is Value
- # Use regex alr, sitll need to split the commas out
- # (Name:)(.*)\n+(Gender:)(.*)\n+(Country:)(.*)\n+(Acceptable_country:)(.*)\n+(Age:)(.*)\n+(Acceptable_age_range:)(.*)\n+(Likes:)(.*)\n+(Dislikes:)(.*)\n+(Books:)((?<=Books:)\D+)
- import os
- from os.path import isfile, join
- import sys
- import re
- # import subprocess as sp
- def exitProg():
- print('Thank you! Byebye!')
- print('================================')
- exitBit = 1
- return(exitBit)
- def welcomeMsg():
- print('Welcome to the program!')
- print('Press 1 for a list of the files in the PWD')
- print('Press 2 to view the student profiles')
- print('Press 3 to add a new student profile')
- print('Press 4 to delete a students profile')
- print('Press 5 to xxx')
- print('Press 10 to exit')
- def start():
- welcomeMsg()
- try:
- menuSelection = int(raw_input('Your selection? => '))
- if int(menuSelection) == 1: # maybe can allow user to input the dir also or use the default './SampleData'
- fileCounter = 1
- parent_dir = './SampleData'
- print('\n' * 100)
- print('================================')
- print('----------Start of Dir----------')
- data_file = [file for file in os.listdir('./SampleData/') if file.endswith('.txt')]
- for i in sorted(data_file):
- print("Data File %s => \"%s\"" % (fileCounter, i))
- fileCounter += 1
- print('-----------End of Dir-----------')
- print('================================')
- exitProg()
- elif int(menuSelection) == 2:
- counter = 1
- parent_dir = './SampleData/'
- print('================================')
- data_file = [file for file in os.listdir('./SampleData/') if file.endswith('.txt')]
- for i in sorted(data_file):
- print('-------------Student %d-------------' %counter)
- toread = parent_dir+i
- with open(toread) as f:
- for line in f:
- print line.rstrip('\n\r')
- print('---------end of Student %d----------' %counter)
- counter += 1
- print('================================')
- exitProg()
- elif int(menuSelection) == 3:
- print('\n' * 100)
- print('================================')
- print('Nothing here yet!')
- print('We\'ll let you choose again!')
- print('================================')
- start()
- elif int(menuSelection) == 4:
- print('\n' * 100)
- print('================================')
- print('Nothing here yet!')
- print('We\'ll let you choose again!')
- print('================================')
- start()
- elif int(menuSelection) == 5:
- print('\n' * 100)
- print('================================')
- print('Nothing here yet!')
- print('We\'ll let you choose again!')
- print('================================')
- start()
- elif int(menuSelection) == 10:
- print('================================')
- exitProg()
- else:
- print('\n' * 100)
- print('================================')
- print('Invalid selection.')
- print('Please choose again!')
- print('================================')
- start()
- except:
- print('\n' * 100)
- print('================================')
- print('Something went wrong!')
- print('Please choose again!')
- print('================================')
- start()
- print(sys.version)
- print('================================')
- exitBit = 0
- if exitBit > 0:
- sys.exit()
- else:
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement