12345678910111213141516171819202122232425262728293031 |
- def dob():
- if not os.path.exists('analytics'):
- os.mkdir('analytics')
- if os.path.exists('analytics/dob'):
- shutil.rmtree('analytics/dob')
- with open('studentinfo_cs384.csv', newline='') as csvfile:
- reader = csv.DictReader(csvfile)
- if not os.path.exists('analytics/dob'):
- os.mkdir('analytics/dob')
- for row in reader:
- l = list(row.values())
- head = list(row.keys())
- x = str(re.sub(r"\D","-",row['dob']))
- yr = int(x.split('-')[-1])
- k = int(yr)%10
- if k>4:
- name = 'bday_' + str(yr - k + 5) + '_' + str(yr - k + 9)
- else:
- name = 'bday_' + str(yr - k ) + '_' + str(yr - k + 4)
- if yr > 2014:
- name = 'bday_2015_2020'
- with open('analytics/dob/'+name+ '.csv', mode = 'a') as f:
- f_write = csv.writer(f, delimiter=',',lineterminator='\r')
- if os.path.getsize('analytics/dob/'+name+ '.csv')==0:
- f_write.writerow(head)
- f_write.writerow(l)
- f.close()
-
|