代码拉取完成,页面将自动刷新
同步操作将从 小为/PTHospital.chrome 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2016年5月4日
从 https://raw.githubusercontent.com/langhua9527/Hospital/ 中解析数据
@author: hustcc
'''
import requests
import os
import json
import sys
sys
def get_res_content():
r = requests.get("https://raw.githubusercontent.com/open-power-workgroup/Hospital/master/resource/API_resource/hospital_list.json").json()
return r
def process_json(content_json):
hospital_res = {}
cnt = 1
for city in content_json:
hospitals = content_json[city]
for name in hospitals:
hospital = hospitals[name]
websites = hospital.get(u"网址") or []
phones = hospital.get(u"电话") or []
if len(phones) > 2:
phones = phones[0:2]
# 对于没有网址的医院,使用pt_num
if len(websites) == 0:
hospital_res["pt" + str(cnt)] = [name, " / ".join(phones)]
cnt += 1
for website in websites:
website = website.replace("http://", "").replace("https://", "").replace("/", "")
hospital_res[website] = [name, " / ".join(phones)]
return hospital_res;
def output_raw(hospital_res):
try:
filename = os.path.join(os.getcwd(), "PTHospitalList.js")
output = json.dumps(hospital_res, indent=2)
output = "var PTHospitalList = " + output
file_object = open(filename, 'w')
file_object.write(output)
file_object.close( )
except IOError: # file don't exist
print(u"File save Error", filename)
if __name__ == '__main__':
content_json = get_res_content()
hos = process_json(content_json)
output_raw(hos)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。