Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- from xml.dom.minidom import parse
- import os
- import sys
- import time
- START_TIMESTAMP_SECS = 1294290000000
- HOUR_TO_MILLISECS = 60 * 60 * 1000
- RECEIVED, SENT = (1, 2)
- def format_time(timestamp_in_ms):
- return time.strftime("%a, %d %b %Y %H:%M:%S",
- time.gmtime(timestamp_in_ms / 1000))
- def convert_est_to_utc(timestamp_in_ms):
- return timestamp_in_ms + (5 * HOUR_TO_MILLISECS)
- def replace_timestamps(document):
- smses = document.getElementsByTagName('sms')
- for sms in smses:
- received = int(sms.getAttribute('type')) == RECEIVED
- date = int(sms.getAttribute('date'))
- if received and date > START_TIMESTAMP_SECS:
- sms.setAttribute('date', unicode(convert_est_to_utc(date)))
- def main():
- if (len(sys.argv) < 2):
- sys.exit('Usage: %s sms_file' % os.path.basename(__file__))
- sms_file = sys.argv[1]
- document = parse(sms_file)
- replace_timestamps(document)
- print(document.toprettyxml(encoding='utf-8'))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement