-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprocess.py
executable file
·148 lines (134 loc) · 5.36 KB
/
process.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python
# -*- coding: utf8 -*-
import sys, os, urllib, urllib2, urlparse
from BeautifulSoup import BeautifulSoup, BeautifulStoneSoup
BASE_URL = "http://www.mosgorzdrav.ru/mgz/komzdravsite.nsf/va_WebPages/sys_DigitsList_%d"
NUM_LIST_PAGES = 231
def extract_stats():
f2 = open('extracted.txt', 'r')
ftime = open('timeseries.csv', 'w')
ftime.write("thedate|num_rides|num_childrides|text\n")
i = 0
for l in f2:
l = l.strip()
i += 1
if i == 1: continue
thedate, text, url, filename = l.split('|')
print url
fsave = open('data/' + filename, 'r')
page = BeautifulSoup(fsave.read())
fsave.close()
texts = page.findAll('font')
for t in texts:
if t.string.find(u'Всего выездов:') > -1:
text = t.string.split(u'Всего выездов:', 1)[1]
words = text.split()
total = '0'
children = '0'
if words[0].strip(',').isdigit(): total = words[0].strip(',').strip()
text2 = text.split(u'к детям', 1)
if len(text2) > 1:
children = text2[-1].strip(':').strip().strip(';').strip(',')
ftime.write(('%s|%s|%s|%s\n' %(thedate, total, children, text.strip())).encode('utf8'))
break
ftime.close()
f2.close()
def extract_dead():
f2 = open('extracted.txt', 'r')
ftime = open('timeseries_dead.csv', 'w')
ftime.write("thedate|dead|dead_children|text\n")
i = 0
for l in f2:
l = l.strip()
i += 1
if i == 1: continue
thedate, text, url, filename = l.split('|')
print url
fsave = open('data/' + filename, 'r')
page = BeautifulSoup(fsave.read())
fsave.close()
texts = page.findAll('font')
for t in texts:
if t.string.find(u'трупов:') > -1:
text = t.string.split(u'трупов:', 1)[1]
words = text.split()
total = '0'
children = '0'
if words[0].strip(',').isdigit(): total = words[0].strip(',').strip()
if total == '-': total = '0'
text2 = text.split(u'детей:', 1)
if len(text2) > 1:
children = text2[-1].strip(':').strip().strip(';').strip(',').strip('.').strip()
if children == '-': children = '0'
ftime.write(('%s|%s|%s|%s\n' %(thedate, total, children, text.strip())).encode('utf8'))
break
ftime.close()
f2.close()
def extract_hosp():
f2 = open('extracted.txt', 'r')
ftime = open('timeseries_hosp.csv', 'w')
ftime.write("thedate|hosp|hosp_children|text\n")
i = 0
for l in f2:
l = l.strip()
i += 1
if i == 1: continue
thedate, text, url, filename = l.split('|')
print url
fsave = open('data/' + filename, 'r')
page = BeautifulSoup(fsave.read())
fsave.close()
texts = page.findAll('font')
for t in texts:
if t.string.find(u'госпитализировано') > -1:
text = t.string.split(u'госпитализировано', 1)[1].strip(':')
words = text.split()
total = '0'
children = '0'
if words[0].strip(',').isdigit(): total = words[0].strip(',').strip()
if total == '-': total = '0'
text2 = text.split(u'детей:', 1)
if len(text2) > 1:
children = text2[-1].strip(':').strip().strip(';').strip(',').strip('.').strip()
if children == '-': children = '0'
ftime.write(('%s|%s|%s|%s\n' %(thedate, total, children, text.strip())).encode('utf8'))
break
ftime.close()
f2.close()
def extract_hosp2():
f2 = open('extracted.txt', 'r')
ftime = open('timeseries_hosp2.csv', 'w')
ftime.write("thedate|total_hosp|text\n")
i = 0
for l in f2:
l = l.strip()
i += 1
if i == 1: continue
thedate, text, url, filename = l.split('|')
print url
fsave = open('data/' + filename, 'r')
page = BeautifulSoup(fsave.read())
fsave.close()
texts = page.findAll('font')
for t in texts:
if not t.string: break
if t.string.find(u'на госпитализацию') > -1:
text = t.string.split(u'на госпитализацию', 1)[1].strip(':')
words = text.split()
total = '0'
children = '0'
try:
total = words[0].strip(',').strip()
except:
total = ''
if not total.isdigit(): continue
if total == '-': total = '0'
ftime.write(('%s|%s|%s\n' %(thedate, total, text.strip())).encode('utf8'))
break
ftime.close()
f2.close()
if __name__ == "__main__":
# extract_stats()
# extract_dead()
# extract_hosp()
extract_hosp2()