summaryrefslogtreecommitdiffstats
path: root/notes.py
diff options
context:
space:
mode:
Diffstat (limited to 'notes.py')
-rw-r--r--notes.py75
1 files changed, 38 insertions, 37 deletions
diff --git a/notes.py b/notes.py
index 8aeb179..82f6ef2 100644
--- a/notes.py
+++ b/notes.py
@@ -75,46 +75,11 @@ def home(subject= "mechanika", datestring= "14grudnia2012"):
other_dates.remove(datestring)
thumbs_info = {"subject": subject, "datestring": datestring, "other_dates": other_dates}
- print thumbs
thumbs = [dict(href=thumb.href, src=thumb.src) for thumb in thumbs]
main_page_src=thumbs[0]["href"]
- print all_dates
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 prepare_all_dates():
- all_dates = [date["datestring"] for date in get_all_dates()]
- datastrings = [date["datestring"] for date in get_all_dates()]
- all_dates = [convert_datestring_to_date(date) for date in datastrings]
- sorted_dates = {}
- for date, datestring in zip(all_dates, datastrings):
- if not date.datetime.year in sorted_dates:
- sorted_dates[date.datetime.year] = {}
- if not date.datetime.month in sorted_dates[date.datetime.year]:
- sorted_dates[date.datetime.year][date.datetime.month] = []
- sorted_dates[date.datetime.year][date.datetime.month].append({"day" : date.datetime.day, "source": datestring,
- "weekday": weekday(date.datetime.weekday())})
- sorted = sort_number_strings(sorted_dates[date.datetime.year][date.datetime.month])
- sorted_dates[date.datetime.year][date.datetime.month] = sorted
- print sorted_dates
- return sorted_dates
-
-def sort_number_strings(data):
- number_data = [int(day["day"]) for day in data]
- number_data.sort()
- print "sorted date" + str(number_data)
- return [{"day": number, "source": data[get_index_for(number, data)]["source"],
- "weekday": data[get_index_for(number, data)]["weekday"] } for i, number in enumerate(number_data)]
-
-def weekday(number):
- weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
- return weekdays[number]
-def get_index_for(number, data):
- index = 0
- for i, day in enumerate(data):
- if day["day"] == number:
- index = i
- return index
@app.route('/subject/<subject>')
def show_subject(subject):
@@ -168,7 +133,6 @@ def get_thumbs(subject, datestring=""):
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 query_result
return [create_thumb(subject, datestring, t["name"], t["tags"]) for t in query_result ]
def get_possible_dates(subject):
@@ -176,20 +140,57 @@ def get_possible_dates(subject):
return dates
def get_notes_for_day(datestring):
- """returns pages which where written that day (daystring) with other info"""
+ """return 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():
+ """return all dates from database"""
dates = query_db("select distinct datestring from notes ")
return dates
def get_all_subjects():
+ """return all subject from database"""
subjects = query_db("select distinct subject from notes ")
return subjects
+def prepare_all_dates():
+ """return all dates in well formated form of nested dictionaries"""
+ all_dates = [date["datestring"] for date in get_all_dates()]
+ datastrings = [date["datestring"] for date in get_all_dates()]
+ all_dates = [convert_datestring_to_date(date) for date in datastrings]
+ sorted_dates = {}
+ for date, datestring in zip(all_dates, datastrings):
+ if not date.datetime.year in sorted_dates:
+ sorted_dates[date.datetime.year] = {}
+ if not date.datetime.month in sorted_dates[date.datetime.year]:
+ sorted_dates[date.datetime.year][date.datetime.month] = []
+ sorted_dates[date.datetime.year][date.datetime.month].append({"day" : date.datetime.day, "source": datestring,
+ "weekday": weekday(date.datetime.weekday())})
+ sorted = sort_number_strings(sorted_dates[date.datetime.year][date.datetime.month])
+ sorted_dates[date.datetime.year][date.datetime.month] = sorted
+ return sorted_dates
+def sort_number_strings(data):
+ """return array of dictionaries sorted by day treated as a number, i.e. 12 is after 3."""
+ number_data = [int(day["day"]) for day in data]
+ number_data.sort()
+ return [{"day": number, "source": data[get_index_for(number, data)]["source"],
+ "weekday": data[get_index_for(number, data)]["weekday"] } for i, number in enumerate(number_data)]
+
+def weekday(number):
+ """return name of the weekday for a specific number in range 0-6"""
+ weekdays = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
+ return weekdays[number]
+
+def get_index_for(number, data):
+ """get index of dictionary which day value equals number"""
+ index = 0
+ for i, day in enumerate(data):
+ if day["day"] == number:
+ index = i
+ return index
if __name__ == '__main__':
app.run()