[Python] The Custom section for importing data from the Shanghai/Shanghai news

Source: Internet
Author: User

[Python] The Custom section for importing data from the Shanghai/Shanghai news

Import the Shanghai/Shanghai news

Principle: python reads the csv file output from the increase or decrease of the previous processed computing five days later.

Add "[paint]" before the file name

The drawing file and section File Format of the security photo communication letter, and the output file

Use the import function of Tongda mail to import drawing files and plate files.

Advance data:

Processed files:

Import the following sections to Tongda mail:

Key line:

Code:

1 # coding = UTF-8 2 3 # Read the csv file starting with '[paint]' 4 # copyright @ WangXinsheng 5 # http://www.cnblogs.com/wangxinsheng/ 6 import OS 7 import struct 8 import time 9 import datetime 10 11 def getPriceByte (infile, arg, code, ss, day): 12 dirc = {"-5":-3, "-3":-2, "-1":-1, "1": 1, "3": 2, "5": 3, "7": 4, "9": 5, "11 ": 6} 13 first = 0 14 second = 0 15 a = float (arg) 16 for I in [-5,-3,-, 11]: 17 ib = I-2 18 if (a> = 2 ** ib And a <2 ** I): 19 # print (str (a) + ": [" + str (2 ** ib) + ", "+ str (2 ** I) +"] "+" I: "+ str (I) +" ib: "+ str (ib )) 20 first = ib 21 break; 22 # print (first) 23 chushu = 2 ** first 24 if (arg> = chushu * 2 ): 25 second = arg/chushu 26 # print (second) 27 second = int (second * 64) 28 else: 29 second = arg/chushu-1 30 # print (second) 31 second = int (second * 128) 32 33 if (first <0): 34 first = 64 + dirc [str (first)] 35 else: 36 first = 63 + dirc [str (first)] 37''' 38 print (first) 39 print (second) 40 print (struct. pack ('B', first) 41 print (struct. pack ('B', second) 42 ''' 43 # print (struct. pack ('B', first) 44 # print (struct. pack ('B', second) 45 46 infile. write (struct. pack ('B', ss) 47 infile. write (code. encode () 48 infile. write (B '\ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 ') 49 infile. write (B '\ x03') 50 infi Le. write ('standk '. encode () 51 infile. write (B '\ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 ') 52 infile. write (B '\ x04') 53 infile. write (B '\ x00') 54 infile. write (B '\ x1a \ x10 \ x0 0 \ x00') 55 infile. write (struct. pack ('I', int (day) 56 infile. write (B '\ x00 \ x00') 57 infile. write (struct. pack ('B', second) 58 infile. write (struct. pack ('B', first) 59 infile. write (B '\ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ X00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ xdcz3 \ x01 \ x01 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x0 0 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x0 0 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 \ x00 ') 60 61 print (str (code) +': Already on '+ day +, price: "+ str (arg) +" Add Tag ") 62 # infile = open (" tdxline. eld "," rw ") 63 # getPriceByte (5.55) 64 file = open (" WXSline. eld "," wb ") 65 zxg ='' 66 path = R '. '67 files = OS. listdir (path) 68 files. sort () 69 j = 0 70 for f in files: 71 if (f. startswith ('[paint]') and f.endswith('.csv '): 72 print ('read file:' + path + '/' + f) 73 74 f = open (path + '/' + f, 'rt ') 7 5 infos = f. readlines () 76 f. close () 77 I = 0 78 for info in infos: 79 if (I = 0): 80 I = I + 1 81 continue 82 tmp = info. split (', ') 83 if (len (tmp) <2): 84 continue 85 code = str (tmp [1]. replace ('"',''). replace ("'", "") 86 if (code. startswith ('6'): 87 ss = 1 88 else: 89 ss = 0 90 addzxg = ''91 try: 92 zxg. index (str (ss) + code) 93 minutes T: 94 addzxg = str (ss) + code + "\ n" 95 96 if (addzxg! = ''): 97 zxg = zxg + str (ss) + code +" \ n "98 if (len (tmp) <10 ): 99 continue100 101 days = tmp [0]. split ('-') 102 if (len (days) <2): 103 days = tmp [0]. split ('/') 104 105 if (len (days) <2): 106 continue107 108 if (len (days [1]) <2 ): 109 days [1] = '0' + days [1] 110 if (len (days [2]) <2 ): 111 days [2] = '0' + days [2] 112 day = days [0] + days [1] + days [2] 113 # print (day) 114 115 priceArr = tmp [9]. replace ('"',''). split ('%') 116 if (len (priceArr) <2): 117 continue118 a = float (priceArr [1]. replace ('[',''). replace (']', '') * (1-float (priceArr [0]. replace ('%', '')/100) 119 a = round (a, 2) 120 code = str (tmp [1]. replace ('"',''). replace ("'", "") 121 if (code. startswith ('6'): 122 ss = 1123 else: 124 ss = 0125 126 getPriceByte (file, a, code, ss, day) 127 ''' 128 if (j> 3): 129 break130 else: 131 j = j + 1132 ''' 133 fileA = open ("WXS condition stock. ebk "," w ") 135 fileA. write (zxg) 136 fileA. close () 137 file. close () 138 print ('processed \ n drawing file address :. /WXSline. eld ') 139 print (' \ n section file address :. /WXS condition stock. ebk ')

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.