Exemple #1
0
def init_main_table():
    university_list, college_list, company_list, facility_list, normal_list = [], [], [], [], []
    model_list: list = DBConnector.cnki_query_all()
    for model in model_list:
        model: DataModel.CNKIContent
        if '大学' in model.Organ:
            university_index = model.Organ.index('大学')
            organ = model.Organ[0:university_index + 2]
            # if '实验室' in organ:
            #    organ = organ[0:organ.index('实验室') + 3]
            university_model = DataModel.CNKILocationContent()
            university_model.Organ = organ
            university_model.ori_sid = model.sid
            university_list.append(university_model)
            continue

        if '学院' in model.Organ:
            organ = model.Organ[0:model.Organ.index('学院') + 2]
            college_model = DataModel.CNKILocationContent()
            college_model.ori_sid = model.sid
            college_model.Organ = organ
            college_list.append(college_model)
            continue

        normal_model = DataModel.CNKILocationContent()
        normal_model.ori_sid = model.sid
        normal_model.Organ = model.Organ
        normal_list.append(normal_model)
    DBConnector.db_list_writer(university_list)
    DBConnector.db_list_writer(college_list)
    DBConnector.db_list_writer(normal_list)
Exemple #2
0
def get_city_and_organ_location_by_google(start_sid):
    models = DBConnector.cnki_location_query_all_min_sid(start_sid)
    api_key = 'AIzaSyBuyQu2l_H3nCgGo84W26VwEVhFTNnm99g'
    for model in models:
        model: DataModel.CNKILocationContent
        if model.City is None:
            continue
        url = 'https://maps.googleapis.com/maps/api/geocode/json?address={0}&key={1}'.format(
            model.City, api_key)
        proxy = {
            'http': 'socks5://127.0.0.1:1086',
            'https': 'socks5://127.0.0.1:1086'
        }
        web = requests.get(url=url, proxies=proxy)
        response = json.loads(web.text)
        if response['status'] != 'OK':
            continue
        print(response['results'][0]['formatted_address'])
        location = response['results'][0]['geometry']['location']
        print(location)
        response_model = DataModel.CNKILocationContent()
        response_model.City_Longitude = location['lng']
        response_model.City_Latitude = location['lat']
        DBConnector.update_cnki_location_city_location(model.sid,
                                                       response_model)
Exemple #3
0
def get_city_and_organ_location_by_tencent(start_sid):
    models = DBConnector.cnki_location_query_all()
    api_key = 'PFSBZ-GTOKP-JWHD3-VWKIL-KI4BQ-4YFQP'
    count = 0
    for model in models:
        model: DataModel.CNKILocationContent
        if model.sid < start_sid:
            continue
        url = 'https://apis.map.qq.com/ws/geocoder/v1/?address={0}&key={1}'.format(
            model.Organ, api_key)
        web = requests.get(url)
        time.sleep(0.3)
        response = json.loads(web.text)
        print(response)
        if response['status'] != 0:
            continue
        response_model = DataModel.CNKILocationContent()
        response_model.Province = response['result']['address_components'][
            'province']
        response_model.City = response['result']['address_components']['city']
        response_model.District = response['result']['address_components'][
            'district']
        response_model.Organ_Longitude = response['result']['location']['lng']
        response_model.Organ_Latitude = response['result']['location']['lat']
        DBConnector.update_cnki_location_city(model.sid, response_model)
        count = count + 1
        if count == 5000:
            break
Exemple #4
0
def init_location_table():
    models: [DataModel.CNKIMainContent
             ] = DBConnector.query_all(DataModel.CNKIMainContent)
    organ_model_list = []
    for model in models:
        if not model.Organ:
            continue
        for organ in model.Organ.split(';'):
            organ_model = DataModel.CNKILocationContent()
            organ_model.organ_full_name = organ
            organ_model.ori_sid = model.sid
            organ_model_list.append(organ_model)
    DBConnector.db_list_writer(organ_model_list)