-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from tylerlight071/Features
Database Uplink + Password Hashing
- Loading branch information
Showing
12 changed files
with
563 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,5 +160,5 @@ cython_debug/ | |
#.idea/ | ||
|
||
# User Files | ||
*.json | ||
*.txt | ||
audit_log.txt | ||
config.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,49 @@ | ||
import json | ||
import os | ||
import time | ||
from colorama import Fore, Style | ||
from common_functions import clear_screen, load_data, save_data | ||
from sudo_user import sudo_user | ||
from common_functions import clear_screen, load_animal_data, save_data, log_action | ||
from pymongo import MongoClient | ||
from config import mongodb_uri | ||
|
||
ANIMAL_DATA_FILE = "animals.json" | ||
# Connect to MongoDB | ||
uri = mongodb_uri | ||
client = MongoClient(uri) | ||
|
||
db = client['animal_rescue'] | ||
animals_collection = db['animals'] | ||
|
||
def change_adopted_status(): | ||
clear_screen() | ||
|
||
# Load animal data from file | ||
animals = load_data(ANIMAL_DATA_FILE) | ||
animals = load_animal_data(animals_collection) | ||
current_user = sudo_user() | ||
|
||
name = input("\nEnter the name of the animal to toggle adoption status: ") | ||
name = input("\nEnter the name of the animal to toggle adoption status (type 'exit' to leave): ") | ||
|
||
# Check if animal exists in the data | ||
if name in animals: | ||
|
||
# Toggle the adopted status | ||
animals[name]['adopted'] = not animals[name].get('adopted', False) | ||
save_data(animals, ANIMAL_DATA_FILE) | ||
|
||
# Notify the user about the updated adoptino status | ||
if animals[name]['adopted']: | ||
print(Fore.GREEN + f"\n{name} has been marked as " + Fore.CYAN + "adopted!" + Style.RESET_ALL) | ||
else: | ||
print(Fore.GREEN + f"\n{name} has been marked as " + Fore.RED + "not adopted!" + Style.RESET_ALL) | ||
if name == "exit": | ||
log_action(current_user, "Exited 'Change Adoption Status'") | ||
print("\nExiting...") | ||
time.sleep(2) | ||
return | ||
|
||
# Notify the user if the animal is not found | ||
else: | ||
print(Fore.RED + f"\nNo animal found with the name {name}" + Style.RESET_ALL) | ||
# Check if animal exists in the data | ||
if name in animals: | ||
|
||
# Toggle the adopted status | ||
animals[name]['adopted'] = not animals[name].get('adopted', False) | ||
save_data(animals) | ||
|
||
# Notify the user about the updated adoptino status | ||
if animals[name]['adopted']: | ||
print(Fore.GREEN + f"\n{name} has been marked as " + Fore.CYAN + "adopted!" + Style.RESET_ALL) | ||
log_action(current_user, f"{name} marked as adopted") | ||
else: | ||
print(Fore.GREEN + f"\n{name} has been marked as " + Fore.RED + "not adopted!" + Style.RESET_ALL) | ||
log_action(current_user, f"{name} marked as not adopted") | ||
# Notify the user if the animal is not found | ||
else: | ||
print(Fore.RED + f"\nNo animal found with the name {name}" + Style.RESET_ALL) | ||
|
||
time.sleep(2) | ||
time.sleep(2) |
Oops, something went wrong.