Committed by
GitHub
Merge pull request #9 from goesnow/goesnow
Goesnow
Showing
20 changed files
with
204 additions
and
33 deletions
__pycache__/server.cpython-37.pyc
0 → 100644
No preview for this file type
app/src/App.ts
0 → 100644
1 | +/** | ||
2 | + * @author : wonseog | ||
3 | + * @date : 2021/03/08 | ||
4 | + * @description : 메인 app | ||
5 | + * index.ts에서 pathname 받아 | ||
6 | + * 컴포넌트 제작 후 반환 | ||
7 | +**/ | ||
8 | + | ||
9 | +import Header from "./views/header/Header"; | ||
10 | +import Body from "./views/body/Body"; | ||
11 | +import Footer from "./views/footer/Footer"; | ||
12 | + | ||
13 | +const App = (pathname : string) : string => { | ||
14 | + history.pushState('','', pathname); | ||
15 | + | ||
16 | + return ` | ||
17 | + <div> | ||
18 | + ${Header()} | ||
19 | + ${Body(pathname)} | ||
20 | + ${Footer()} | ||
21 | + <a href="/wonseog" id="nav-button" data-link>wonseok!!</a> | ||
22 | + </div> | ||
23 | + `; | ||
24 | +} | ||
25 | + | ||
26 | +export default App; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
app/src/Bye.ts
deleted
100644 → 0
1 | -export const Bye = () => console.log('Bye!'); |
app/src/components/title.ts
0 → 100644
1 | +/** | ||
2 | + * @author : wonseog | ||
3 | + * @date : 2021/03/08 | ||
4 | + * @description : 타이틀 대 / 중 / 소 반환 | ||
5 | +**/ | ||
6 | + | ||
7 | +const titleTemplate = (type : string, title : string) => ` | ||
8 | + <div class="${type}-title"> | ||
9 | + ${title} | ||
10 | + </div> | ||
11 | +` | ||
12 | + | ||
13 | +const Title = (title : string) => ({ | ||
14 | + Large : titleTemplate('large', title), | ||
15 | + Medium : titleTemplate('medium', title), | ||
16 | + Small : titleTemplate('small', title) | ||
17 | +}) | ||
18 | + | ||
19 | +export default Title; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
app/src/config/url.ts
0 → 100644
1 | +export const BASE_URL = 'http://localhost:5000/'; |
... | @@ -6,7 +6,7 @@ | ... | @@ -6,7 +6,7 @@ |
6 | <title>home</title> | 6 | <title>home</title> |
7 | </head> | 7 | </head> |
8 | <body> | 8 | <body> |
9 | - <div id="App"> </div> | 9 | + <div id="App"></div> |
10 | <!-- <script src="public/main.js" ></script>--> | 10 | <!-- <script src="public/main.js" ></script>--> |
11 | </body> | 11 | </body> |
12 | </html> | 12 | </html> |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | -import {Bye} from './Bye'; | 1 | +/** |
2 | -import './assets/style/App.css'; | 2 | + * @author : wonseog |
3 | -import v4 from './assets/image/v4Logo.png'; | 3 | + * @date : 2021/03/08 |
4 | + * @description : 현재 pathname을 파악 후 App으로 전달 | ||
5 | +**/ | ||
6 | +import App from './App'; | ||
7 | +import {BASE_URL} from './config/url'; | ||
4 | 8 | ||
5 | -const hi = 'hchoi won'; | 9 | +window.addEventListener('DOMContentLoaded', () => { |
10 | + const $App = document.querySelector('#App'); | ||
11 | + const pathname = window.location.pathname.split('/')[1]; | ||
6 | 12 | ||
7 | -const hi1 = () => { | 13 | + document.body.addEventListener('click', async (e) => { |
8 | - console.log(hi); | 14 | + e.stopPropagation(); |
9 | - Bye(); | 15 | + if((e.target as HTMLAnchorElement).matches("[data-link]")){ |
16 | + const href = (e.target as HTMLAnchorElement).href.split(BASE_URL)[1]; | ||
17 | + e.preventDefault(); | ||
18 | + $App && ($App.innerHTML = App(href)); | ||
19 | + } else if((e.target as HTMLAnchorElement).id === 'update-button') { | ||
20 | + let result: any= null; | ||
21 | + const insta_id = (document.querySelector('#id-input') as HTMLInputElement).value; | ||
10 | 22 | ||
11 | - const tag = window.document.querySelector('#App'); | 23 | + if(insta_id){ |
24 | + try{ | ||
25 | + result = await (await fetch(BASE_URL + 'update?insta_id=' + insta_id)).json(); | ||
26 | + } catch (e){ | ||
27 | + console.log(e); | ||
28 | + } finally { | ||
29 | + console.log(result) | ||
30 | + result && $App && ($App.innerHTML = App('main')) | ||
31 | + } | ||
32 | + } | ||
33 | + } | ||
34 | + }); | ||
12 | 35 | ||
13 | - if(tag) { | 36 | + window.addEventListener('popstate', ()=>{ |
14 | - tag.innerHTML = `<img src=${v4} alt="image" />`; | 37 | + $App && ($App.innerHTML = App(pathname)) |
15 | - } | 38 | + }); |
16 | -}; | ||
17 | 39 | ||
18 | -hi1(); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
40 | + $App && ($App.innerHTML = App(pathname)); | ||
41 | +}) | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
app/src/state/state.ts
0 → 100644
1 | +/** | ||
2 | + * @author wonseog | ||
3 | + * @date 2021-03-09 | ||
4 | + * @description state 관리 | ||
5 | + * 주로 instaId, followers, following 관리 | ||
6 | + **/ | ||
7 | + | ||
8 | +export interface StateType{ | ||
9 | + insta_id? : string, | ||
10 | + followers? : Array<string>, | ||
11 | + following? : Array<string> | ||
12 | +} | ||
13 | + | ||
14 | +export const state: StateType ={ | ||
15 | + insta_id : '', | ||
16 | + followers : [''], | ||
17 | + following : [''], | ||
18 | +}; | ||
19 | + | ||
20 | +export const setState = (newState: StateType): StateType =>({ | ||
21 | + ...state, | ||
22 | + ...newState | ||
23 | +}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
app/src/views/body/Body.ts
0 → 100644
1 | +/** | ||
2 | + * @author : wonseog | ||
3 | + * @date : 2021/03/08 | ||
4 | + * @description : 페이지 내용 | ||
5 | +**/ | ||
6 | +import Home from "./contents/Home"; | ||
7 | + | ||
8 | +const Body = (pathname: string) : string => { | ||
9 | + let contentsContainer = ''; | ||
10 | + | ||
11 | + switch (pathname){ | ||
12 | + case 'compare': | ||
13 | + break; | ||
14 | + case 'main': | ||
15 | + break; | ||
16 | + default: | ||
17 | + contentsContainer = Home(); | ||
18 | + } | ||
19 | + | ||
20 | + return ` | ||
21 | + <div class="Body"> | ||
22 | + ${contentsContainer} | ||
23 | + </div> | ||
24 | + `; | ||
25 | +} | ||
26 | + | ||
27 | +export default Body; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
app/src/views/body/contents/Home.ts
0 → 100644
1 | +/** | ||
2 | + * @author wonseog | ||
3 | + * @date 2021-03-09 | ||
4 | + * @description id 입력하는 메인 화면 | ||
5 | + * 조회 / 업데이트 | ||
6 | + **/ | ||
7 | +import {state} from "../../../state/state"; | ||
8 | +import Title from "../../../components/title"; | ||
9 | + | ||
10 | +const Home = (): string =>{ | ||
11 | + const onSubmit = (e : Event) => { | ||
12 | + e.preventDefault(); | ||
13 | + alert('hi'); | ||
14 | + } | ||
15 | + | ||
16 | + const literalTag = `<div class="home"> | ||
17 | + <lable> | ||
18 | + ${Title('인스타 조회하기').Large} | ||
19 | + <input id="id-input" type="text" name="insta_id" /> | ||
20 | + <button id="update-button">조회</button> | ||
21 | + </lable> | ||
22 | + </div>` | ||
23 | + | ||
24 | + return literalTag; | ||
25 | +} | ||
26 | + | ||
27 | +export default Home; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
app/src/views/footer/Footer.ts
0 → 100644
app/src/views/header/Header.ts
0 → 100644
1 | +/** | ||
2 | + * @author : wonseog | ||
3 | + * @date : 2021/03/08 | ||
4 | + * @description : 페이지 헤더 | ||
5 | +**/ | ||
6 | + | ||
7 | +import Title from "../../components/title"; | ||
8 | + | ||
9 | +const Header = () : string => ` | ||
10 | + <div class="header"> | ||
11 | + ${Title('im title').Large} | ||
12 | + </div> | ||
13 | +`; | ||
14 | + | ||
15 | +export default Header; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
config/__pycache__/URLs.cpython-37.pyc
0 → 100644
No preview for this file type
config/__pycache__/__init__.cpython-37.pyc
0 → 100644
No preview for this file type
config/__pycache__/admin.cpython-37.pyc
0 → 100644
No preview for this file type
config/__pycache__/firebase.cpython-37.pyc
0 → 100644
No preview for this file type
crawler/__pycache__/__init__.cpython-37.pyc
0 → 100644
No preview for this file type
No preview for this file type
... | @@ -3,7 +3,7 @@ from selenium import webdriver | ... | @@ -3,7 +3,7 @@ from selenium import webdriver |
3 | from selenium.webdriver.common.keys import Keys | 3 | from selenium.webdriver.common.keys import Keys |
4 | from config.admin import ID, PW, LOCAL_PROJECT_PATH | 4 | from config.admin import ID, PW, LOCAL_PROJECT_PATH |
5 | from config.URLs import INSTAGRAM_URL | 5 | from config.URLs import INSTAGRAM_URL |
6 | -from config.firebase import update_data | 6 | +# from config.firebase import update_data |
7 | 7 | ||
8 | def check_people(driver, type): | 8 | def check_people(driver, type): |
9 | result = [] | 9 | result = [] |
... | @@ -43,16 +43,16 @@ def get_list(insta_id, driver): | ... | @@ -43,16 +43,16 @@ def get_list(insta_id, driver): |
43 | following_list = check_people(driver, "following") | 43 | following_list = check_people(driver, "following") |
44 | 44 | ||
45 | # update at firebase | 45 | # update at firebase |
46 | - update_data(insta_id, followers_list, following_list) | 46 | + # update_data(insta_id, followers_list, following_list) |
47 | 47 | ||
48 | 48 | ||
49 | def crawler_instagram(insta_id): | 49 | def crawler_instagram(insta_id): |
50 | driver = webdriver.Chrome(executable_path=LOCAL_PROJECT_PATH + '/crawler/chromedriver') | 50 | driver = webdriver.Chrome(executable_path=LOCAL_PROJECT_PATH + '/crawler/chromedriver') |
51 | driver.get(url=INSTAGRAM_URL) | 51 | driver.get(url=INSTAGRAM_URL) |
52 | - time.sleep(4) | 52 | + time.sleep(2) |
53 | 53 | ||
54 | login(driver) | 54 | login(driver) |
55 | - time.sleep(5) | 55 | + time.sleep(2) |
56 | 56 | ||
57 | url="%s/%s"%(INSTAGRAM_URL, insta_id) | 57 | url="%s/%s"%(INSTAGRAM_URL, insta_id) |
58 | driver.get(url=url) | 58 | driver.get(url=url) | ... | ... |
... | @@ -2,9 +2,14 @@ import os | ... | @@ -2,9 +2,14 @@ import os |
2 | from flask import Flask, render_template, request, jsonify, send_from_directory | 2 | from flask import Flask, render_template, request, jsonify, send_from_directory |
3 | from crawler.crawler_instagram import crawler_instagram | 3 | from crawler.crawler_instagram import crawler_instagram |
4 | 4 | ||
5 | -my_path = '/Users/choewonseog/Documents/check-your-instagram/app/public' | 5 | +# my_path = '/Users/choewonseog/Documents/check-your-instagram/app/public' |
6 | +# my_path = 'C:/Users/goesnow/Documents/study/check-your-instagram/app/public' | ||
7 | + | ||
8 | +root_dir = os.path.dirname(os.getcwd()) | ||
9 | +my_path = os.path.join(root_dir, 'check-your-instagram', 'app', 'public') | ||
6 | app = Flask(__name__, static_folder=os.path.abspath(my_path)) | 10 | app = Flask(__name__, static_folder=os.path.abspath(my_path)) |
7 | 11 | ||
12 | + | ||
8 | def update(insta_id): | 13 | def update(insta_id): |
9 | crawler_instagram(insta_id) | 14 | crawler_instagram(insta_id) |
10 | 15 | ||
... | @@ -18,24 +23,16 @@ def update(insta_id): | ... | @@ -18,24 +23,16 @@ def update(insta_id): |
18 | def page_not_found(): | 23 | def page_not_found(): |
19 | return render_template('404.html') | 24 | return render_template('404.html') |
20 | 25 | ||
26 | + | ||
21 | @app.route("/", defaults={"path": ""}) | 27 | @app.route("/", defaults={"path": ""}) |
22 | @app.route("/<path:path>") | 28 | @app.route("/<path:path>") |
23 | def home(path): | 29 | def home(path): |
24 | - print("hi? your in '%s' !!"%(path)) | ||
25 | - | ||
26 | - # if path != "" and os.path.exists(app.static_folder + '/' + path): | ||
27 | - # return send_from_directory(app.static_folder, path) | ||
28 | - # else: | ||
29 | - # return send_from_directory(app.static_folder, 'index.html') | ||
30 | if path == 'update': | 30 | if path == 'update': |
31 | insta_id = request.args.get('insta_id') | 31 | insta_id = request.args.get('insta_id') |
32 | - update(insta_id) | 32 | + return update(insta_id) |
33 | - elif path == '' : | 33 | + |
34 | - root_dir = os.path.dirname(os.getcwd()) | 34 | + return send_from_directory(my_path, filename='index.html') |
35 | - return send_from_directory(os.path.join(root_dir, 'check-your-instagram', 'app', 'public'), filename='index.html') | 35 | + |
36 | - return render_template('index.html') | ||
37 | - # else: | ||
38 | - # return render_template('index.html') | ||
39 | 36 | ||
40 | if __name__ == "__main__": | 37 | if __name__ == "__main__": |
41 | print("-" * 60) | 38 | print("-" * 60) | ... | ... |
-
Please register or login to post a comment