최원석3 [goesnow]

catch error in server

...@@ -4,7 +4,6 @@ body { ...@@ -4,7 +4,6 @@ body {
4 } 4 }
5 5
6 .container { 6 .container {
7 - border: 1px solid green;
8 display: flex; 7 display: flex;
9 justify-content: center; 8 justify-content: center;
10 align-items: center; 9 align-items: center;
...@@ -15,6 +14,6 @@ body { ...@@ -15,6 +14,6 @@ body {
15 transform: translate(-50%, -50%); 14 transform: translate(-50%, -50%);
16 min-width: 250px; 15 min-width: 250px;
17 min-height: 500px; 16 min-height: 500px;
18 - width: 90%; 17 + width: 100%;
19 height: 100%; 18 height: 100%;
20 } 19 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
7 import App from './App'; 7 import App from './App';
8 import {BASE_URL} from './config/url'; 8 import {BASE_URL} from './config/url';
9 import {initialTrantition, randomTransition} from "./components/pageTransition"; 9 import {initialTrantition, randomTransition} from "./components/pageTransition";
10 +import {setState} from "./state/state";
10 11
11 window.addEventListener('DOMContentLoaded', () => { 12 window.addEventListener('DOMContentLoaded', () => {
12 /* add div for page transitions */ 13 /* add div for page transitions */
...@@ -53,7 +54,10 @@ window.addEventListener('DOMContentLoaded', () => { ...@@ -53,7 +54,10 @@ window.addEventListener('DOMContentLoaded', () => {
53 console.log(e); 54 console.log(e);
54 } finally { 55 } finally {
55 console.log(result); 56 console.log(result);
56 - result && $App && ($App.innerHTML = App('main')); 57 + result && $App && (()=>{
58 + $App.innerHTML = App('main');
59 + setState({insta_id : insta_id});
60 + })();
57 } 61 }
58 } else { 62 } else {
59 alert('아이디를 입력하세요'); 63 alert('아이디를 입력하세요');
......
1 +export {default} from './state';
...@@ -11,7 +11,7 @@ export interface StateType{ ...@@ -11,7 +11,7 @@ export interface StateType{
11 following? : Array<string> 11 following? : Array<string>
12 } 12 }
13 13
14 -export const state: StateType ={ 14 +const state: StateType ={
15 insta_id : '', 15 insta_id : '',
16 followers : [''], 16 followers : [''],
17 following : [''], 17 following : [''],
...@@ -20,4 +20,6 @@ export const state: StateType ={ ...@@ -20,4 +20,6 @@ export const state: StateType ={
20 export const setState = (newState: StateType): StateType =>({ 20 export const setState = (newState: StateType): StateType =>({
21 ...state, 21 ...state,
22 ...newState 22 ...newState
23 -});
...\ No newline at end of file ...\ No newline at end of file
23 +});
24 +
25 +export default state;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
4 * @description id 입력하는 메인 화면 4 * @description id 입력하는 메인 화면
5 * 조회 / 업데이트 5 * 조회 / 업데이트
6 **/ 6 **/
7 -import {state} from "../../../state/state"; 7 +import state from "../../../state";
8 import Title from "../../../components/title"; 8 import Title from "../../../components/title";
9 9
10 const Home = (): string =>{ 10 const Home = (): string =>{
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -17,12 +17,21 @@ firebase = pyrebase.initialize_app(config) ...@@ -17,12 +17,21 @@ firebase = pyrebase.initialize_app(config)
17 17
18 db = firebase.database() 18 db = firebase.database()
19 19
20 -def update_data(user_insta_id ,followers, followings):
21 - insta_id = user_insta_id.replace('_','').replace('.','')
22 20
23 - data = { 21 +def id_encrypt(user_insta_id):
24 - "followings" : followings, 22 + return user_insta_id.replace('_', '1z1').replace('.', '2z2')
25 - "followers" : followers 23 +
26 - } 24 +
25 +def update_data(user_insta_id, data):
26 + insta_id = id_encrypt(user_insta_id)
27 27
28 db.child("insta").child(insta_id).update(data) 28 db.child("insta").child(insta_id).update(data)
29 +
30 +
31 +def get_data_by_id(user_insta_id):
32 + insta_id = id_encrypt(user_insta_id)
33 +
34 + data = db.child("insta").child(insta_id).get()
35 +
36 + return data.val()
37 +
......
...@@ -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,7 +43,12 @@ def get_list(insta_id, driver): ...@@ -43,7 +43,12 @@ 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 + data = {
47 + "followers" : followers_list,
48 + "followings" : following_list,
49 + "insta_id" : insta_id
50 + }
51 + update_data(insta_id, data)
47 52
48 53
49 def crawler_instagram(insta_id): 54 def crawler_instagram(insta_id):
...@@ -64,10 +69,9 @@ def crawler_instagram(insta_id): ...@@ -64,10 +69,9 @@ def crawler_instagram(insta_id):
64 isPrivate = "" 69 isPrivate = ""
65 pass 70 pass
66 71
67 - # 비공개 계정인 경우 72 + # account is private
68 if isPrivate: 73 if isPrivate:
69 print('private!!') 74 print('private!!')
70 - # 공개 계정인 경우
71 else: 75 else:
72 get_list(insta_id, driver) 76 get_list(insta_id, driver)
73 77
......
No preview for this file type
...@@ -5,18 +5,16 @@ googleapis-common-protos==1.52.0 ...@@ -5,18 +5,16 @@ googleapis-common-protos==1.52.0
5 httplib2==0.19.0 5 httplib2==0.19.0
6 itsdangerous==1.1.0 6 itsdangerous==1.1.0
7 Jinja2==2.11.3 7 Jinja2==2.11.3
8 -jws==0.1.3
9 MarkupSafe==1.1.1 8 MarkupSafe==1.1.1
10 oauth2client==3.0.0 9 oauth2client==3.0.0
11 protobuf==3.15.2 10 protobuf==3.15.2
12 pyasn1==0.4.8 11 pyasn1==0.4.8
13 pyasn1-modules==0.2.8 12 pyasn1-modules==0.2.8
14 -pycryptodome==3.4.3
15 pyparsing==2.4.7 13 pyparsing==2.4.7
16 Pyrebase==3.0.27 14 Pyrebase==3.0.27
17 -python-jwt==2.0.1 15 +Pyrebase4==4.4.3
18 requests==2.11.1 16 requests==2.11.1
19 requests-toolbelt==0.7.0 17 requests-toolbelt==0.7.0
20 rsa==4.7.2 18 rsa==4.7.2
21 six==1.15.0 19 six==1.15.0
22 -Werkzeug==1.0.1 20 +Werkzeug==1.0.1
...\ No newline at end of file ...\ No newline at end of file
......
1 import os 1 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 +from config.firebase import get_data_by_id
5 +
4 6
5 root_dir = os.path.dirname(os.getcwd()) 7 root_dir = os.path.dirname(os.getcwd())
6 my_path = os.path.join(root_dir, 'check-your-instagram', 'app', 'public') 8 my_path = os.path.join(root_dir, 'check-your-instagram', 'app', 'public')
...@@ -8,14 +10,29 @@ app = Flask(__name__, static_folder=os.path.abspath(my_path)) ...@@ -8,14 +10,29 @@ app = Flask(__name__, static_folder=os.path.abspath(my_path))
8 10
9 11
10 def update(insta_id): 12 def update(insta_id):
11 - crawler_instagram(insta_id) 13 + result = 'ok'
14 + try:
15 + crawler_instagram(insta_id)
16 + except Exception as e:
17 + print(e)
18 + result = 'fail'
12 19
13 data = { 20 data = {
14 - "insta_id" : insta_id 21 + "result" : result
15 } 22 }
16 return jsonify(data) 23 return jsonify(data)
17 24
18 25
26 +def search(insta_id):
27 + result = {}
28 + try:
29 + result = get_data_by_id(insta_id)
30 + except Exception as e:
31 + print(e)
32 +
33 + return jsonify(result)
34 +
35 +
19 @app.errorhandler(404) 36 @app.errorhandler(404)
20 def page_not_found(): 37 def page_not_found():
21 return render_template('404.html') 38 return render_template('404.html')
...@@ -24,11 +41,13 @@ def page_not_found(): ...@@ -24,11 +41,13 @@ def page_not_found():
24 @app.route("/", defaults={"path": ""}) 41 @app.route("/", defaults={"path": ""})
25 @app.route("/<path:path>") 42 @app.route("/<path:path>")
26 def home(path): 43 def home(path):
44 + insta_id = request.args.get('insta_id')
27 if path == 'update': 45 if path == 'update':
28 - insta_id = request.args.get('insta_id')
29 return update(insta_id) 46 return update(insta_id)
30 - 47 + elif path == 'search':
31 - return send_from_directory(my_path, filename='index.html') 48 + return search(insta_id)
49 + else:
50 + return send_from_directory(my_path, filename='index.html')
32 51
33 52
34 if __name__ == "__main__": 53 if __name__ == "__main__":
......
No preview for this file type
1 -<!DOCTYPE html>
2 -<html>
3 -<head>
4 - <title>check insta</title>
5 -</head>
6 -<body>
7 - <h1>메인 화면</h1>
8 - <input id="insta_id" placeholder="id" type="text" name="insta_id"/>
9 - <button id="submit_id">제출</button>
10 - <script>
11 - const button = document.querySelector('#submit_id')
12 - const input = document.querySelector('#insta_id')
13 -
14 - button.addEventListener('click',async () => {
15 - let result = null;
16 -
17 - try {
18 - result = await (await fetch('http://localhost:5000/update?insta_id=' + input.value)).json()
19 - } catch (e) {
20 - console.log(e)
21 - } finally {
22 - if(result) {
23 - console.log(result.insta_id)
24 - }
25 - }
26 - })
27 - </script>
28 -</body>
29 -</html>
...\ No newline at end of file ...\ No newline at end of file