Toggle navigation
Toggle navigation
This project
Loading...
Sign in
최원석
/
2021-1-database-project
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
1seok2
2021-06-04 01:10:50 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ef6c6d45a0446192295b937697298656547ae81a
ef6c6d45
1 parent
ad28eed3
feat: update database
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
10 deletions
crawler/crawler_instagram.py
database/update_users_data.py
router/search.py
router/update.py
server.py
crawler/crawler_instagram.py
View file @
ef6c6d4
...
...
@@ -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
...
...
database/update_users_data.py
0 → 100644
View file @
ef6c6d4
def
update_users_data
(
data
):
\ No newline at end of file
router/search.py
View file @
ef6c6d4
...
...
@@ -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
)
...
...
router/update.py
View file @
ef6c6d4
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
...
...
server.py
View file @
ef6c6d4
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
...
...
Please
register
or
login
to post a comment