Skip to content

Commit c65ac6c

Browse files
committed
batch upload
1 parent c4c1826 commit c65ac6c

File tree

7 files changed

+62
-6
lines changed

7 files changed

+62
-6
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
tmp/
2-
*.geojson
32
.vscode/
43
*.pyc
54
.DS_Store
@@ -10,4 +9,5 @@ env/
109
*.egg-info/
1110
.idea/
1211

13-
/catalog.json
12+
*.json
13+
output/

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ROSREESTR TO COORDINATE
2525
* -o - путь для полученого geojson файла
2626
* -e - параметр, определяющий точность аппроксимации
2727
* -t - тип плащади: Участки 1, ОКС 5, Кварталы 2, Районы 3, Округа 4, Границы 7, ЗОУИТ 10, Тер. зоны 6, Красные линии 13, Лес 12, СРЗУ 15, ОЭЗ 16, ГОК 9
28+
* -l - пакетная загрузка из списка в текстовом файле (тестовый файл -l list_example.txt )
2829

2930
programmatically:
3031

list_example.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
38:36:000021:1106
2+
38:06:144003:4723
3+
38:36:000033:375

script/batch.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from __future__ import print_function
2+
from script.catalog import Catalog
3+
from script.parser import Area
4+
5+
6+
def batch_parser(codes, area_type=1, media_path="", with_log=False, catalog=""):
7+
catalog = Catalog(catalog)
8+
restores = []
9+
with_error = 0
10+
success = 0
11+
from_catalog = 0
12+
print("Launched parsing of of %i areas:" % len(codes))
13+
print("================================")
14+
for c in codes:
15+
code = c.strip()
16+
print("%s" % code, end="")
17+
restore = catalog.find(code)
18+
if not restore:
19+
try:
20+
area = Area(code, media_path=media_path, area_type=area_type, with_log=with_log)
21+
restore = catalog.update(area)
22+
print(" - ok")
23+
success += 1
24+
except Exception as er:
25+
print(" - error")
26+
with_error += 1
27+
pass
28+
else:
29+
print(" - ok, from catalog")
30+
success += 1
31+
from_catalog += 1
32+
restores.append(restore)
33+
catalog.close()
34+
35+
print("=================")
36+
print("Parsing complate:")
37+
print(" success : %i" % success)
38+
print(" error : %i" % with_error)
39+
print(" from catalog: %i" % from_catalog)
40+
print("-----------------")

script/catalog.py

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def update(self, area):
4444
for a in attr_list:
4545
to_store[a] = getattr(area, a)
4646
self.store["Area"][getattr(area, "code")] = to_store
47+
return to_store
4748

4849
def close(self, buffering=-1):
4950
with open(self.file_path, "w", buffering=buffering) as local_file:

script/console.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import os
55

6+
from script.batch import batch_parser
67
from script.parser import Area, TYPES
78

89

@@ -20,19 +21,23 @@ def getopts():
2021
http://pkk5.rosreestr.ru/
2122
""")
2223
)
23-
parser.add_argument('-c', '--code', action='store', type=str, required=True,
24+
parser.add_argument('-c', '--code', action='store', type=str, required=False,
2425
help='area cadastral number')
2526
parser.add_argument('-t', '--area_type', action='store', type=int, required=False, default=1,
2627
help='area types: %s' % "; ".join(["%s:%s" % (k, v) for k, v in TYPES.items()]))
2728
parser.add_argument('-p', '--path', action='store', type=str, required=False,
2829
help='media path')
2930
parser.add_argument('-o', '--output', action='store', type=str, required=False,
3031
help='output path')
32+
parser.add_argument('-l', '--list', action='store', type=str, required=False,
33+
help='code list path')
3134
parser.add_argument('-e', '--epsilon', action='store', type=int, required=False,
3235
help='Parameter specifying the approximation accuracy. '
3336
'This is the maximum distance between the original curve and its approximation.')
3437
opts = parser.parse_args()
3538

39+
40+
3641
return opts
3742

3843

@@ -52,9 +57,15 @@ def main():
5257
area_type = opt.area_type if opt.area_type else 1
5358

5459
catalog_path = os.path.join(os.getcwd(), "catalog.json")
55-
5660
abspath = os.path.abspath(output)
57-
if code:
61+
62+
if opt.list:
63+
f = open(opt.list, 'r')
64+
codes = f.readlines()
65+
f.close()
66+
batch_parser(codes, media_path=path, area_type=area_type, catalog=catalog_path)
67+
68+
elif code:
5869
area = Area(code, media_path=path, area_type=area_type, epsilon=epsilon, with_log=True, catalog=catalog_path)
5970
geojson = area.to_geojson_poly()
6071
if geojson:

script/parser.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def __init__(self, code="", area_type=1, epsilon=5, media_path="", with_log=Fals
122122
image = self.download_image(f)
123123
if image:
124124
self.get_geometry()
125-
if self.catalog and self.catalog.store:
125+
if catalog:
126126
self.catalog.update(self)
127127
self.catalog.close()
128128
break

0 commit comments

Comments
 (0)