From 5fec49357e2fcbcf4a8a5cdef64edf59e0201a46 Mon Sep 17 00:00:00 2001 From: Charles Connell Date: Tue, 17 Dec 2013 22:47:59 -0500 Subject: [PATCH] Basics of Evernote workaround --- karmaworld/apps/notes/gdrive.py | 15 +++++++++++---- karmaworld/apps/notes/tasks.py | 22 ---------------------- reqs/common.txt | 1 + 3 files changed, 12 insertions(+), 26 deletions(-) delete mode 100644 karmaworld/apps/notes/tasks.py diff --git a/karmaworld/apps/notes/gdrive.py b/karmaworld/apps/notes/gdrive.py index 5a426ba..cd540e7 100644 --- a/karmaworld/apps/notes/gdrive.py +++ b/karmaworld/apps/notes/gdrive.py @@ -3,6 +3,7 @@ # Copyright (C) 2012 FinalsClub Foundation import datetime +from ENML2HTML import ENMLToHTML import magic import mimetypes import os @@ -161,6 +162,7 @@ def upload_to_gdrive(service, media, filename, extension=None, mimetype=None): return file_dict + def convert_with_google_drive(note): """ Upload a local note and download HTML using Google Drive @@ -238,13 +240,18 @@ def convert_raw_document(raw_document): print mimetype print "" - if mimetype == 'text/enml': mimetype = 'text/xml' + document_contents = fp_file.read() + + # Special case for Evernote documents + if raw_document.mimetype == 'text/enml': + document_contents = ENMLToHTML(document_contents) + raw_document.mimetype = 'text/html' - if mimetype == None: - media = MediaInMemoryUpload(fp_file.read(), + if raw_document.mimetype == None: + media = MediaInMemoryUpload(document_contents, chunksize=1024*1024, resumable=True) else: - media = MediaInMemoryUpload(fp_file.read(), mimetype=mimetype, + media = MediaInMemoryUpload(document_contents, mimetype=raw_document.mimetype, chunksize=1024*1024, resumable=True) auth = DriveAuth.objects.filter(email=GOOGLE_USER).all()[0] diff --git a/karmaworld/apps/notes/tasks.py b/karmaworld/apps/notes/tasks.py deleted file mode 100644 index d27e8e6..0000000 --- a/karmaworld/apps/notes/tasks.py +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env python -# -*- coding:utf8 -*- -# Copyright (C) 2012 FinalsClub Foundation - -from celery.task import task -from karmaworld.apps.notes.gdrive import convert_with_google_drive - -@task -def process_document(note): - """ Process a file with Google Drive - populates and saves the Note.html, Note.text - - :note: A `karmaworld.apps.notes.models.Note` instance associated, document or pdf file - :returns: True on success, else False - """ - print "Processing document: %s -- %s" % (note.id, note.name) - try: - convert_with_google_drive(note) - except Exception, e: - print "\terror processing doc: %s -- %s" % (note.id, note.name) - return False - return True diff --git a/reqs/common.txt b/reqs/common.txt index 0c215a4..d48d7ae 100644 --- a/reqs/common.txt +++ b/reqs/common.txt @@ -15,3 +15,4 @@ filemagic==1.6 fabric-virtualenv requests beautifulsoup4 +git+https://github.com/btbonval/ENML_PY.git -- 2.25.1