최원석3 [goesnow]

catch error in server

......@@ -4,7 +4,6 @@ body {
}
.container {
border: 1px solid green;
display: flex;
justify-content: center;
align-items: center;
......@@ -15,6 +14,6 @@ body {
transform: translate(-50%, -50%);
min-width: 250px;
min-height: 500px;
width: 90%;
width: 100%;
height: 100%;
}
\ No newline at end of file
......
......@@ -7,6 +7,7 @@
import App from './App';
import {BASE_URL} from './config/url';
import {initialTrantition, randomTransition} from "./components/pageTransition";
import {setState} from "./state/state";
window.addEventListener('DOMContentLoaded', () => {
/* add div for page transitions */
......@@ -53,7 +54,10 @@ window.addEventListener('DOMContentLoaded', () => {
console.log(e);
} finally {
console.log(result);
result && $App && ($App.innerHTML = App('main'));
result && $App && (()=>{
$App.innerHTML = App('main');
setState({insta_id : insta_id});
})();
}
} else {
alert('아이디를 입력하세요');
......
export {default} from './state';
......@@ -11,7 +11,7 @@ export interface StateType{
following? : Array<string>
}
export const state: StateType ={
const state: StateType ={
insta_id : '',
followers : [''],
following : [''],
......@@ -21,3 +21,5 @@ export const setState = (newState: StateType): StateType =>({
...state,
...newState
});
export default state;
......
......@@ -4,7 +4,7 @@
* @description id 입력하는 메인 화면
* 조회 / 업데이트
**/
import {state} from "../../../state/state";
import state from "../../../state";
import Title from "../../../components/title";
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)
db = firebase.database()
def update_data(user_insta_id ,followers, followings):
insta_id = user_insta_id.replace('_','').replace('.','')
data = {
"followings" : followings,
"followers" : followers
}
def id_encrypt(user_insta_id):
return user_insta_id.replace('_', '1z1').replace('.', '2z2')
def update_data(user_insta_id, data):
insta_id = id_encrypt(user_insta_id)
db.child("insta").child(insta_id).update(data)
def get_data_by_id(user_insta_id):
insta_id = id_encrypt(user_insta_id)
data = db.child("insta").child(insta_id).get()
return data.val()
......
......@@ -3,7 +3,7 @@ from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from config.admin import ID, PW, LOCAL_PROJECT_PATH
from config.URLs import INSTAGRAM_URL
# from config.firebase import update_data
from config.firebase import update_data
def check_people(driver, type):
result = []
......@@ -43,7 +43,12 @@ def get_list(insta_id, driver):
following_list = check_people(driver, "following")
# update at firebase
# update_data(insta_id, followers_list, following_list)
data = {
"followers" : followers_list,
"followings" : following_list,
"insta_id" : insta_id
}
update_data(insta_id, data)
def crawler_instagram(insta_id):
......@@ -64,10 +69,9 @@ def crawler_instagram(insta_id):
isPrivate = ""
pass
# 비공개 계정인 경우
# account is private
if isPrivate:
print('private!!')
# 공개 계정인 경우
else:
get_list(insta_id, driver)
......
No preview for this file type
......@@ -5,16 +5,14 @@ googleapis-common-protos==1.52.0
httplib2==0.19.0
itsdangerous==1.1.0
Jinja2==2.11.3
jws==0.1.3
MarkupSafe==1.1.1
oauth2client==3.0.0
protobuf==3.15.2
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycryptodome==3.4.3
pyparsing==2.4.7
Pyrebase==3.0.27
python-jwt==2.0.1
Pyrebase4==4.4.3
requests==2.11.1
requests-toolbelt==0.7.0
rsa==4.7.2
......
import os
from flask import Flask, render_template, request, jsonify, send_from_directory
from crawler.crawler_instagram import crawler_instagram
from config.firebase import get_data_by_id
root_dir = os.path.dirname(os.getcwd())
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))
def update(insta_id):
result = 'ok'
try:
crawler_instagram(insta_id)
except Exception as e:
print(e)
result = 'fail'
data = {
"insta_id" : insta_id
"result" : result
}
return jsonify(data)
def search(insta_id):
result = {}
try:
result = get_data_by_id(insta_id)
except Exception as e:
print(e)
return jsonify(result)
@app.errorhandler(404)
def page_not_found():
return render_template('404.html')
......@@ -24,10 +41,12 @@ def page_not_found():
@app.route("/", defaults={"path": ""})
@app.route("/<path:path>")
def home(path):
if path == 'update':
insta_id = request.args.get('insta_id')
if path == 'update':
return update(insta_id)
elif path == 'search':
return search(insta_id)
else:
return send_from_directory(my_path, filename='index.html')
......
No preview for this file type
<!DOCTYPE html>
<html>
<head>
<title>check insta</title>
</head>
<body>
<h1>메인 화면</h1>
<input id="insta_id" placeholder="id" type="text" name="insta_id"/>
<button id="submit_id">제출</button>
<script>
const button = document.querySelector('#submit_id')
const input = document.querySelector('#insta_id')
button.addEventListener('click',async () => {
let result = null;
try {
result = await (await fetch('http://localhost:5000/update?insta_id=' + input.value)).json()
} catch (e) {
console.log(e)
} finally {
if(result) {
console.log(result.insta_id)
}
}
})
</script>
</body>
</html>
\ No newline at end of file