import requests
point=[]
c="17378"
city=[]
f=open("line.csv","r",encoding="UTF-8")
for line in f:
x=line.split(",")
q=x[7].strip()
if q==c:city.append(x[5])
f.close()
dic=[]
for c1 in city:
h=0
if c1 in dic:h=100
if h<50:dic.append(c1)
for d1 in dic:
c1=d1
if len(c1)==4:p1=c1[0:1]
if len(c1)==5:p1=c1[0:2]
if len(c1)==4:c1="0"+c1
url = 'https://opendata.resas-portal.go.jp/api/v1/population/composition/perYear?cityCode='+c1+"&prefCode="+p1
KEY = 'QTPchshTtS5JGmrEw0ELladqSbGwnKxh5KVqmZvU'
query = {'X-API-KEY': KEY}
r = requests.get(url, headers=query)
m=r.text
mode=0
p1=-1
a=[]
while mode<50:
p1=m.find("{",p1+1)
if p1>-1:a.append(p1)
if p1<0:mode=100
b=[]
mode=0
p1=-1
while mode<50:
p1=m.find("}",p1+1)
if p1>-1:b.append(p1)
if p1<0:mode=100
point_a=[]
for a1 in a:
point_a.append(-1)
for j in range(len(b)):
asx=-1
for i in range(len(a)):
h=0
if point_a[i]==-1:h=h+1
if a[i]<b[j]:h=h+1
if h==2:asx=i
point_a[asx]=j
delta=[]
for i in range(len(a)):
a1=a[i]
j=point_a[i]
b1=b[j]
sig=m[a1+1:b1]
h=0
if "}" in sig:h=100
if h<50:delta.append(sig)
c1="year"
c2="value"
yy=[]
vv=[]
for de in delta:
p1=de.find(c1)
p1=de.find(":",p1)
p2=de.find(",",p1)
if p2==-1:p2=len(de)
w1=de[p1+1:p2]
yy.append(w1)
p1=de.find(c2)
p1=de.find(":",p1)
p2=de.find(",",p1)
if p2==-1:p2=len(de)
w1=de[p1+1:p2]
vv.append(w1)
point.append(vv)
print(yy)
for j in range(8):
z=0
for p1 in point:
z=z+int(p1[j])
print(z)
最終更新:2018年02月10日 18:17