I need to generate a function that finds the employee who is free for a meeting based on the following data. If I pass a valid time, it should return back who is free during that hour.
1234 Mon-Tue 09:30 am - 1:00 pm
2345 Mon-Thu 1:00 pm - 3:00 pm , Fri 10:30 am - 3:00 pm
456 Mon-Wed 9:00 am - 9:30 am , Tue 10:00 am - 3:00 pm , Fri 10:00 am - 2:00 pm
I need to split the second value, i.e free time and check if the user is free.
My challenge is around how do I split semi structured data into a list and search my desired value.
Thanks,
What I have tried:
This is what I tried.
# My data in myfile.csv
"""
user1 Mon-Tue 11:30 am - 1:00 pm
user2 Mon-Thu 2:00 pm - 3:00 pm , Fri 11:30 am - 4:00 pm
user3 Mon-Wed 9:00 am - 9:30 am , Tue 10:00 am - 3:00 pm , Fri 10:00 am - 2:00 pm
user4 Mon 10:00 am - 10:30 am , Tue 1:00 pm - 3:00 pm , Fri 9:00 am - 10:00 am
user5 Fri 11:00 am - 11:30 am
user6 Mon-Fri 9:00 am - 4:30 pm
user7 Mon-Wed 10:30 am - 11:30 am , Tue 11:30 am - 3:00 pm , Fri 10:00 am - 2:00 pm
user8 Mon 10:30 am - 11:30 am , Tue 10:00 am - 3:00 pm , Fri 11:00 am - 2:00 pm
user9 Mon-Wed 9:00 am - 9:30 am , Tue 10:00 am - 3:00 pm , Fri 10:00 am - 2:00 pm
user10 Tue-Wed 10:00 am - 11:30 am , Fri 10:00 am - 2:00 pm
user11 Wed 11:00 am - 3:30 pm , Fri 11:00 am - 2:00 pm
user12 Mon 9:00 am - 3:30 pm , Fri 11:00 am - 2:00 pm
user13 Fri 11:00 am - 3:30 pm
user14 Wed 12:00 am - 12:30 pm
user16 Fri 10:00 am - 12:00 pm
"""
import csv
import re
userid = []
dates = []
num = []
let = []
pattern = re.compile(r'\b([A-Z][a-z]{2})\s*((-)\s*([A-Z][a-z]{2}))?\s*(\d?\d:\d\d *[aApP][Mm])')
with open('myfile.csv') as csvDataFile:
csvReader = csv.reader(csvDataFile)
for row in csvReader:
userid.append(row[0])
list_val = [item.strip() for item in row[1].split(',')]
dates.append(list_val)
print dates, list_val
a = filter(pattern.match,dates)
print str(a)
for (letters, numbers) in filter(pattern.match,dates):
num.append(numbers)
let.append(letters)
print(numbers, '*', letters)