-
Notifications
You must be signed in to change notification settings - Fork 0
/
jpDataLNI.py
108 lines (100 loc) · 3.92 KB
/
jpDataLNI.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
# -*- coding: utf-8 -*-
import os, csv
from . import jpDataUtils
def getPrefsOrRegionsByMapCode(code_map):
file_path = os.path.join(
os.path.dirname(__file__), "csv", "LandNumInfo_" + code_map + ".csv"
)
prefs_or_regions = []
with open(file_path, "r") as f:
csvreader = csv.DictReader(f)
for row in csvreader:
if len(row) >= 2:
prefs_or_regions.append(row["availability"])
unique_prefs_or_regions = []
for x in prefs_or_regions:
if x not in unique_prefs_or_regions:
unique_prefs_or_regions.append(x)
return unique_prefs_or_regions
def getYearsByMapCode(code_map, name_pref=None):
file_path = os.path.join(
os.path.dirname(__file__), "csv", "LandNumInfo_" + code_map + ".csv"
)
years = []
with open(file_path, "r") as f:
csvreader = csv.DictReader(f)
for row in csvreader:
if len(row) >= 2 and name_pref is None:
years.append(row["year"])
elif len(row) >= 2 and row["availability"] == name_pref:
years.append(row["year"])
unique_years = []
for x in years:
if x not in unique_years:
unique_years.append(x)
return unique_years
def getDetailsByMapCodePrefNameYear(code_map, name_pref, year):
file_path = os.path.join(
os.path.dirname(__file__), "csv", "LandNumInfo_" + code_map + ".csv"
)
details = []
with open(file_path, "r") as f:
csvreader = csv.DictReader(f)
for row in csvreader:
if len(row) >= 2 and row["availability"] == name_pref and row["year"] == year:
details.append(row["detail1"] + ' ' + row["detail2"])
unique_details = []
for x in details:
if x not in unique_details:
unique_details.append(x)
return unique_details
def getShapeByMapCodePrefNameYearDetail(code_map, name_pref, year, detail):
file_path = os.path.join(
os.path.dirname(__file__), "csv", "LandNumInfo_" + code_map + ".csv"
)
details = []
with open(file_path, "r") as f:
csvreader = csv.DictReader(f)
for row in csvreader:
if len(row) >= 2 and row["availability"] == name_pref and row["year"] == year and row["detail1"] + ' ' + row["detail2"] == detail:
details.append(row["shp"])
unique_details = []
for x in details:
if x not in unique_details:
unique_details.append(x)
return unique_details
def getUrlCodeZipByPrefName(code_map, name_pref, year, detail = None):
# name_pref = jpDataUtils.getPrefNameByCode(code_pref)
file_path = os.path.join(
os.path.dirname(__file__), "csv", "LandNumInfo_" + code_map + ".csv"
)
code_pref = jpDataUtils.getPrefCodeByName(name_pref)
x = {
"year": "",
"url": "",
"code_map": code_map,
"zip": "",
"shp": "",
"altdir": "",
}
with open(file_path, "r") as f:
csvreader = csv.DictReader(f)
for row in csvreader:
if (
len(row) >= 2
and row["availability"] == name_pref
and row["year"] == year
):
if detail is None:
x["year"] = row["year"]
x["url"] = row["url"].replace("code_pref",code_pref)
x["zip"] = row["zip"].replace("code_pref",code_pref)
x["shp"] = row["shp"].replace("code_pref",code_pref)
x["altdir"] = row["altdir"].replace("code_pref",code_pref)
elif detail == row["detail1"] + ' ' + row["detail2"]:
x["year"] = row["year"]
x["url"] = row["url"].replace("code_pref",code_pref)
x["zip"] = row["zip"].replace("code_pref",code_pref)
x["shp"] = row["shp"].replace("code_pref",code_pref)
x["altdir"] = row["altdir"].replace("code_pref",code_pref)
return x