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-03-10 23:08:37 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
083ddc9d78b24a8b9395437fcb3515e8616c5b45
083ddc9d
1 parent
eb0a85cd
edit store, crawler
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
60 additions
and
27 deletions
app/src/components/addEvent.ts
app/src/components/pageTransition.ts
app/src/index.ts
app/src/store/state.ts
app/src/views/body/contents/compare/Compare.ts
app/src/views/body/contents/intro/Intro.ts
app/src/views/body/contents/main/Main.ts
config/firebase.py
crawler/crawler_instagram.py
server.py
app/src/components/addEvent.ts
View file @
083ddc9
...
...
@@ -6,7 +6,7 @@
import
{
BASE_URL
}
from
"@src/config/url"
;
import
{
randomTransition
}
from
"@src/components/pageTransition"
;
import
{
setState
}
from
"@src/store/state"
;
import
{
getState
,
setState
}
from
"@src/store/state"
;
export
const
addEvent
=
async
(
e
:
Event
,
...
...
@@ -31,18 +31,21 @@ export const addEvent = async (
if
(
insta_id
){
try
{
result
=
await
(
await
fetch
(
BASE_URL
+
'
update
?insta_id='
+
insta_id
)).
json
();
result
=
await
(
await
fetch
(
BASE_URL
+
'
search
?insta_id='
+
insta_id
)).
json
();
}
catch
(
e
){
console
.
log
(
e
);
}
finally
{
console
.
log
(
result
);
console
.
log
(
'res!'
,
result
);
result
&&
$App
&&
(()
=>
{
$App
.
innerHTML
=
App
(
'main'
);
randomTransition
(
);
setState
({
insta_id
:
insta_id
,
followers
:
result
.
followers
,
following
:
result
.
following
});
setTimeout
(()
=>
{
$App
.
innerHTML
=
App
(
'main'
);
},
1200
)
})();
}
}
else
{
...
...
@@ -62,8 +65,15 @@ export const addEvent = async (
}
finally
{
console
.
log
(
result
);
result
&&
$App
&&
(()
=>
{
randomTransition
();
setState
({
insta_id
:
insta_id
,
followers
:
result
.
followers
,
following
:
result
.
following
});
setTimeout
(()
=>
{
$App
.
innerHTML
=
App
(
'main'
);
setState
({
insta_id
:
insta_id
});
},
1200
)
})();
}
}
else
{
...
...
app/src/components/pageTransition.ts
View file @
083ddc9
...
...
@@ -24,7 +24,7 @@ const turnOnAndOff = (idx : number)=>{
$div
.
style
.
display
=
'none'
;
$div
.
classList
.
toggle
(
pageTransitionClassList
[
idx
]);
})()
},
idx
===
0
?
1000
:
24
00
);
},
idx
===
0
?
900
:
23
00
);
})()
}
...
...
app/src/index.ts
View file @
083ddc9
...
...
@@ -5,9 +5,7 @@
**/
import
App
from
'./App'
;
import
{
BASE_URL
}
from
'./config/url'
;
import
{
initialTrantition
,
randomTransition
}
from
"./components/pageTransition"
;
import
{
setState
}
from
"./store/state"
;
import
{
initialTrantition
}
from
"./components/pageTransition"
;
import
'./assets/style/PageTransition.scss'
;
import
{
addEvent
}
from
"@src/components/addEvent"
;
...
...
app/src/store/state.ts
View file @
083ddc9
...
...
@@ -15,13 +15,18 @@ const initialState = {
insta_id
:
''
,
followers
:
[
''
],
following
:
[
''
],
};
const
state
:
StateType
=
initialState
;
}
let
state
:
StateType
=
initialState
;
export
const
setState
=
(
newState
:
StateType
):
StateType
=>
({
export
const
setState
=
(
newState
:
StateType
):
void
=>
{
state
=
{
...
state
,
...
newState
});
}
};
export
const
getState
=
()
=>
{
return
state
}
export
default
state
;
...
...
app/src/views/body/contents/compare/Compare.ts
View file @
083ddc9
/**
* @author : wonseog
* @date : 2021/03/10
* @description : followers vs following
s
* @description : followers vs following
**/
const
Compare
=
()
=>
{
...
...
app/src/views/body/contents/intro/Intro.ts
View file @
083ddc9
...
...
@@ -13,6 +13,7 @@ const Intro = (): string =>{
${
Title
(
'인스타 조회하기'
).
Large
}
<input id="id-input" type="text" name="insta_id" />
<button id="search-button">조회</button>
<button id="update-button">업데이</button>
</lable>
</div>`
}
...
...
app/src/views/body/contents/main/Main.ts
View file @
083ddc9
...
...
@@ -5,11 +5,20 @@
* 업데이트하기
* 다른 메뉴 보기
**/
import
state
from
"@src/store"
;
import
{
getState
}
from
"@src/store/state"
;
const
Main
=
()
=>
{
let
contents
=
`<div>
${
state
.
insta_id
}
</div>`
contents
+=
getState
().
followers
?.
map
(
id
=>
`<div>followers
${
id
}
</div>`
)
contents
+=
getState
().
following
?.
map
(
id
=>
`<div>following
${
id
}
</div>`
)
return
`
<div class="main">
its main
${
contents
}
</div>
`
}
...
...
config/firebase.py
View file @
083ddc9
...
...
@@ -19,7 +19,7 @@ db = firebase.database()
def
id_encrypt
(
user_insta_id
):
return
user_insta_id
.
replace
(
'_'
,
'
1z1'
)
.
replace
(
'.'
,
'2z2
'
)
return
user_insta_id
.
replace
(
'_'
,
'
'
)
.
replace
(
'.'
,
'
'
)
def
update_data
(
user_insta_id
,
data
):
...
...
crawler/crawler_instagram.py
View file @
083ddc9
import
time
from
selenium
import
webdriver
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
...
...
@@ -13,7 +14,7 @@ def check_people(driver, type):
navigations
[
1
]
.
click
()
elif
type
==
"following"
:
navigations
[
2
]
.
click
()
time
.
sleep
(
1
)
time
.
sleep
(
2
)
elem
=
driver
.
find_elements_by_css_selector
(
'.Jv7Aj ._0imsa'
)
for
obj
in
elem
:
...
...
@@ -24,6 +25,8 @@ def check_people(driver, type):
def
login
(
driver
):
elem
=
driver
.
find_elements_by_css_selector
(
'._9GP1n .f0n8F ._2hvTZ'
)
time
.
sleep
(
1
)
elem
[
0
]
.
send_keys
(
ID
)
elem
[
1
]
.
send_keys
(
PW
)
...
...
@@ -39,30 +42,39 @@ def get_list(insta_id, driver):
driver
.
find_element_by_css_selector
(
'.WaOAr .wpO6b'
)
.
click
()
time
.
sleep
(
1
)
# check following
s
# check following
following_list
=
check_people
(
driver
,
"following"
)
# update at firebase
data
=
{
"followers"
:
followers_list
,
"following
s
"
:
following_list
,
"following"
:
following_list
,
"insta_id"
:
insta_id
}
update_data
(
insta_id
,
data
)
return
data
def
crawler_instagram
(
insta_id
):
driver
=
webdriver
.
Chrome
(
executable_path
=
LOCAL_PROJECT_PATH
+
'/crawler/chromedriver'
)
options
=
Options
()
# options.add_argument("--headless")
options
.
add_argument
(
"window-size=1920,1080"
)
driver
=
webdriver
.
Chrome
(
chrome_options
=
options
,
executable_path
=
LOCAL_PROJECT_PATH
+
'/crawler/chromedriver'
)
driver
.
get
(
url
=
INSTAGRAM_URL
)
time
.
sleep
(
2
)
print
(
'hi'
)
login
(
driver
)
print
(
'by'
)
time
.
sleep
(
2
)
url
=
"
%
s/
%
s"
%
(
INSTAGRAM_URL
,
insta_id
)
driver
.
get
(
url
=
url
)
time
.
sleep
(
2
)
data
=
{};
try
:
isPrivate
=
driver
.
find_element_by_class_name
(
'rkEop'
)
.
text
except
Exception
as
e
:
...
...
@@ -73,10 +85,12 @@ def crawler_instagram(insta_id):
if
isPrivate
:
print
(
'private!!'
)
else
:
get_list
(
insta_id
,
driver
)
data
=
get_list
(
insta_id
,
driver
)
driver
.
close
()
return
data
if
__name__
==
"__main__"
:
print
(
"-"
*
60
)
...
...
server.py
View file @
083ddc9
...
...
@@ -10,16 +10,12 @@ app = Flask(__name__, static_folder=os.path.abspath(my_path))
def
update
(
insta_id
):
result
=
'ok'
data
=
{}
try
:
crawler_instagram
(
insta_id
)
data
=
crawler_instagram
(
insta_id
)
except
Exception
as
e
:
print
(
e
)
result
=
'fail'
data
=
{
"result"
:
result
}
return
jsonify
(
data
)
...
...
Please
register
or
login
to post a comment