Guest User

Untitled

a guest
May 21st, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import gdata.docs.data
  4. import gdata.docs.client
  5.  
  6. client = gdata.docs.client.DocsClient(source = 'names-update-1')
  7. client.ssl = True
  8. client.http_client.debug = False
  9. client.ClientLogin('user.name@gmail.com', 'password', client.source)
  10. docs = client.GetEverything()
  11.  
  12. types = {
  13. 'image/vnd.djvu': '.djvu',
  14. 'chemical/x-chemdraw': '.chm',
  15. 'spreadsheet': '.xls',
  16. 'pdf': '.pdf',
  17. 'document': '.doc',
  18. 'presentation': '.ppt'
  19. }
  20.  
  21. for doc in docs:
  22. print "Processing %s" % doc.title.text
  23. ext = types[doc.get_document_type()]
  24. name = original_name = doc.title.text
  25.  
  26. # append file suffix if not present
  27. if not name.endswith(ext):
  28. name += ext
  29.  
  30. parts = name.split('.')
  31. parts.pop()
  32. name = ' '.join(parts) + ext
  33.  
  34. if name != original_name:
  35. try:
  36. print "Updating with new name %s" % name
  37. doc.title.text = name
  38. client.Update(doc)
  39. except Exception as boom:
  40. print "Epic fail", boom
Add Comment
Please, Sign In to add comment