Skip to content

Commit 89f5cd1

Browse files
authored
Merge pull request #74 from konan625/main
My-Personal-Journal Completed
2 parents 6ac43f3 + ea679de commit 89f5cd1

File tree

12 files changed

+717
-0
lines changed

12 files changed

+717
-0
lines changed

My-Personal-Journal/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Personal Journal
2+
3+
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.
4+
5+
## Features
6+
7+
- **Add New Entries**: Users can add journal entries with mood, content, and tags.
8+
- **Search Entries**: Search through entries using keywords or specific dates.
9+
- **Tag Management**: Create and view tags associated with each entry, and filter entries by tags.
10+
- **User-Friendly Interface**: A clean and professional UI for easy navigation and use.
11+
12+
## Technologies Used
13+
14+
- Python
15+
- Flask
16+
- SQLite
17+
- HTML/CSS
18+
19+
## Installation
20+
21+
1. **Clone the Repository**:
22+
```bash
23+
git clone <repository-url>
24+
cd your_project
25+
26+
2. **Install Required Packages: Make sure you have Python installed (preferably Python 3). Install the required packages using pip**:
27+
```bash
28+
pip install -r requirements.txt
29+
30+
3. **Run the Application: Start the Flask application**:
31+
```bash
32+
python app.py
33+
34+
4. **Access the App: Open your web browser and navigate to http://127.0.0.1:8080 to access the application.**

My-Personal-Journal/app.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from flask import Flask, render_template, request, redirect, url_for
2+
from journal_app import add_entry, search_entries
3+
from datetime import datetime
4+
import sqlite3
5+
6+
app = Flask(__name__)
7+
8+
# Route to show the home page
9+
@app.route('/')
10+
def index():
11+
return render_template('index.html')
12+
13+
# Route to add a new journal entry
14+
@app.route('/add', methods=['GET', 'POST'])
15+
def add():
16+
if request.method == 'POST':
17+
mood = request.form['mood']
18+
content = request.form['content']
19+
tags = request.form['tags']
20+
add_entry("user_1", mood, content, tags)
21+
return redirect(url_for('index'))
22+
return render_template('add.html')
23+
24+
# Route to search journal entries
25+
26+
27+
@app.route('/search', methods=['GET', 'POST'])
28+
def search():
29+
if request.method == 'POST':
30+
search_input = request.form['search_term']
31+
32+
# Try to parse the input as a date
33+
try:
34+
search_date = datetime.strptime(search_input, '%Y-%m-%d').date()
35+
results = search_entries("user_1", date=search_date)
36+
except ValueError:
37+
# If parsing fails, treat it as a search term
38+
results = search_entries("user_1", search_term=search_input)
39+
40+
return render_template('search_results.html', results=results)
41+
42+
return render_template('search.html')
43+
44+
45+
# Route to list all unique tags
46+
@app.route('/tags')
47+
def list_tags():
48+
conn = sqlite3.connect('journal.db')
49+
cursor = conn.cursor()
50+
51+
# Fetch unique tags from all entries
52+
cursor.execute("SELECT DISTINCT tags FROM journal_entries")
53+
tags_data = cursor.fetchall()
54+
conn.close()
55+
56+
# Flatten the tags and remove duplicates
57+
tags = set()
58+
for row in tags_data:
59+
if row[0]:
60+
tags.update(tag.strip() for tag in row[0].split(','))
61+
62+
return render_template('tags.html', tags=sorted(tags))
63+
64+
# Route to show journal entries by tag
65+
@app.route('/tags/<tag>')
66+
def entries_by_tag(tag):
67+
conn = sqlite3.connect('journal.db')
68+
cursor = conn.cursor()
69+
70+
# Search for entries that contain the selected tag
71+
cursor.execute("SELECT * FROM journal_entries WHERE tags LIKE ?", ('%' + tag + '%',))
72+
results = cursor.fetchall()
73+
conn.close()
74+
75+
return render_template('search_results.html', results=results)
76+
77+
if __name__ == '__main__':
78+
app.run(debug=True, port=8080)

My-Personal-Journal/database.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from sqlalchemy.orm import sessionmaker
2+
from models import JournalEntry, Base
3+
from sqlalchemy import create_engine
4+
5+
engine = create_engine('sqlite:///journal.db')
6+
Base.metadata.create_all(engine)
7+
Session = sessionmaker(bind=engine)
8+
session = Session()
9+
10+
def add_entry(user_id, mood, content, tags):
11+
entry = JournalEntry(user_id=user_id, mood=mood, content=content, tags=tags)
12+
session.add(entry)
13+
session.commit()
14+
15+
def search_entries(user_id, search_term=None, date=None):
16+
query = session.query(JournalEntry).filter(JournalEntry.user_id == user_id)
17+
if search_term:
18+
query = query.filter(JournalEntry.content.contains(search_term))
19+
if date:
20+
query = query.filter(JournalEntry.date == date)
21+
return query.all()

My-Personal-Journal/journal_app.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import sqlite3
2+
from datetime import datetime
3+
4+
DB_NAME = "journal.db"
5+
6+
def connect_db():
7+
return sqlite3.connect(DB_NAME)
8+
9+
def create_table():
10+
with connect_db() as conn:
11+
cursor = conn.cursor()
12+
cursor.execute('''
13+
CREATE TABLE IF NOT EXISTS journal_entries (
14+
id INTEGER PRIMARY KEY AUTOINCREMENT,
15+
user_id TEXT,
16+
date TEXT,
17+
mood TEXT,
18+
content TEXT,
19+
tags TEXT
20+
)
21+
''')
22+
conn.commit()
23+
24+
def add_entry(user_id, mood, content, tags):
25+
with connect_db() as conn:
26+
cursor = conn.cursor()
27+
cursor.execute('''
28+
INSERT INTO journal_entries (user_id, date, mood, content, tags)
29+
VALUES (?, ?, ?, ?, ?)
30+
''', (user_id, datetime.now().strftime('%Y-%m-%d %H:%M:%S'), mood, content, tags))
31+
conn.commit()
32+
33+
def search_entries(user_id, search_term=None, date=None):
34+
with connect_db() as conn:
35+
cursor = conn.cursor()
36+
37+
if search_term:
38+
query = '''
39+
SELECT * FROM journal_entries
40+
WHERE user_id = ? AND (content LIKE ? OR tags LIKE ?)
41+
'''
42+
cursor.execute(query, (user_id, f'%{search_term}%', f'%{search_term}%'))
43+
elif date:
44+
query = '''
45+
SELECT * FROM journal_entries
46+
WHERE user_id = ? AND date(date) = ?
47+
'''
48+
cursor.execute(query, (user_id, date.strftime('%Y-%m-%d')))
49+
else:
50+
return []
51+
52+
return cursor.fetchall()
53+
54+
# Create the journal table at the start
55+
create_table()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
flask
2+
sqlalchemy
3+
# sqlite3
4+
bcrypt
5+
pandas
6+
matplotlib
7+
# tkinter
8+
flask

0 commit comments

Comments
 (0)