present-skype-messages.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # HOW TO USE THIS SCRIPT
  2. #
  3. # You can't export your skype messages DIRECTLY inside skype for some
  4. # reason. So I searched on the internet how to export messages from
  5. # skype and found this page from microsoft's support website
  6. # https://support.skype.com/en/faq/FA34894/how-do-i-export-or-delete-my-skype-data. It's
  7. # a lot of extra steps it lists to use their weird JS tool to view the
  8. # content. You can't even download it after except by doing Control +
  9. # P a lot on all your things. Which won't even do you well because
  10. # it's not going to show you the whole list of messages. So I present
  11. # to you my script.
  12. # 1. Go to the export page and sign into your microsoft account.
  13. # https://go.skype.com/export
  14. # 2. Select download your Conversations. Wait a bit and it will give
  15. # you a tar link to download.
  16. # 3. Extract the tar using your method of tar extraction. They list to
  17. # use some command line option. If it failes on one file look for some
  18. # option to keep the files. It should give you a new file called
  19. # "messages.json"
  20. # 4. Install python and run this script. python FILEOFTHISSCRIPT
  21. # 5. Now then there will be a index.html file generated and click on
  22. # the links for all your messages. You should also see a bunch of
  23. # other html files were downloaded. You could in your browser export
  24. # them as PDF or do whatever you want. It has who it was from, date
  25. # and content in plaintext.
  26. import json
  27. import urllib.parse
  28. import os.path
  29. file = "C:/SGZ_Pro/Skype chats/messages.json"
  30. with open(file,encoding="utf8") as f:
  31. data = json.loads(f.read())
  32. with open("index.html","w") as f:
  33. f.write("<h1>Skype Chats</h1>\n")
  34. for conversation in data["conversations"]:
  35. print(conversation["displayName"])
  36. file_name = str(conversation["displayName"]).replace(":","").replace(",","")+".html"
  37. with open(file_name,"w") as f:
  38. f.write(f"<h1>{conversation['displayName']}</h1>\n")
  39. files = os.listdir("media")
  40. for message in conversation["MessageList"]:
  41. with open(file_name,"a") as f:
  42. if message['messagetype'] == "RichText/UriObject":
  43. try:
  44. image = message["content"].split('doc_id="')[1].split('"')[0]
  45. for file in files:
  46. if file.endswith(".json"):
  47. pass
  48. else:
  49. if image in file:
  50. f.write(f'<img src="./media/{file}" width=50% height=auto>')
  51. except:
  52. print("ERROR")
  53. else:
  54. f.write(f"<h2>{message['from']} on {message['originalarrivaltime']}</h2>\n<p>{message['content'].encode('utf-8').decode('ascii','ignore')}</p>")
  55. with open("index.html","a") as f:
  56. f.write(f"<li><a href='./{urllib.parse.quote(file_name)}'>{conversation['displayName']}</a></li>")