获取win7时区所有信息

打开命令行工具:

tzutil /l

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

获取win7时区所有信息_第1张图片

 

 1 # -*- utf-8 -*-
 2 
 3 """获取win7所有时区信息,并写入到sql语句中
 4 
 5 Usage: python data.py -f data.txt -o data.sql
 6 """
 7 
 8 if __name__ == "__main__":
 9     import re
10     import os
11     import sys
12 
13     file_path = ''
14     output_file_path = ''
15 
16     if len(sys.argv)!=5 or not (sys.argv[1].startswith('-') and sys.argv[3].startswith('-')):
17         print "Usage: " + sys.argv[0] + " -f data.txt -o data.sql"
18         sys.exit()
19     else:
20         file_path = sys.argv[2]
21         output_file_path = sys.argv[4]
22 
23     try:
24         os.system("tzutil /l > %s" % file_path)
25         file_handler = open(file_path, 'r+')
26     except:
27         print "Wrong file path."
28         sys.exit()
29 
30     sql = """insert into region_info (region_time, description) VALUES \n"""
31     pattern = r'(UTC([+-]\d+):00)\w+'
32 
33     group_one = ''
34     group_two = ''
35     group_three = ''
36     for line in file_handler:
37         if line.strip():
38             result = re.search(r'(\(UTC(([+-]\d+):(\d+))?\))(.*)', line)
39             if result:
40                 group_one = result.group(1)
41 
42                 if result.group(2):
43                     group_two = result.group(3)
44                     group_three = result.group(4)
45                     if group_three=='30':
46                         group_two = str(int(group_two))+'.5'
47                     else:
48                         group_two = str(int(group_two))
49 
50                     sql += """(%s, '{"%s","%s""" % (group_two, line.strip(), group_one)
51                 else:
52                     sql += """(0, '{"%s","%s""" % (line.strip(), "(UTC)")
53 
54             else:
55                 sql += """%s"}'),\n""" % line.strip()
56 
57     file_handler.close()
58 
59     sql = sql[0:-2] + ';'
60 
61     try:
62         file_handler = open(output_file_path, 'w+')
63         file_handler.write(sql)
64         file_handler.close()
65     except:
66         print "Wrong output file path."
67         sys.exit()

 

你可能感兴趣的:(win7)