1seok2

feat: update database

......@@ -4,17 +4,19 @@ from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from config.admin import ID, PW, LOCAL_PROJECT_PATH
from config.URLs import INSTAGRAM_URL
from config.firebase import update_data
def check_people(driver, type):
def get_description(driver):
element = driver.find_element_by_css_selector('.Igw0E .IwRSH .eGOV_ ._4EzTm')
data = element.get_attribute('innerHTML')
return str(data)
def check_people(driver):
result = []
navigations = driver.find_elements_by_class_name('-nal3')
if type == "followers":
navigations[1].click()
elif type == "following":
navigations[2].click()
navigations[1].click()
time.sleep(2)
elem = driver.find_elements_by_css_selector('.Jv7Aj ._0imsa')
......@@ -36,8 +38,10 @@ def login(driver):
def get_list(insta_id, driver):
desc = get_description(driver)
# check followers
followers_list = check_people(driver, "followers")
followers_list = check_people(driver)
# close followers
driver.find_element_by_css_selector('.WaOAr .wpO6b').click()
......@@ -47,8 +51,9 @@ def get_list(insta_id, driver):
data = {
"followers": followers_list,
"insta_id": insta_id,
"description": desc,
"follower_num": len(followers_list)
}
update_data(insta_id, data)
return data
......
def update_users_data(data):
\ No newline at end of file
......@@ -25,4 +25,4 @@ def search(insta_id):
if __name__ == '__main__':
os.putenv('NLS_LANG', '.UTF8')
cx_Oracle.init_oracle_client(lib_dir="/Users/choewonseog/Downloads/instantclient_19_8")
print(search('__tester2__').data)
\ No newline at end of file
print(search('__tester2__').data)
......
from crawler.crawler_instagram import crawler_instagram
import json
import cx_Oracle
import os
from config.key import DATABASE_ID, DATABASE_PW
from config.URLs import DATABASE_URL
from flask import jsonify
# data = {
# "followers": followers_list,
# "insta_id": insta_id,
# "description": desc,
# "follower_num": len(followers_list)
# }
def update(insta_id):
data = {}
try:
data = crawler_instagram(insta_id)
except Exception as e:
print(e)
connection = cx_Oracle.connect(DATABASE_ID, DATABASE_PW, DATABASE_URL)
cursor = connection.cursor()
user_query = """
select * from users where user_id=\'%s\'
""" % insta_id
cursor.execute(user_query) # user가 존재하는지 확인
exist_user = cursor.fetchall()
query = ""
if len(exist_user) == 0:
query = f"""
insert into
users(user_id, description, follower_num)
values(
\'{data.user_id}\',
\'{data.description}\',
\'{data.follower_num}\'
)
"""
else:
query = f"""
update users set
user_id = \'{data.user_id}\',
description = \'{data.description}\',
follower_num = \'{data.follower_num}\'
"""
cursor.execute(query)
cursor.close()
return jsonify(data)
\ No newline at end of file
......
import cx_Oracle
import os
from flask import Flask, render_template, request, send_from_directory
from database.connect import connectDB
from router.update import update
from router.search import search
......