-
Notifications
You must be signed in to change notification settings - Fork 63
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 #74 from konan625/main
My-Personal-Journal Completed
- Loading branch information
Showing
12 changed files
with
717 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Personal Journal | ||
|
||
A simple web-based application for maintaining a personal journal. Users can create entries, tag them, and search through past entries by date or keywords. The application is built using Flask and SQLite for a lightweight and efficient experience. | ||
|
||
## Features | ||
|
||
- **Add New Entries**: Users can add journal entries with mood, content, and tags. | ||
- **Search Entries**: Search through entries using keywords or specific dates. | ||
- **Tag Management**: Create and view tags associated with each entry, and filter entries by tags. | ||
- **User-Friendly Interface**: A clean and professional UI for easy navigation and use. | ||
|
||
## Technologies Used | ||
|
||
- Python | ||
- Flask | ||
- SQLite | ||
- HTML/CSS | ||
|
||
## Installation | ||
|
||
1. **Clone the Repository**: | ||
```bash | ||
git clone <repository-url> | ||
cd your_project | ||
|
||
2. **Install Required Packages: Make sure you have Python installed (preferably Python 3). Install the required packages using pip**: | ||
```bash | ||
pip install -r requirements.txt | ||
3. **Run the Application: Start the Flask application**: | ||
```bash | ||
python app.py | ||
|
||
4. **Access the App: Open your web browser and navigate to http://127.0.0.1:8080 to access the application.** |
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
from flask import Flask, render_template, request, redirect, url_for | ||
from journal_app import add_entry, search_entries | ||
from datetime import datetime | ||
import sqlite3 | ||
|
||
app = Flask(__name__) | ||
|
||
# Route to show the home page | ||
@app.route('/') | ||
def index(): | ||
return render_template('index.html') | ||
|
||
# Route to add a new journal entry | ||
@app.route('/add', methods=['GET', 'POST']) | ||
def add(): | ||
if request.method == 'POST': | ||
mood = request.form['mood'] | ||
content = request.form['content'] | ||
tags = request.form['tags'] | ||
add_entry("user_1", mood, content, tags) | ||
return redirect(url_for('index')) | ||
return render_template('add.html') | ||
|
||
# Route to search journal entries | ||
|
||
|
||
@app.route('/search', methods=['GET', 'POST']) | ||
def search(): | ||
if request.method == 'POST': | ||
search_input = request.form['search_term'] | ||
|
||
# Try to parse the input as a date | ||
try: | ||
search_date = datetime.strptime(search_input, '%Y-%m-%d').date() | ||
results = search_entries("user_1", date=search_date) | ||
except ValueError: | ||
# If parsing fails, treat it as a search term | ||
results = search_entries("user_1", search_term=search_input) | ||
|
||
return render_template('search_results.html', results=results) | ||
|
||
return render_template('search.html') | ||
|
||
|
||
# Route to list all unique tags | ||
@app.route('/tags') | ||
def list_tags(): | ||
conn = sqlite3.connect('journal.db') | ||
cursor = conn.cursor() | ||
|
||
# Fetch unique tags from all entries | ||
cursor.execute("SELECT DISTINCT tags FROM journal_entries") | ||
tags_data = cursor.fetchall() | ||
conn.close() | ||
|
||
# Flatten the tags and remove duplicates | ||
tags = set() | ||
for row in tags_data: | ||
if row[0]: | ||
tags.update(tag.strip() for tag in row[0].split(',')) | ||
|
||
return render_template('tags.html', tags=sorted(tags)) | ||
|
||
# Route to show journal entries by tag | ||
@app.route('/tags/<tag>') | ||
def entries_by_tag(tag): | ||
conn = sqlite3.connect('journal.db') | ||
cursor = conn.cursor() | ||
|
||
# Search for entries that contain the selected tag | ||
cursor.execute("SELECT * FROM journal_entries WHERE tags LIKE ?", ('%' + tag + '%',)) | ||
results = cursor.fetchall() | ||
conn.close() | ||
|
||
return render_template('search_results.html', results=results) | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True, port=8080) |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from sqlalchemy.orm import sessionmaker | ||
from models import JournalEntry, Base | ||
from sqlalchemy import create_engine | ||
|
||
engine = create_engine('sqlite:///journal.db') | ||
Base.metadata.create_all(engine) | ||
Session = sessionmaker(bind=engine) | ||
session = Session() | ||
|
||
def add_entry(user_id, mood, content, tags): | ||
entry = JournalEntry(user_id=user_id, mood=mood, content=content, tags=tags) | ||
session.add(entry) | ||
session.commit() | ||
|
||
def search_entries(user_id, search_term=None, date=None): | ||
query = session.query(JournalEntry).filter(JournalEntry.user_id == user_id) | ||
if search_term: | ||
query = query.filter(JournalEntry.content.contains(search_term)) | ||
if date: | ||
query = query.filter(JournalEntry.date == date) | ||
return query.all() |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import sqlite3 | ||
from datetime import datetime | ||
|
||
DB_NAME = "journal.db" | ||
|
||
def connect_db(): | ||
return sqlite3.connect(DB_NAME) | ||
|
||
def create_table(): | ||
with connect_db() as conn: | ||
cursor = conn.cursor() | ||
cursor.execute(''' | ||
CREATE TABLE IF NOT EXISTS journal_entries ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
user_id TEXT, | ||
date TEXT, | ||
mood TEXT, | ||
content TEXT, | ||
tags TEXT | ||
) | ||
''') | ||
conn.commit() | ||
|
||
def add_entry(user_id, mood, content, tags): | ||
with connect_db() as conn: | ||
cursor = conn.cursor() | ||
cursor.execute(''' | ||
INSERT INTO journal_entries (user_id, date, mood, content, tags) | ||
VALUES (?, ?, ?, ?, ?) | ||
''', (user_id, datetime.now().strftime('%Y-%m-%d %H:%M:%S'), mood, content, tags)) | ||
conn.commit() | ||
|
||
def search_entries(user_id, search_term=None, date=None): | ||
with connect_db() as conn: | ||
cursor = conn.cursor() | ||
|
||
if search_term: | ||
query = ''' | ||
SELECT * FROM journal_entries | ||
WHERE user_id = ? AND (content LIKE ? OR tags LIKE ?) | ||
''' | ||
cursor.execute(query, (user_id, f'%{search_term}%', f'%{search_term}%')) | ||
elif date: | ||
query = ''' | ||
SELECT * FROM journal_entries | ||
WHERE user_id = ? AND date(date) = ? | ||
''' | ||
cursor.execute(query, (user_id, date.strftime('%Y-%m-%d'))) | ||
else: | ||
return [] | ||
|
||
return cursor.fetchall() | ||
|
||
# Create the journal table at the start | ||
create_table() |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
flask | ||
sqlalchemy | ||
# sqlite3 | ||
bcrypt | ||
pandas | ||
matplotlib | ||
# tkinter | ||
flask |
Oops, something went wrong.