Skip to content

Commit

Permalink
Get_appended_humans_by_period
Browse files Browse the repository at this point in the history
  • Loading branch information
FirelCrafter committed Feb 6, 2021
1 parent 0298a8f commit 15f4ff1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Humans
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1 Baraka Vongo 10.10.1991 2021-02-05
1 Baraka Vongo 10/10/1991 6/2/2021
4 changes: 3 additions & 1 deletion base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,13 @@ def exists(self, humans):
return None

def add_to_base(self):
now = d.datetime.now()
with open('Humans') as f:
size = sum(1 for string in f)
self.id = size + 1
f = open('Humans', 'a+')
f.write(' '.join([str(self.id), self.f_name, self.l_name, str(self.d_birth)]) + ' ' + str(d.date.today()) + '\n')
f.write(' '.join([str(self.id), self.f_name, self.l_name, str(self.d_birth)])
+ ' ' + '{}/{}/{}'.format(now.day, now.month, now.year) + '\n')
f.close()
print('ID# {} {} {} Date of birth: {} is added to Database'
.format(self.id, self.f_name, self.l_name, self.d_birth))
Expand Down
12 changes: 12 additions & 0 deletions engine.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from prettytable import PrettyTable
from base import Filter, Human, Crime
from datetime import datetime, time, date


def get_humans():
Expand Down Expand Up @@ -109,3 +110,14 @@ def search_human(base, name):
return 'Do you mean: ' + ', '.join(rec_names).strip(', ') + ' ?'
else:
return 'Person with name: {} not found.'.format(f.name)


def get_humans_by_period(from_date, to_date, humans):
found_humans = []
for human in humans:
get_date = datetime.strptime(human[4], '%d/%m/%Y')
diff1 = to_date - get_date
diff2 = to_date - from_date
if diff1 <= diff2:
found_humans.append(human)
return found_humans
23 changes: 20 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import engine
from base import Base, Filter
import datetime
from datetime import datetime, time, date

########################################################################################################################

Expand All @@ -11,7 +11,8 @@
+ '3. Watch humans' + '\n'
+ '4. Watch crimes' + '\n'
+ '5. Find human by name' + '\n'
+ '6. Get crimes by date')
+ '6. Get crimes by date' + '\n'
+ '7. Get humans by period')
base = Base()

while True:
Expand Down Expand Up @@ -49,7 +50,9 @@

elif choice == '5':
name = input('Input name: ')
print(engine.search_human(base, name))
print(engine.search_human(base, name))

#############################################

elif choice == '6':
crimes = engine.get_crimes()
Expand All @@ -61,6 +64,20 @@
print(engine.print_crimes(found))
else:
print('Crimes for date: {} not found'.format(date))

##################################################

elif choice == '7':
humans = engine.get_humans()
if humans:
from_date = datetime.strptime(input('Enter start period date (DD/MM/YYYY): '), '%d/%m/%Y')
to_date = datetime.strptime(input('Enter end period date: '), '%d/%m/%Y')
found_humans = engine.get_humans_by_period(from_date=from_date, to_date=to_date, humans=humans)
if found_humans:
print(engine.print_humans(found_humans))
else:
print('Humans not found')

else:
print('Wrong number')

Expand Down

0 comments on commit 15f4ff1

Please sign in to comment.