获取win7时区所有信息

打开命令行工具:

tzutil /l

# 或者输入到文件中
tzutil /l > data.txt

获取win7时区所有信息

 # -*- utf-8 -*-

 """获取win7所有时区信息,并写入到sql语句中

 Usage: python data.py -f data.txt -o data.sql
""" if __name__ == "__main__":
import re
import os
import sys file_path = ''
output_file_path = '' if len(sys.argv)!=5 or not (sys.argv[1].startswith('-') and sys.argv[3].startswith('-')):
print "Usage: " + sys.argv[0] + " -f data.txt -o data.sql"
sys.exit()
else:
file_path = sys.argv[2]
output_file_path = sys.argv[4] try:
os.system("tzutil /l > %s" % file_path)
file_handler = open(file_path, 'r+')
except:
print "Wrong file path."
sys.exit() sql = """insert into region_info (region_time, description) VALUES \n"""
pattern = r'(UTC([+-]\d+):00)\w+' group_one = ''
group_two = ''
group_three = ''
for line in file_handler:
if line.strip():
result = re.search(r'(\(UTC(([+-]\d+):(\d+))?\))(.*)', line)
if result:
group_one = result.group(1) if result.group(2):
group_two = result.group(3)
group_three = result.group(4)
if group_three=='':
group_two = str(int(group_two))+'.5'
else:
group_two = str(int(group_two)) sql += """(%s, '{"%s","%s""" % (group_two, line.strip(), group_one)
else:
sql += """(0, '{"%s","%s""" % (line.strip(), "(UTC)") else:
sql += """%s"}'),\n""" % line.strip() file_handler.close() sql = sql[0:-2] + ';' try:
file_handler = open(output_file_path, 'w+')
file_handler.write(sql)
file_handler.close()
except:
print "Wrong output file path."
sys.exit()
上一篇:iOS开发(3):tips提示 | 如何提示一行文字或一个图片


下一篇:js的scroll详解