I have 100+ save file of omnigraffle, need to write a script to read then change its content.
Example one:
https://www.dropbox.com/s/97cec5err3qubgq/test.graffle?dl=0
I can open it by TextMate, file's content is in xml format
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ActiveLayerIndex</key>
<integer>0</integer>
<key>ApplicationVersion</key>
<array>
<string>com.omnigroup.OmniGraffle6</string>
<string>163.7.0.243167</string>
</array>
<key>AutoAdjust</key>
<true/>
<key>BackgroundGraphic</key>
<dict>...
So i write code to read and write that file in Python
contents = open(filename).read()
print contents
Result is
?]Ys?8~N~?֯IxgO?Gbg}?%?;)Wm?$sB
4???=?z?;F.??l??h?O????q??ش7~?z???ݓ???{??s#?8=?><?il4??Nx?????6N??o???;?hl?0?o????[XP???VF?Ӑ$d????&?????&i=????????o6??ǭN??w???????Ͷ?+/t}FF$?????
?yװ5???aWT??pT?ۥ??v??r???O??Û?u٣GR?)?I!o?~MK??|7??)[)c?'2;|@g#1?J/?!??Jo?X;ؿ??I??t%L?2Jy&?]?;)ЧC^?D????ܑ_`
????{?l?????h????]?7.?y?]7 ?&?
So how can we read that file in Python/PHP?
-
seems like you need to mess with string encodingtmthydvnprt– tmthydvnprt2016年03月13日 00:37:04 +00:00Commented Mar 13, 2016 at 0:37
1 Answer 1
The file in the link you give is compressed with gzip, either as it is stored, or compressed by dropbox when being downloaded to save space.
Either run the gunzip command on the file before using it, or use the python gzip module:
import gzip
with gzip.open(filename) as f:
contents = f.read()