Esempio n. 1
0
    def update_one_bulk(self, schema, collection, docs, *key):
        obj = self.get_table_obj(schema, collection)
        queries = []
        for doc in docs:
            key_made = {k: doc[k] for k in key}
            queries.append(UpdateOne(key_made, {'$set': doc}, upsert=True))

        if queries:
            result = obj.bulk_write(queries)
            print_bulk_result(result)
        else:
            print('Record Not Found.')
Esempio n. 2
0
def load_burial_set_geocode(collection):
    with MyMongo() as db:
        # cemetry = list(db.find('burial', 'cemetry', {'lat': {'$exists': False}}))
        burial = list(
            db.find('burial', collection, {'lat': {
                '$exists': False
            }}))

    # print(cemetry[1])
    # print(enshrinement)

    queries = []
    for doc in burial:
        address = get_geocode_from_address(doc['주소'], None, doc['시설명'])
        if type(address) == str:
            print('Address Not Found.')
            print(doc['주소'], doc['시설명'])
            continue

        # lat, lng = address['y'], address['x']
        doc['lat'] = address['y']
        doc['lng'] = address['x']
        doc['filter0'] = address.get('region_1depth_name')
        doc['filter1'] = address.get('region_2depth_name')
        doc['filter2'] = address.get('region_3depth_name')

        queries.append(
            UpdateOne({'_id': doc['_id']}, {'$set': doc}, upsert=True))

        if len(queries) == 20:
            with MyMongo() as db:
                obj = db.get_table_obj('burial', collection)
                result = obj.bulk_write(queries)
                print_bulk_result(result)
                queries.clear()

    with MyMongo() as db:
        obj = db.get_table_obj('burial', collection)
        result = obj.bulk_write(queries)
        print_bulk_result(result)
        queries.clear()
Esempio n. 3
0
def load_market_set_geocode(schema, collection):
    with MyMongo() as db:
        # parking = list(db.find('market', collection, {'위도': '0.000'}))
        docs = list(db.find(schema, collection, {'위도': np.nan}))

    # print(cemetry[1])
    # print(enshrinement)

    queries = []
    for doc in docs:
        address = get_geocode_from_address(str(doc['소재지도로명주소']), None,
                                           str(doc['시장명']))
        if type(address) == str:
            print('Address Not Found.')
            print(doc['소재지도로명주소'], doc['시장명'])
            continue

        # lat, lng = address['y'], address['x']
        doc['위도'] = address['y']
        doc['경도'] = address['x']
        doc['filter0'] = address.get('region_1depth_name')
        doc['filter1'] = address.get('region_2depth_name')
        doc['filter2'] = address.get('region_3depth_name')

        queries.append(
            UpdateOne({'_id': doc['_id']}, {'$set': doc}, upsert=True))

        if len(queries) == 20:
            with MyMongo() as db:
                obj = db.get_table_obj(schema, collection)
                result = obj.bulk_write(queries)
                print_bulk_result(result)
                queries.clear()

    with MyMongo() as db:
        obj = db.get_table_obj(schema, collection)
        result = obj.bulk_write(queries)
        print_bulk_result(result)
        queries.clear()
Esempio n. 4
0
        name_kr = names[0].strip()
        name_hj = names[2].strip()
        table = body.find("table", class_="table-user-information")
        trs = table.find_all("tr")
        # print(trs)

        member_dict = {'seq': seq, 'empNm': name_kr, 'hjNm': name_hj}
        for tr in trs:
            tds = tr.find_all("td")
            key = tds[0].get_text().strip()
            value = tds[1].get_text().strip()

            if key == "정당":
                value = value.replace("● ", "")
            if key == "학력" or key == "주요경력":
                value = value.replace("\n", " | ")
            if key == "소속위원회":
                value = ' | '.join(
                    list(filter(lambda x: x != '', value.split('위원회'))))

            member_dict[key] = value
            # print(key, value)

        queries.append(
            UpdateOne({'seq': seq}, {'$set': member_dict}, upsert=True))

    with MyMongo() as db:
        table_watch_member = db.get_table_obj('assembly', 'watch_member')
        result = table_watch_member.bulk_write(queries)
        print_bulk_result(result)
Esempio n. 5
0
            print(f'confer_id: {confer_id} has blank table.')
            continue
        trs = table.table.find_all('tr')

        for tr in trs:
            tds = tr.find_all('td')
            party = tds[0].string.split()[0]

            member_a = tds[1].find_all('a')
            for a in member_a:
                seq = re.search(r'member_seq=(\d+)', a['href']).group(1)
                empNm = a.string
                rollbook_dict = {
                    'confer_id': confer_id,
                    'attended': attended,
                    'party': party,
                    'seq': seq,
                    'empNm': empNm,
                }
                query_on_watch_rollbook.append(InsertOne(rollbook_dict))

    with MyMongo() as db:
        table_watch_conference = db.get_table_obj('assembly',
                                                  'watch_conference')
        result_watch_conference = table_watch_conference.bulk_write(query_on_watch_conference)
        table_watch_rollbook = db.get_table_obj('assembly', 'watch_rollbook')
        result_watch_rollbook = table_watch_rollbook.bulk_write(query_on_watch_rollbook)

        print_bulk_result(result_watch_conference)
        print_bulk_result(result_watch_rollbook)