<jupyter_start><jupyter_text>noSQL<jupyter_code>import requests
from pymongo import MongoClient
mongo_uri = "mongodb://strongadmin:<EMAIL>:35844/mydbinstance"
client = MongoClient(mongo_uri)


client.mydbinstance.collection_names()
db = client.mydbinstance
db["users"] #이렇게 하실 수도 있습니다. db.users

users_collection = db.users
# INSERT INTO users(name,email) VALUES(a,b);
some_user = {
    "name": "<NAME>",
    "email": "<EMAIL>",
}

users_collection.insert_one(some_user)
# SELECT * FROM users;
query = {}
users_collection.find_one(query)
lots_of_users = [
    {
        "name": "jyp",
        "email": "<EMAIL>",
    },
    {
        "name": "gdragoon",
        "address": "Seoul, Korea",
    },
    {
        "name": "Sbucks"
    },
]

users_collection.insert_many(lots_of_users)
query = {}
users_collection.find_one(query)

query = {}
list(users_collection.find(query))

[item["name"] for item in users_collection.find(query)]
# WHERE name = "JYP"
query = {
    "name":"jyp",
}
list(users_collection.find(query))
# WHERE name IN ('jyp','Sbucks')
query = {
    "name":{
        "$in":['jyp','Sbucks']
    }
}
list(users_collection.find(query))
# TODO: mlab에서 bigbang이라는 collection을 추가한 뒤, 아래의 문장 실행
# zigb... 에 접속해 원하는 동네의 매물 정보에 접근해 추가
# requests.get 을 이용하시면 되겠죠?

# Step 1 assign collection named "bigbang_collection"
bigbang_collection = db.bigbang
list(bigbang_collection.find({}))
# Step 2 get real estate data from zig...

response = requests.get("https://apis.zigbang.com/v3/items?detail=true&item_ids=[14398188,14388831,14359880,14470986,14398265,14399002,14454456,14359830,14455741,14398108,14407326,14538654,14271650,14169764,14317786,14360392,14284983,14455772,14507858,14328611,14324683,14455800,14472148,14321635,14397994,14062510,14398156,14164631,14398229,14512053,14454383,14511262,14536531,14269988,14187437,14467241,14448306,14226360,14467013,14317887,14513370,13416109,14165519,14263914,14222733,14254448,14467099,14203858,14328661,14241599,14407024,14138253,14527248,14175178,14147978,14328791,14178200,14348743,14428203,14218025]")

data = response.json()['items']
# Step 3 insert into bigbang_collection
# SELECT count(*) FROM bigbang;
bigbang_collection.insert_many(data)

bigbang_collection.find({}).count()
# 보증금이 2000 이하 이거나 월세가 50 이하인 매물 검색 from bigbang_collection
# rent: 월세, deposit: 보증금
query = {
    "$or":[
    {
        "item.deposit":{
        "$lte":2000,
        "$gte":100,
        }
    },
        {"item.rent":{
        "$lte": 50,
        }
    }
    ]
}

len(list(bigbang_collection.find(query)))
# naver realtime keyword
# with beautifulsoup4
from bs4 import BeautifulSoup
from time import ctime


html = requests.get('https://www.naver.com/').text
executed_time = ctime() # value1

soup = BeautifulSoup(html, 'html.parser')
kw_list = soup.find("ul", attrs={"class":"ah_l"})
all_li = kw_list.find_all("span", attrs={"class":"ah_k"})
result = [] # value2
for li in all_li:
    result.append(li.text) 

#result = ['','','']
#{"executed": "2019-01-12 17:25:00",
# "keywords": ["스카이캐슬..",""] }
nv_collection = db.nvkwlist

data = {
    "executed": executed_time,
    "keywords": result,
}

nv_collection.insert_one(data)

nv_collection.find_one({})<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15666770282872242, 'fraction_numerical': 0.16226297792974823, 'mean_word_length': 5.037523452157599, 'pattern_counts': {'":': 22, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '111423', 'license': 'MIT', 'n_tokens_mistral': 1645, 'n_tokens_neox': 1373, 'n_words': 199, 'path': 'SQL/Day20.HAVING,noSQL.ipynb', 'repo_name': 'MinJiH/TIL', 'size': '3273'}