I wrote script to miniaturize images.
|
@ -0,0 +1,55 @@
|
|||
import Image
|
||||
import os
|
||||
|
||||
def make_miniatures_of_notes(path, div):
|
||||
subjects = os.listdir(path)
|
||||
if "bootstrap" in subjects:
|
||||
subjects.remove("bootstrap")
|
||||
if "miniatures" in subjects:
|
||||
subjects.remove("miniatures")
|
||||
for subject in subjects:
|
||||
for date in os.listdir(path+"/" + subject):
|
||||
notes = []
|
||||
for note in os.listdir(path+"/" + subject +"/" + date ):
|
||||
notes.append({"tags": "none", "name": note})
|
||||
image_path = "/" + subject +"/" + date + "/" + note
|
||||
miniature = make_miniature(path + image_path, div)
|
||||
if miniature:
|
||||
print "creating dir " + path + "/mini" + "/" + subject +"/" + date
|
||||
make_reccurent_dir(path + "/mini" + "/" + subject +"/" + date)
|
||||
print "saving file " + path + "/mini" + image_path
|
||||
miniature.save(path + "/mini" + image_path)
|
||||
|
||||
def make_reccurent_dir(path):
|
||||
dirs = path.split("/")
|
||||
already_made = ""
|
||||
for directory in dirs:
|
||||
try:
|
||||
print "creating: " + already_made + directory
|
||||
os.mkdir(already_made + directory)
|
||||
except OSError:
|
||||
pass
|
||||
already_made += directory + "/"
|
||||
|
||||
def make_miniature(path, div):
|
||||
print "opening path: " + path
|
||||
try:
|
||||
im1 = Image.open(path)
|
||||
width = im1.size[0] / div
|
||||
height = im1.size[1] / div
|
||||
im2 = im1.resize((width, height), Image.ANTIALIAS)
|
||||
except:
|
||||
print "couln't open file " + path
|
||||
return
|
||||
return im2
|
||||
|
||||
def main():
|
||||
path = raw_input("Path: ")
|
||||
div = int(raw_input("How many times smaller?: "))
|
||||
try:
|
||||
make_miniatures_of_notes(path, div)
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -1,25 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
from contextlib import closing
|
||||
import sqlite3
|
||||
|
||||
DATABASE = '/tmp/notes.db'
|
||||
DATABASE = 'notes.db'
|
||||
|
||||
def add_all_notes_in_dir(path):
|
||||
os.chdir(path)
|
||||
subjects = os.listdir(os.getcwd())
|
||||
subjects = os.listdir(path)
|
||||
if "bootstrap" in subjects:
|
||||
subjects.remove("bootstrap")
|
||||
for subject in subjects:
|
||||
os.chdir(subject)
|
||||
for date in os.listdir(os.getcwd()):
|
||||
for date in os.listdir(path+"/" + subject):
|
||||
notes = []
|
||||
os.chdir(date)
|
||||
for note in os.listdir(os.getcwd()):
|
||||
for note in os.listdir(path+"/" + subject +"/" + date ):
|
||||
notes.append({"tags": "none", "name": note})
|
||||
add_note(subject, date, notes)
|
||||
os.chdir("..")
|
||||
os.chdir("..")
|
||||
|
||||
|
||||
def add_note(subject, datestring, notes):
|
||||
|
@ -34,16 +28,10 @@ def add_note(subject, datestring, notes):
|
|||
def connect_db():
|
||||
return sqlite3.connect(DATABASE)
|
||||
|
||||
def add_notes_to_db():
|
||||
|
||||
query_result = query_db("select * from pages ")
|
||||
print query_result
|
||||
if not query_result:
|
||||
add_note("analiza", "9stycznia", notes)
|
||||
db.close()
|
||||
|
||||
def init_db():
|
||||
db = connect_db()
|
||||
print "initialize database..."
|
||||
f = open("schema.sql", "r")
|
||||
db.cursor().executescript(f.read())
|
||||
db.commit()
|
||||
|
|
202
notes.py
|
@ -12,7 +12,7 @@ from subprocess import Popen, PIPE
|
|||
import smtplib
|
||||
|
||||
# configuration
|
||||
DATABASE = '/tmp/notes.db'
|
||||
DATABASE = 'notes.db'
|
||||
DEBUG = True
|
||||
SECRET_KEY = 'development key'
|
||||
USERNAME = 'admin'
|
||||
|
@ -22,21 +22,25 @@ app = Flask(__name__)
|
|||
app.config.from_object(__name__)
|
||||
|
||||
class Thumb:
|
||||
def __init__(self, source, href, tags):
|
||||
self.src = source
|
||||
self.href = href
|
||||
self.tags = tags
|
||||
def __init__(self, source, href, tags):
|
||||
self.src = source
|
||||
self.href = href
|
||||
self.tags = tags
|
||||
|
||||
#DB functions
|
||||
def connect_db():
|
||||
return sqlite3.connect(app.config['DATABASE'])
|
||||
return sqlite3.connect(app.config['DATABASE'])
|
||||
|
||||
def init_db():
|
||||
with closing(connect_db()) as db:
|
||||
with app.open_resource('schema.sql') as f:
|
||||
db.cursor().executescript(f.read())
|
||||
db.commit()
|
||||
with closing(connect_db()) as db:
|
||||
with app.open_resource('schema.sql') as f:
|
||||
db.cursor().executescript(f.read())
|
||||
db.commit()
|
||||
|
||||
def query_db(query, args=(), one=False):
|
||||
"""
|
||||
Simple wrapper around query
|
||||
"""
|
||||
cur = g.db.execute(query, args)
|
||||
rv = [dict((cur.description[idx][0], value)
|
||||
for idx, value in enumerate(row)) for row in cur.fetchall()]
|
||||
|
@ -44,156 +48,110 @@ def query_db(query, args=(), one=False):
|
|||
|
||||
@app.before_request
|
||||
def before_request():
|
||||
try:
|
||||
g.db = g._db.cursor()
|
||||
except AttributeError:
|
||||
g._db = connect_db()
|
||||
g.db = g._db.cursor()
|
||||
try:
|
||||
g.db = g._db.cursor()
|
||||
except AttributeError:
|
||||
g._db = connect_db()
|
||||
g.db = g._db.cursor()
|
||||
|
||||
@app.teardown_request
|
||||
def teardown_request(exception):
|
||||
try:
|
||||
g.db.close()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
try:
|
||||
g.db.close()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
#VIEWS
|
||||
@app.route('/')
|
||||
@app.route('/view')
|
||||
@app.route('/view/<subject>/<datestring>')
|
||||
def home(subject= "chemia", datestring= "12grudnia"):
|
||||
other_dates = [date["datestring"] for date in get_possible_dates(subject)]
|
||||
all_dates = [date["datestring"] for date in get_all_dates()]
|
||||
all_subjects = [sub["subject"] for sub in get_all_subjects()]
|
||||
|
||||
if datestring in other_dates:
|
||||
other_dates.remove(datestring)
|
||||
thumbs_info = {"subject": subject, "datestring": datestring, "other_dates": other_dates}
|
||||
thumbs = get_thumbs(subject, datestring)
|
||||
thumbs = [dict(href=thumb.href, src=thumb.src) for thumb in thumbs]
|
||||
main_page_src=thumbs[0]["href"]
|
||||
print thumbs
|
||||
return render_template('index.html', thumbs=thumbs, main_page_src=main_page_src,thumbs_info=thumbs_info,
|
||||
all_dates=all_dates, all_subjects=all_subjects)
|
||||
def home(subject= "chemia", datestring= "12grudnia2012"):
|
||||
other_dates = [date["datestring"] for date in get_possible_dates(subject)]
|
||||
all_dates = [date["datestring"] for date in get_all_dates()]
|
||||
all_subjects = [sub["subject"] for sub in get_all_subjects()]
|
||||
if datestring in other_dates:
|
||||
other_dates.remove(datestring)
|
||||
thumbs_info = {"subject": subject, "datestring": datestring, "other_dates": other_dates}
|
||||
thumbs = get_thumbs(subject, datestring)
|
||||
thumbs = [dict(href=thumb.href, src=thumb.src) for thumb in thumbs]
|
||||
main_page_src=thumbs[0]["href"]
|
||||
return render_template('index.html', thumbs=thumbs, main_page_src=main_page_src,thumbs_info=thumbs_info,
|
||||
all_dates=all_dates, all_subjects=all_subjects)
|
||||
|
||||
@app.route('/subject/<subject>')
|
||||
def show_subject(subject):
|
||||
dates = [date["datestring"] for date in get_possible_dates(subject)]
|
||||
all_dates = [date["datestring"] for date in get_all_dates()]
|
||||
all_subjects = [sub["subject"] for sub in get_all_subjects()]
|
||||
return render_template('subject.html', subject=subject, dates=dates, all_dates=all_dates, all_subjects=all_subjects)
|
||||
dates = [date["datestring"] for date in get_possible_dates(subject)]
|
||||
all_dates = [date["datestring"] for date in get_all_dates()]
|
||||
all_subjects = [sub["subject"] for sub in get_all_subjects()]
|
||||
return render_template('subject.html', subject=subject, dates=dates, all_dates=all_dates, all_subjects=all_subjects)
|
||||
|
||||
@app.route('/date/<datestring>')
|
||||
def show_date(datestring):
|
||||
all_dates = [date["datestring"] for date in get_all_dates()]
|
||||
all_subjects = [sub["subject"] for sub in get_all_subjects()]
|
||||
notes = get_notes_for_day(datestring)
|
||||
all_dates = [date["datestring"] for date in get_all_dates()]
|
||||
all_subjects = [sub["subject"] for sub in get_all_subjects()]
|
||||
notes = get_notes_for_day(datestring)
|
||||
separated_notes = {}
|
||||
for note in notes:
|
||||
if not note["subject"] in separated_notes:
|
||||
separated_notes[note["subject"]] = []
|
||||
separated_notes[note["subject"]].append(note)
|
||||
|
||||
separated_notes = {}
|
||||
|
||||
for note in notes:
|
||||
if not note["subject"] in separated_notes:
|
||||
separated_notes[note["subject"]] = []
|
||||
separated_notes[note["subject"]].append(note)
|
||||
|
||||
print separated_notes
|
||||
return render_template('date.html', date=datestring, all_dates=all_dates, all_subjects=all_subjects, separated_notes=separated_notes)
|
||||
return render_template('date.html', date=datestring, all_dates=all_dates, all_subjects=all_subjects, separated_notes=separated_notes)
|
||||
|
||||
@app.route('/search')
|
||||
def show_search():
|
||||
all_dates = [date["datestring"] for date in get_all_dates()]
|
||||
all_subjects = [sub["subject"] for sub in get_all_subjects()]
|
||||
return render_template('search.html', all_dates=all_dates, all_subjects=all_subjects )
|
||||
all_dates = [date["datestring"] for date in get_all_dates()]
|
||||
all_subjects = [sub["subject"] for sub in get_all_subjects()]
|
||||
return render_template('search.html', all_dates=all_dates, all_subjects=all_subjects )
|
||||
|
||||
@app.route('/about')
|
||||
def about():
|
||||
all_dates = [date["datestring"] for date in get_all_dates()]
|
||||
all_subjects = [sub["subject"] for sub in get_all_subjects()]
|
||||
return render_template('about.html', all_dates=all_dates, all_subjects=all_subjects )
|
||||
all_dates = [date["datestring"] for date in get_all_dates()]
|
||||
all_subjects = [sub["subject"] for sub in get_all_subjects()]
|
||||
return render_template('about.html', all_dates=all_dates, all_subjects=all_subjects )
|
||||
|
||||
#HELPERS
|
||||
def add_note(subject, datestring, notes):
|
||||
g.db.execute('insert into notes (subject, datestring ) values (?, ?)', [subject, datestring])
|
||||
note_id = g.db.lastrowid
|
||||
for note in notes:
|
||||
g.db.execute('insert into pages (note_id, name, tags ) values (?, ?, ?)', [note_id, note["name"], note["tags"]])
|
||||
g.db.execute('insert into pages (note_id, name, tags ) values (?, ?, ?)', [note_id, note["name"], note["tags"]])
|
||||
g._db.commit()
|
||||
|
||||
def create_thumb(subject, datestring, name, tags):
|
||||
src = subject + "/" + datestring + "/" + name
|
||||
href = src
|
||||
thumb = Thumb(src, href, tags)
|
||||
return thumb
|
||||
src = subject + "/" + datestring + "/" + name
|
||||
href = src
|
||||
thumb = Thumb(src, href, tags)
|
||||
return thumb
|
||||
|
||||
def get_thumbs(subject, datestring=""):
|
||||
if(datestring==""):
|
||||
query_result = query_db("select pages.* from pages left join notes on notes.id = pages.note_id where notes.subject = ?", [subject,])
|
||||
else:
|
||||
query_result = query_db("select pages.* from pages left join notes on notes.id = pages.note_id \
|
||||
where notes.subject = ? and datestring = ?", [subject, datestring])
|
||||
print "qr " + str(query_result)
|
||||
return [create_thumb(subject, datestring, t["name"], t["tags"]) for t in query_result ]
|
||||
|
||||
if(datestring==""):
|
||||
query_result = query_db("select pages.* from pages left join notes on notes.id = pages.note_id where notes.subject = ?", [subject,])
|
||||
else:
|
||||
query_result = query_db("select pages.* from pages left join notes on notes.id = pages.note_id \
|
||||
where notes.subject = ? and datestring = ?", [subject, datestring])
|
||||
return [create_thumb(subject, datestring, t["name"], t["tags"]) for t in query_result ]
|
||||
|
||||
def get_possible_dates(subject):
|
||||
dates = query_db("select distinct datestring from notes where subject = ? ", [subject])
|
||||
return dates
|
||||
dates = query_db("select distinct datestring from notes where subject = ? ", [subject])
|
||||
return dates
|
||||
|
||||
def get_notes_for_day(datestring):
|
||||
query_result = query_db("select pages.*,notes.subject from pages left join notes on notes.id = pages.note_id \
|
||||
where datestring = ?", [datestring])
|
||||
|
||||
return [{"subject": t["subject"], "datestring": datestring, "name": t["name"]}for t in query_result ]
|
||||
"""returns pages which where written that day (daystring) with other info"""
|
||||
query_result = query_db("select pages.*,notes.subject from pages left join notes on notes.id = pages.note_id \
|
||||
where datestring = ?", [datestring])
|
||||
return [{"subject": t["subject"], "datestring": datestring, "name": t["name"]}for t in query_result ]
|
||||
|
||||
def get_all_dates():
|
||||
dates = query_db("select distinct datestring from notes ")
|
||||
return dates
|
||||
dates = query_db("select distinct datestring from notes ")
|
||||
return dates
|
||||
|
||||
def get_all_subjects():
|
||||
subjects = query_db("select distinct subject from notes ")
|
||||
return subjects
|
||||
|
||||
@app.before_first_request
|
||||
def add_notes_data_to_db():
|
||||
init_db()
|
||||
g._db = connect_db()
|
||||
g.db = g._db.cursor()
|
||||
query_result = query_db("select * from pages ")
|
||||
print query_result
|
||||
if not query_result:
|
||||
notes = []
|
||||
notes.append({"name": "0003.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
|
||||
notes.append({"name": "0004.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
|
||||
add_note("chemia", "12grudnia", notes)
|
||||
|
||||
notes = []
|
||||
notes.append({"name": "0005.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
|
||||
notes.append({"name": "0006.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
|
||||
add_note("chemia", "19grudnia", notes)
|
||||
|
||||
notes = []
|
||||
notes.append({"name": "0005.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
|
||||
notes.append({"name": "0006.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
|
||||
notes.append({"name": "0007.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
|
||||
add_note("chemia", "28listopada", notes)
|
||||
|
||||
notes = []
|
||||
notes.append({"name": "0009.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
|
||||
notes.append({"name": "0010.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
|
||||
notes.append({"name": "0011.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
|
||||
notes.append({"name": "0012.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
|
||||
add_note("analiza", "2stycznia", notes)
|
||||
|
||||
notes = []
|
||||
notes.append({"name": "0013.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
|
||||
notes.append({"name": "0014.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
|
||||
notes.append({"name": "0015.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
|
||||
notes.append({"name": "0016.jpeg", "tags": u"karbonylek, Fe, żelazo, CO"})
|
||||
add_note("analiza", "9stycznia", notes)
|
||||
subjects = query_db("select distinct subject from notes ")
|
||||
return subjects
|
||||
|
||||
|
||||
|
||||
g.db.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
|
||||
app.run()
|
||||
app.run()
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
[Dolphin]
|
||||
Timestamp=2013,1,19,22,19,36
|
||||
Version=3
|
After Width: | Height: | Size: 8.7 KiB |
After Width: | Height: | Size: 8.1 KiB |
After Width: | Height: | Size: 6.7 KiB |
After Width: | Height: | Size: 6.7 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 5.5 KiB |
After Width: | Height: | Size: 8.7 KiB |
After Width: | Height: | Size: 9.3 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 7.1 KiB |
After Width: | Height: | Size: 6.6 KiB |
After Width: | Height: | Size: 5.7 KiB |
After Width: | Height: | Size: 5.2 KiB |
After Width: | Height: | Size: 5.1 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 7.1 KiB |
After Width: | Height: | Size: 6.1 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 8.4 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 9.9 KiB |
After Width: | Height: | Size: 8.5 KiB |
After Width: | Height: | Size: 9.2 KiB |
After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 8.6 KiB |
After Width: | Height: | Size: 7.4 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 9.5 KiB |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 6.1 KiB |
After Width: | Height: | Size: 7.2 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 8.6 KiB |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 8.8 KiB |
After Width: | Height: | Size: 8.8 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 10 KiB |
|
@ -0,0 +1,4 @@
|
|||
[Dolphin]
|
||||
PreviewsShown=true
|
||||
Timestamp=2013,1,19,22,41,42
|
||||
Version=3
|
After Width: | Height: | Size: 8.8 KiB |
After Width: | Height: | Size: 8.6 KiB |
After Width: | Height: | Size: 7.9 KiB |
After Width: | Height: | Size: 7.1 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 9.4 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 9.2 KiB |
After Width: | Height: | Size: 9.3 KiB |
After Width: | Height: | Size: 6.9 KiB |
After Width: | Height: | Size: 8.5 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 9.5 KiB |
After Width: | Height: | Size: 9.9 KiB |
After Width: | Height: | Size: 9.3 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 9.5 KiB |
After Width: | Height: | Size: 7.7 KiB |
After Width: | Height: | Size: 7.9 KiB |
After Width: | Height: | Size: 8.1 KiB |
After Width: | Height: | Size: 7.9 KiB |
After Width: | Height: | Size: 8.1 KiB |
After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 8.2 KiB |