# Copyright (C) 2012 FinalsClub Foundation
import datetime
+from ENML2HTML import ENMLToHTML
import magic
import mimetypes
import os
return file_dict
+
def convert_with_google_drive(note):
""" Upload a local note and download HTML
using Google Drive
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]
+++ /dev/null
-#!/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