23 Star 69 Fork 21

小为 / PTHospital.chrome

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
read_from_Hospital.py 1.72 KB
一键复制 编辑 原始数据 按行查看 历史
aTool 提交于 2016-05-14 11:55 . add jshint
#!/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)
JavaScript
1
https://gitee.com/hustcc/PTHospital.chrome.git
git@gitee.com:hustcc/PTHospital.chrome.git
hustcc
PTHospital.chrome
PTHospital.chrome
master

搜索帮助