예제 #1
0
def fetch_passenger(selectdate):
    url = 'http://openapi.airport.kr/openapi/service/PassengerNoticeKR/getfPassengerNoticeIKR'
    params = {
        'selectdate': 0,
    }
    params['selectdate'] = selectdate
    df = get_df_from_url(url, params)
    idx = df.loc[df['adate'] == '합계'].index
    idxdec = idx - 1
    date = df.iloc[idxdec]['adate'].values[0]
    df.at[idx, 'adate'] = date
    df.at[idx, 'atime'] = 'total'

    with MyMongo() as db:
        passenger = db.get_table_obj('airport', 'passenger')
        passenger.delete_many({'adate': date})
        print(f'Old Data Removed from \'{passenger}\', date: {date}.')
        passenger.insert_many(df.to_dict(orient='records'))
        print(f'New Data inserted to \'{passenger}\'.')
예제 #2
0
# from pprint import pprint
from datetime import datetime
from api.common import get_df_as_per_total
from db.mongo_connection import MyMongo

url = 'http://openapi.d2b.go.kr/openapi/service/CodeInqireService/getOrntCodeList'
params = {}

df = get_df_as_per_total(url, params)
time_stamp = datetime.now()
df['update_on'] = time_stamp

with MyMongo() as db:
    prev_df = db.get_df_from_table('defense', 'orntCode')
    db.archive_complement_and_dump_new(prev_df, df, 'code', 'defense',
                                       'orntCode', 'orntCode_archive')
예제 #3
0
if __name__ == "__main__" and __package__ is None:
    import os
    import sys
    current_path = os.path.dirname(__file__)
    project_path = os.path.abspath(os.path.join(current_path, '..'))
    sys.path.append(project_path)

# from pprint import pprint
from datetime import datetime
import pandas as pd

from api.common import get_url, get_refined_dict_from_url, get_df_from_url
from db.mongo_connection import MyMongo
# from common import get_data_frame, KEY

db = MyMongo()
# tmp = list(db.assembly.member.find({}))
# df = pd.DataFrame(tmp)
# print(df.columns)

col = [
    'deptCd', 'empNm', 'engNm', 'hjNm', 'jpgLink', 'num', 'origNm',
    'reeleGbnNm', 'update_on'
]
val = [['test', 'test', 't', 't', 't', 't', 't', 't', datetime.now()]]

new = pd.DataFrame(columns=col, data=val)
db.assembly.member.insert_many(new.to_dict(orient='records'))
tmp = list(db.assembly.member.find({'deptCd': 'test'}))
print(tmp[0])