summaryrefslogtreecommitdiff
path: root/app/books/kindleparser.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2014-05-23 11:28:10 -0400
committerluxagraf <sng@luxagraf.net>2014-05-23 11:28:10 -0400
commit518b2d618bc10f93cfa44a83715593b8358eb9ce (patch)
treea07993c3ae31bed42f32c0e00788989568790716 /app/books/kindleparser.py
parent4bae11bb25a8e3c43118891d17fd8e981ecf8dc6 (diff)
minor refactor to adoipt pep8 and pyflakes coding styles and clean up
some cruft that's been hangin round for years
Diffstat (limited to 'app/books/kindleparser.py')
-rw-r--r--app/books/kindleparser.py31
1 files changed, 17 insertions, 14 deletions
diff --git a/app/books/kindleparser.py b/app/books/kindleparser.py
index 6b708d9..aaa742f 100644
--- a/app/books/kindleparser.py
+++ b/app/books/kindleparser.py
@@ -8,6 +8,7 @@ import datetime
from django.core.exceptions import ObjectDoesNotExist
from books.models import Book, BookHighlight
+
def parse_kindle_clippings(path):
json_data = open(path)
data = json.load(json_data)
@@ -20,11 +21,11 @@ def parse_kindle_clippings(path):
body_markdown = clip['content']
except KeyError:
body_markdown = ""
- try:
+ try:
location = int(clip['locationRange'])
except:
location = 0
- try:
+ try:
page = int(clip['pageRange'])
except:
page = 0
@@ -37,21 +38,23 @@ def parse_kindle_clippings(path):
row = Book.objects.get(title=clip['title'])
except ObjectDoesNotExist:
b, created = Book.objects.get_or_create(
- title = clip['title'],
- author_name = author_name,
- read_date = clip_date
+ title=clip['title'],
+ author_name=author_name,
+ read_date=clip_date
)
try:
- #see if we already this highlight
- row = BookHighlight.objects.get(book__title=clip['title'], date_added=clip_date )
- #if we don't create a new book highlight
+ #see if we already this highlight
+ row = BookHighlight.objects.get(
+ book__title=clip['title'],
+ date_added=clip_date
+ )
+ #if we don't create a new book highlight
except ObjectDoesNotExist:
book = Book.objects.get(title=clip['title'])
bh, created = BookHighlight.objects.get_or_create(
- book = book,
- page = page,
- location = location,
- date_added = clip_date,
- body_markdown = body_markdown
+ book=book,
+ page=page,
+ location=location,
+ date_added=clip_date,
+ body_markdown=body_markdown
)
-