Basics of Evernote workaround
authorCharles Connell <charles@connells.org>
Wed, 18 Dec 2013 03:47:59 +0000 (22:47 -0500)
committerCharles Connell <charles@connells.org>
Wed, 18 Dec 2013 03:52:09 +0000 (22:52 -0500)
karmaworld/apps/notes/gdrive.py
karmaworld/apps/notes/tasks.py [deleted file]
reqs/common.txt

index 5a426ba624a6555fab11955c52691f853fda44da..cd540e7f2f311f312edade48a222b7d07d05c13f 100644 (file)
@@ -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 (file)
index d27e8e6..0000000
+++ /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
index 0c215a43bf072d60f2ba81830b43d7612eec7b3b..d48d7aedbfb7c1881b187ae3b9997fd01bd12e09 100644 (file)
@@ -15,3 +15,4 @@ filemagic==1.6
 fabric-virtualenv
 requests
 beautifulsoup4
+git+https://github.com/btbonval/ENML_PY.git