-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpb.py
63 lines (42 loc) · 1.35 KB
/
cpb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -*- coding:cp1251 -*-
#!/usr/bin/python
from zeep import Client
import datetime
import codecs
import os
def get_data(bank, required_time, url):
client = Client(url)
result = client.service.Data135FormFullXML(bank, required_time)
header = "Year;V;C"
filename = bank + '.xlsx'
# Check if file already exists. If yes - append to it, otherwise - create a new one
if os.path.exists(filename):
append_write = 'a'
else:
append_write = 'w'
with codecs.open(filename, append_write,'utf-8') as ofile:
for i in result.xpath('F135_3'):
V = i.xpath('V3')
C = i.xpath('C3')
if len(V) == 0:
pass
else:
line = "%s;%s;%s" % (required_time, V[0].text, C[0].text)
ofile.write(line + '\n')
print line
def main():
url = 'http://www.cbr.ru/CreditInfoWebServ/CreditOrgInfo.asmx?WSDL'
bank = '1481'
start_year = 2011
end_year = 2017
day = 1
for i in range(end_year - start_year):
year = start_year + i + 1
for j in range(12):
month = j + 1
required_time = datetime.date(year, month, day)
get_data(bank, required_time, url)
# bank_list = ['1481']
# 1481 - Sberbank
if __name__ == "__main__":
main()