Spaces:
Runtime error
Runtime error
File size: 1,325 Bytes
2fe14e5 b8a5de3 f74c1d3 2fe14e5 00b352c d4d9b2b 7a02370 00b352c 7a02370 2fe14e5 7a02370 ef4c471 |
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 |
#code by princesslucy
import json, time, requests, os, sys
from tqdm import tqdm
from util.dbquery import load_json, insert_data, getDataNum
def fetch_and_store_data():
print("μ΅μ λ°μ΄ν°λ₯Ό λ°μμ€λ μ€μ
λλ€. λ°μ΄ν°λ₯Ό λ°λ λμ€ νλ‘κ·Έλ¨μ μ’
λ£νμ§ λ§μμμ€.")
KEY = os.environ['PRODUCT_PRICE_API']
i = 1
while i + 999 <= 100000:
url = f'http://openAPI.seoul.go.kr:8088/{KEY}/json/ListNecessariesPricesService/{i}/{i+999}'
response = requests.get(url)
decoded = response.content.decode('utf-8')
data = json.loads(decoded)
# λ°μ΄ν°λ₯Ό λ°λ‘ μ²λ¦¬νκ³ λ°μ΄ν°λ² μ΄μ€μ μ½μ
inserted_rows = insert_data(data)
if inserted_rows == 0: # μλ‘ μ½μ
λ λ°μ΄ν°κ° μμΌλ©΄ 루ν νμΆ
print("\nλ°μ΄ν°λ² μ΄μ€μ μλ‘μ΄ λ°μ΄ν°κ° μμ΅λλ€. μ
λ°μ΄νΈλ₯Ό μ€λ¨ν©λλ€.")
break
i += 1000
sys.stdout.write('\r')
completion = min(int(i/1000), 100)
sys.stdout.write("[%-50s] %d%%" % ('='*int(completion/2), completion))
sys.stdout.flush()
current_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
print(f"\nλ°μ΄ν° μ
λ°μ΄νΈ μλ£ μκ°: {current_time}")
print("μ
λ°μ΄νΈ μλ£") |