-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvolunteer.py
More file actions
70 lines (61 loc) · 2.8 KB
/
volunteer.py
File metadata and controls
70 lines (61 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import pandas as pd
import os
from refugee import Refugee
import datetime
class Volunteer:
if os.path.exists("volunteers.csv"):
volunteers = pd.read_csv("volunteers.csv")
else:
volunteers = pd.DataFrame()
# figure out how to represent and store availability dates
def __init__(self, username, password, firstName, lastName, phone, camp, avail_startDate, avail_endDate):
self.username = username
self.password = password
self.firstName = firstName
self.lastName = lastName
self.phone = phone
self.camp = camp
self.avail_startDate = avail_startDate
self.avail_endDate = avail_endDate
self.active = True
self.status = "volunteer"
self.login = False
#self.loginname_exist = False
#make sure username created by using volunteer class directly is unique
if Volunteer.volunteers.empty or not any(Volunteer.volunteers['username'] == self.username):
# adding the volunteer to the volunteers df by turning it into separate df and concatenating the two
volunteer = {"username": self.username, "password": self.password, "firstname": self.firstName,
"lastname": self.lastName, "phone": self.phone, "camp": self.camp,
"avail_startDate": self.avail_startDate,
"avail_endDate": self.avail_endDate,"status": self.status, "active": self.active, "login": self.login}
df = pd.DataFrame([volunteer])
Volunteer.volunteers = pd.concat([Volunteer.volunteers, df], ignore_index=True)
# save df to csv file
Volunteer.volunteers.to_csv('volunteers.csv', index=False)
else:
print('The username already exists.')
@staticmethod
def create_profile(firstname, lastname, camp, condition, dependants):
return Refugee(firstname, lastname, camp, condition, dependants)
@staticmethod
def edit_info(username, key, value):
df = pd.read_csv("volunteers.csv")
df.loc[df.username == username, key] = value
df.to_csv("volunteers.csv", index=False)
@staticmethod
def date_is_valid(user, period, cur_date):
if period == "start":
date_column = "avail_endDate"
elif period == "end":
date_column = "avail_startDate"
df = pd.read_csv("volunteers.csv")
original_date = df.loc[df.username == user, date_column].values.item()
cur_date = datetime.datetime.strptime(cur_date, '%d/%m/%Y')
original_date = datetime.datetime.strptime(original_date, '%d/%m/%Y')
if period == "start":
if cur_date < original_date:
return True
if period == "end":
if cur_date > original_date:
return True
return False