Spaces:
Sleeping
Sleeping
| # core/visits.py | |
| from pathlib import Path | |
| COUNTER_FILE = Path("visits.txt") | |
| def get_and_update_visits(): | |
| """Reads the current visit count, increments it, writes it back, and returns the new count.""" | |
| if not COUNTER_FILE.exists(): | |
| count = 1 | |
| else: | |
| try: | |
| count = int(COUNTER_FILE.read_text()) + 1 | |
| except (ValueError, IOError): | |
| count = 1 # Reset counter if file is corrupted | |
| try: | |
| COUNTER_FILE.write_text(str(count)) | |
| except IOError as e: | |
| print(f"Error writing to counter file: {e}") | |
| return count | |
| def get_current_visit_count(): | |
| """Reads and returns the current visit count without incrementing it.""" | |
| if not COUNTER_FILE.exists(): | |
| return 0 | |
| try: | |
| return int(COUNTER_FILE.read_text()) | |
| except (ValueError, IOError): | |
| return 0 # Return 0 if file is corrupted |