From: Seth Woodworth Date: Wed, 23 Jan 2013 05:39:51 +0000 (-0500) Subject: cleanup gdrive, remove dead code path (is_pdf) and refactor variable names X-Git-Tag: release-20150131~551^2~3 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ec429394e7516106dee15363471116cb22e5b48d;p=oweals%2Fkarmaworld.git cleanup gdrive, remove dead code path (is_pdf) and refactor variable names --- diff --git a/karmaworld/apps/notes/gdrive.py b/karmaworld/apps/notes/gdrive.py index d33514f..9f815f3 100644 --- a/karmaworld/apps/notes/gdrive.py +++ b/karmaworld/apps/notes/gdrive.py @@ -129,41 +129,32 @@ def convert_with_google_drive(note): # TODO: wrap this in a try loop that does a token refresh if it fails file_dict = service.files().insert(body=resource, media_body=media, convert=True).execute() - # set note.is_pdf - if file_type == 'application/pdf': - # Get a new copy of the file from the database with the new metadata from filemeta - new_file = File.objects.get(id=note.id) - # If it's a pdf, instead save an embed_url from resource['selfLink'] - new_file.is_pdf = True - new_file.embed_url = file_dict[u'selfLink'] - new_file.gdrive_url = file_dict[u'downloadUrl'] - else: - # get the converted filetype urls - download_urls = {} - download_urls['html'] = file_dict[u'exportLinks']['text/html'] - download_urls['text'] = file_dict[u'exportLinks']['text/plain'] - content_dict = {} - - - for download_type, download_url in download_urls.items(): - print "\n%s -- %s" % (download_type, download_urls) - resp, content = http.request(download_url, "GET") - - - if resp.status in [200]: - print "\t downloaded!" - # save to the File.property resulting field - content_dict[download_type] = content - else: - print "\t Download failed: %s" % resp.status - - # Get a new copy of the file from the database with the new metadata from filemeta - new_file = Note.objects.get(id=note.id) - - # set the .odt as the download from google link - new_file.gdrive_url = file_dict[u'exportLinks']['application/vnd.oasis.opendocument.text'] - new_file.html = content_dict['html'] - new_file.text = content_dict['text'] + # get the converted filetype urls + download_urls = {} + download_urls['html'] = file_dict[u'exportLinks']['text/html'] + download_urls['text'] = file_dict[u'exportLinks']['text/plain'] + content_dict = {} + + + for download_type, download_url in download_urls.items(): + print "\n%s -- %s" % (download_type, download_urls) + resp, content = http.request(download_url, "GET") + + + if resp.status in [200]: + print "\t downloaded!" + # save to the File.property resulting field + content_dict[download_type] = content + else: + print "\t Download failed: %s" % resp.status + + # Get a new copy of the file from the database with the new metadata from filemeta + new_note = Note.objects.get(id=note.id) + + # set the .odt as the download from google link + new_note.gdrive_url = file_dict[u'exportLinks']['application/vnd.oasis.opendocument.text'] + new_note.html = content_dict['html'] + new_note.text = content_dict['text'] # Finally, save whatever data we got back from google - new_file.save() + new_note.save()