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-05 01:05:26 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f73d021380fb029f802a8274fcb9d9cb313bf0b2
f73d0213
1 parent
b5aa07e4
feat: search & update DB
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
32 deletions
crawler/crawler_instagram.py
router/search.py
router/update.py
crawler/crawler_instagram.py
View file @
f73d021
...
...
@@ -7,8 +7,8 @@ from config.URLs import INSTAGRAM_URL
def
get_description
(
driver
):
element
=
driver
.
find_element_by_css_selector
(
'.
Igw0E .IwRSH .eGOV_ ._4EzTm
'
)
data
=
element
.
get_attribute
(
'innerHTML'
)
element
=
driver
.
find_element_by_css_selector
(
'.
-vDIg
'
)
data
=
element
.
text
return
str
(
data
)
...
...
@@ -50,7 +50,7 @@ def get_list(insta_id, driver):
# update at firebase
data
=
{
"followers"
:
followers_list
,
"
insta
_id"
:
insta_id
,
"
user
_id"
:
insta_id
,
"description"
:
desc
,
"follower_num"
:
len
(
followers_list
)
}
...
...
@@ -66,9 +66,7 @@ def crawler_instagram(insta_id):
driver
.
get
(
url
=
INSTAGRAM_URL
)
time
.
sleep
(
2
)
print
(
'hi'
)
login
(
driver
)
print
(
insta_id
)
time
.
sleep
(
2
)
url
=
"
%
s/
%
s"
%
(
INSTAGRAM_URL
,
insta_id
)
...
...
router/search.py
View file @
f73d021
...
...
@@ -10,19 +10,31 @@ def search(insta_id):
connection
=
cx_Oracle
.
connect
(
DATABASE_ID
,
DATABASE_PW
,
DATABASE_URL
)
cursor
=
connection
.
cursor
()
query
=
"""
select * from users where user_id=
\'
%
s
\'
"""
%
insta_id
cursor
.
execute
(
query
)
exist
=
cursor
.
fetchall
()
cursor
.
execute
(
f
"""
select * from users where user_id=
\'
{insta_id}
\'
"""
)
exist_user
=
cursor
.
fetchall
()
print
(
exist_user
)
cursor
.
execute
(
f
"""
select * from followers where user_id=
\'
{insta_id}
\'
"""
)
exist_followers
=
cursor
.
fetchall
()
print
(
exist_followers
)
exist_info
=
()
if
len
(
exist_user
)
>
0
:
exist_info
=
{
"user"
:
exist_user
[
0
],
"follower"
:
exist_followers
}
print
(
exist_info
)
cursor
.
close
()
return
Response
(
json
.
dumps
(
exist
),
mimetype
=
'application/json'
)
return
Response
(
json
.
dumps
(
exist
_info
),
mimetype
=
'application/json'
)
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
)
print
(
search
(
'__
re.mind.er
__'
)
.
data
)
...
...
router/update.py
View file @
f73d021
...
...
@@ -4,14 +4,14 @@ import cx_Oracle
import
os
from
config.key
import
DATABASE_ID
,
DATABASE_PW
from
config.URLs
import
DATABASE_URL
from
flask
import
jsonify
from
flask
import
Response
# data = {
# "followers":
followers_list
,
# "followers":
[followers_list]
,
# "insta_id": insta_id,
# "description": desc,
# "follower_num": len(
followers_list
)
# "follower_num": len(
[followers_list]
)
# }
def
update
(
insta_id
):
...
...
@@ -29,31 +29,54 @@ def update(insta_id):
select * from users where user_id=
\'
%
s
\'
"""
%
insta_id
cursor
.
execute
(
user_query
)
# user가 존재하는지 확인
cursor
.
execute
(
user_query
)
# user가 존재하는지 확인
exist_user
=
cursor
.
fetchall
()
print
(
exist_user
)
### update users table ###
query
=
""
if
len
(
exist_user
)
==
0
:
query
=
f
"""
print
(
'insert new'
)
cursor
.
execute
(
f
"""
insert into
users(user_id, description, follower_num)
values(
\'
{data
.user_id
}
\'
,
\'
{data
.description
}
\'
,
\'
{data
.follower_num
}
\'
users
(user_id, description, follower_num)
values
(
\'
{data
['user_id']
}
\'
,
\'
{data
['description'][0:254]
}
\'
,
\'
{data
['follower_num']
}
\'
)
"""
"""
)
else
:
query
=
f
"""
print
(
'update user'
)
cursor
.
execute
(
f
"""
update users set
user_id =
\'
{data.user_id}
\'
,
description =
\'
{data.description}
\'
,
follower_num =
\'
{data.follower_num}
\'
"""
description =
\'
{data['description'][0:254]}
\'
,
follower_num =
\'
{data['follower_num']}
\'
where user_id =
\'
{data['user_id']}
\'
"""
)
### update followers table ###
for
follower
in
data
[
'followers'
]:
print
(
follower
)
cursor
.
execute
(
"""
select * from followers where follower_id=
\'
%
s
\'
"""
%
follower
)
cursor
.
execute
(
query
)
exist_follower
=
cursor
.
fetchall
(
)
if
len
(
exist_follower
)
==
0
:
print
(
'insert follower'
)
cursor
.
execute
(
f
"""
insert into
followers (follower_id, user_id, description)
values (
\'
{follower}
\'
,
\'
{data['user_id']}
\'
,
\'\'
)
"""
)
cursor
.
close
()
return
jsonify
(
data
)
\ No newline at end of file
return
Response
(
json
.
dumps
(
data
),
mimetype
=
'application/json'
)
if
__name__
==
'__main__'
:
os
.
putenv
(
'NLS_LANG'
,
'.UTF8'
)
cx_Oracle
.
init_oracle_client
(
lib_dir
=
"/Users/choewonseog/Downloads/instantclient_19_8"
)
update
(
'__re.mind.er__'
)
...
...
Please
register
or
login
to post a comment