# 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()