Showing
10 changed files
with
62 additions
and
29 deletions
... | @@ -6,7 +6,7 @@ | ... | @@ -6,7 +6,7 @@ |
6 | 6 | ||
7 | import {BASE_URL} from "@src/config/url"; | 7 | import {BASE_URL} from "@src/config/url"; |
8 | import {randomTransition} from "@src/components/pageTransition"; | 8 | import {randomTransition} from "@src/components/pageTransition"; |
9 | -import {setState} from "@src/store/state"; | 9 | +import {getState, setState} from "@src/store/state"; |
10 | 10 | ||
11 | export const addEvent = async ( | 11 | export const addEvent = async ( |
12 | e : Event, | 12 | e : Event, |
... | @@ -31,18 +31,21 @@ export const addEvent = async ( | ... | @@ -31,18 +31,21 @@ export const addEvent = async ( |
31 | 31 | ||
32 | if(insta_id){ | 32 | if(insta_id){ |
33 | try{ | 33 | try{ |
34 | - result = await (await fetch(BASE_URL + 'update?insta_id=' + insta_id)).json(); | 34 | + result = await (await fetch(BASE_URL + 'search?insta_id=' + insta_id)).json(); |
35 | } catch (e){ | 35 | } catch (e){ |
36 | console.log(e); | 36 | console.log(e); |
37 | } finally { | 37 | } finally { |
38 | - console.log(result); | 38 | + console.log('res!',result); |
39 | result && $App && (()=>{ | 39 | result && $App && (()=>{ |
40 | - $App.innerHTML = App('main'); | 40 | + randomTransition(); |
41 | setState({ | 41 | setState({ |
42 | insta_id : insta_id, | 42 | insta_id : insta_id, |
43 | followers : result.followers, | 43 | followers : result.followers, |
44 | following : result.following | 44 | following : result.following |
45 | }); | 45 | }); |
46 | + setTimeout(()=>{ | ||
47 | + $App.innerHTML = App('main'); | ||
48 | + },1200) | ||
46 | })(); | 49 | })(); |
47 | } | 50 | } |
48 | } else { | 51 | } else { |
... | @@ -62,8 +65,15 @@ export const addEvent = async ( | ... | @@ -62,8 +65,15 @@ export const addEvent = async ( |
62 | } finally { | 65 | } finally { |
63 | console.log(result); | 66 | console.log(result); |
64 | result && $App && (()=>{ | 67 | result && $App && (()=>{ |
65 | - $App.innerHTML = App('main'); | 68 | + randomTransition(); |
66 | - setState({insta_id : insta_id}); | 69 | + setState({ |
70 | + insta_id : insta_id, | ||
71 | + followers : result.followers, | ||
72 | + following : result.following | ||
73 | + }); | ||
74 | + setTimeout(()=>{ | ||
75 | + $App.innerHTML = App('main'); | ||
76 | + },1200) | ||
67 | })(); | 77 | })(); |
68 | } | 78 | } |
69 | } else { | 79 | } else { | ... | ... |
... | @@ -24,7 +24,7 @@ const turnOnAndOff = (idx : number)=>{ | ... | @@ -24,7 +24,7 @@ const turnOnAndOff = (idx : number)=>{ |
24 | $div.style.display = 'none'; | 24 | $div.style.display = 'none'; |
25 | $div.classList.toggle(pageTransitionClassList[idx]); | 25 | $div.classList.toggle(pageTransitionClassList[idx]); |
26 | })() | 26 | })() |
27 | - },idx === 0 ? 1000 : 2400); | 27 | + },idx === 0 ? 900 : 2300); |
28 | })() | 28 | })() |
29 | } | 29 | } |
30 | 30 | ... | ... |
... | @@ -5,9 +5,7 @@ | ... | @@ -5,9 +5,7 @@ |
5 | **/ | 5 | **/ |
6 | 6 | ||
7 | import App from './App'; | 7 | import App from './App'; |
8 | -import {BASE_URL} from './config/url'; | 8 | +import {initialTrantition} from "./components/pageTransition"; |
9 | -import {initialTrantition, randomTransition} from "./components/pageTransition"; | ||
10 | -import {setState} from "./store/state"; | ||
11 | import './assets/style/PageTransition.scss'; | 9 | import './assets/style/PageTransition.scss'; |
12 | import {addEvent} from "@src/components/addEvent"; | 10 | import {addEvent} from "@src/components/addEvent"; |
13 | 11 | ... | ... |
... | @@ -15,13 +15,18 @@ const initialState = { | ... | @@ -15,13 +15,18 @@ const initialState = { |
15 | insta_id : '', | 15 | insta_id : '', |
16 | followers : [''], | 16 | followers : [''], |
17 | following : [''], | 17 | following : [''], |
18 | -}; | 18 | +} |
19 | +let state: StateType = initialState; | ||
19 | 20 | ||
20 | -const state: StateType = initialState; | 21 | +export const setState = (newState: StateType): void => { |
22 | + state = { | ||
23 | + ...state, | ||
24 | + ...newState | ||
25 | + } | ||
26 | +}; | ||
21 | 27 | ||
22 | -export const setState = (newState: StateType): StateType =>({ | 28 | +export const getState = () => { |
23 | - ...state, | 29 | + return state |
24 | - ...newState | 30 | +} |
25 | -}); | ||
26 | 31 | ||
27 | export default state; | 32 | export default state; | ... | ... |
... | @@ -13,6 +13,7 @@ const Intro = (): string =>{ | ... | @@ -13,6 +13,7 @@ const Intro = (): string =>{ |
13 | ${Title('인스타 조회하기').Large} | 13 | ${Title('인스타 조회하기').Large} |
14 | <input id="id-input" type="text" name="insta_id" /> | 14 | <input id="id-input" type="text" name="insta_id" /> |
15 | <button id="search-button">조회</button> | 15 | <button id="search-button">조회</button> |
16 | + <button id="update-button">업데이</button> | ||
16 | </lable> | 17 | </lable> |
17 | </div>` | 18 | </div>` |
18 | } | 19 | } | ... | ... |
... | @@ -5,11 +5,20 @@ | ... | @@ -5,11 +5,20 @@ |
5 | * 업데이트하기 | 5 | * 업데이트하기 |
6 | * 다른 메뉴 보기 | 6 | * 다른 메뉴 보기 |
7 | **/ | 7 | **/ |
8 | +import state from "@src/store"; | ||
9 | +import {getState} from "@src/store/state"; | ||
8 | 10 | ||
9 | const Main = () => { | 11 | const Main = () => { |
12 | + let contents = `<div>${state.insta_id}</div>` | ||
13 | + | ||
14 | + contents += getState().followers?.map(id => `<div>followers ${id}</div>`) | ||
15 | + | ||
16 | + contents += getState().following?.map(id => `<div>following ${id}</div>`) | ||
17 | + | ||
10 | return ` | 18 | return ` |
11 | <div class="main"> | 19 | <div class="main"> |
12 | its main | 20 | its main |
21 | + ${contents} | ||
13 | </div> | 22 | </div> |
14 | ` | 23 | ` |
15 | } | 24 | } | ... | ... |
... | @@ -19,7 +19,7 @@ db = firebase.database() | ... | @@ -19,7 +19,7 @@ db = firebase.database() |
19 | 19 | ||
20 | 20 | ||
21 | def id_encrypt(user_insta_id): | 21 | def id_encrypt(user_insta_id): |
22 | - return user_insta_id.replace('_', '1z1').replace('.', '2z2') | 22 | + return user_insta_id.replace('_', '').replace('.', '') |
23 | 23 | ||
24 | 24 | ||
25 | def update_data(user_insta_id, data): | 25 | def update_data(user_insta_id, data): | ... | ... |
1 | import time | 1 | import time |
2 | from selenium import webdriver | 2 | from selenium import webdriver |
3 | from selenium.webdriver.common.keys import Keys | 3 | from selenium.webdriver.common.keys import Keys |
4 | +from selenium.webdriver.chrome.options import Options | ||
4 | from config.admin import ID, PW, LOCAL_PROJECT_PATH | 5 | from config.admin import ID, PW, LOCAL_PROJECT_PATH |
5 | from config.URLs import INSTAGRAM_URL | 6 | from config.URLs import INSTAGRAM_URL |
6 | from config.firebase import update_data | 7 | from config.firebase import update_data |
... | @@ -13,7 +14,7 @@ def check_people(driver, type): | ... | @@ -13,7 +14,7 @@ def check_people(driver, type): |
13 | navigations[1].click() | 14 | navigations[1].click() |
14 | elif type == "following": | 15 | elif type == "following": |
15 | navigations[2].click() | 16 | navigations[2].click() |
16 | - time.sleep(1) | 17 | + time.sleep(2) |
17 | 18 | ||
18 | elem = driver.find_elements_by_css_selector('.Jv7Aj ._0imsa') | 19 | elem = driver.find_elements_by_css_selector('.Jv7Aj ._0imsa') |
19 | for obj in elem: | 20 | for obj in elem: |
... | @@ -24,6 +25,8 @@ def check_people(driver, type): | ... | @@ -24,6 +25,8 @@ def check_people(driver, type): |
24 | 25 | ||
25 | def login(driver): | 26 | def login(driver): |
26 | elem = driver.find_elements_by_css_selector('._9GP1n .f0n8F ._2hvTZ') | 27 | elem = driver.find_elements_by_css_selector('._9GP1n .f0n8F ._2hvTZ') |
28 | + time.sleep(1) | ||
29 | + | ||
27 | elem[0].send_keys(ID) | 30 | elem[0].send_keys(ID) |
28 | elem[1].send_keys(PW) | 31 | elem[1].send_keys(PW) |
29 | 32 | ||
... | @@ -39,30 +42,39 @@ def get_list(insta_id, driver): | ... | @@ -39,30 +42,39 @@ def get_list(insta_id, driver): |
39 | driver.find_element_by_css_selector('.WaOAr .wpO6b').click() | 42 | driver.find_element_by_css_selector('.WaOAr .wpO6b').click() |
40 | time.sleep(1) | 43 | time.sleep(1) |
41 | 44 | ||
42 | - # check followings | 45 | + # check following |
43 | following_list = check_people(driver, "following") | 46 | following_list = check_people(driver, "following") |
44 | 47 | ||
45 | # update at firebase | 48 | # update at firebase |
46 | data = { | 49 | data = { |
47 | "followers" : followers_list, | 50 | "followers" : followers_list, |
48 | - "followings" : following_list, | 51 | + "following" : following_list, |
49 | "insta_id" : insta_id | 52 | "insta_id" : insta_id |
50 | } | 53 | } |
51 | update_data(insta_id, data) | 54 | update_data(insta_id, data) |
52 | 55 | ||
56 | + return data | ||
57 | + | ||
53 | 58 | ||
54 | def crawler_instagram(insta_id): | 59 | def crawler_instagram(insta_id): |
55 | - driver = webdriver.Chrome(executable_path=LOCAL_PROJECT_PATH + '/crawler/chromedriver') | 60 | + options = Options() |
61 | + # options.add_argument("--headless") | ||
62 | + options.add_argument("window-size=1920,1080") | ||
63 | + driver = webdriver.Chrome(chrome_options=options, executable_path=LOCAL_PROJECT_PATH + '/crawler/chromedriver') | ||
56 | driver.get(url=INSTAGRAM_URL) | 64 | driver.get(url=INSTAGRAM_URL) |
57 | time.sleep(2) | 65 | time.sleep(2) |
58 | 66 | ||
67 | + print('hi') | ||
59 | login(driver) | 68 | login(driver) |
69 | + print('by') | ||
60 | time.sleep(2) | 70 | time.sleep(2) |
61 | 71 | ||
62 | url="%s/%s"%(INSTAGRAM_URL, insta_id) | 72 | url="%s/%s"%(INSTAGRAM_URL, insta_id) |
63 | driver.get(url=url) | 73 | driver.get(url=url) |
64 | time.sleep(2) | 74 | time.sleep(2) |
65 | 75 | ||
76 | + data = {}; | ||
77 | + | ||
66 | try: | 78 | try: |
67 | isPrivate = driver.find_element_by_class_name('rkEop').text | 79 | isPrivate = driver.find_element_by_class_name('rkEop').text |
68 | except Exception as e: | 80 | except Exception as e: |
... | @@ -73,10 +85,12 @@ def crawler_instagram(insta_id): | ... | @@ -73,10 +85,12 @@ def crawler_instagram(insta_id): |
73 | if isPrivate: | 85 | if isPrivate: |
74 | print('private!!') | 86 | print('private!!') |
75 | else: | 87 | else: |
76 | - get_list(insta_id, driver) | 88 | + data = get_list(insta_id, driver) |
77 | 89 | ||
78 | driver.close() | 90 | driver.close() |
79 | 91 | ||
92 | + return data | ||
93 | + | ||
80 | 94 | ||
81 | if __name__ == "__main__": | 95 | if __name__ == "__main__": |
82 | print("-" * 60) | 96 | print("-" * 60) | ... | ... |
... | @@ -10,16 +10,12 @@ app = Flask(__name__, static_folder=os.path.abspath(my_path)) | ... | @@ -10,16 +10,12 @@ app = Flask(__name__, static_folder=os.path.abspath(my_path)) |
10 | 10 | ||
11 | 11 | ||
12 | def update(insta_id): | 12 | def update(insta_id): |
13 | - result = 'ok' | 13 | + data = {} |
14 | try: | 14 | try: |
15 | - crawler_instagram(insta_id) | 15 | + data = crawler_instagram(insta_id) |
16 | except Exception as e: | 16 | except Exception as e: |
17 | print(e) | 17 | print(e) |
18 | - result = 'fail' | ||
19 | 18 | ||
20 | - data = { | ||
21 | - "result" : result | ||
22 | - } | ||
23 | return jsonify(data) | 19 | return jsonify(data) |
24 | 20 | ||
25 | 21 | ... | ... |
-
Please register or login to post a comment