최원석
Committed by GitHub

Merge pull request #9 from goesnow/goesnow

Goesnow
No preview for this file type
/**
* @author : wonseog
* @date : 2021/03/08
* @description : 메인 app
* index.ts에서 pathname 받아
* 컴포넌트 제작 후 반환
**/
import Header from "./views/header/Header";
import Body from "./views/body/Body";
import Footer from "./views/footer/Footer";
const App = (pathname : string) : string => {
history.pushState('','', pathname);
return `
<div>
${Header()}
${Body(pathname)}
${Footer()}
<a href="/wonseog" id="nav-button" data-link>wonseok!!</a>
</div>
`;
}
export default App;
\ No newline at end of file
export const Bye = () => console.log('Bye!');
/**
* @author : wonseog
* @date : 2021/03/08
* @description : 타이틀 대 / 중 / 소 반환
**/
const titleTemplate = (type : string, title : string) => `
<div class="${type}-title">
${title}
</div>
`
const Title = (title : string) => ({
Large : titleTemplate('large', title),
Medium : titleTemplate('medium', title),
Small : titleTemplate('small', title)
})
export default Title;
\ No newline at end of file
export const BASE_URL = 'http://localhost:5000/';
......@@ -6,7 +6,7 @@
<title>home</title>
</head>
<body>
<div id="App"> </div>
<div id="App"></div>
<!-- <script src="public/main.js" ></script>-->
</body>
</html>
\ No newline at end of file
......
import {Bye} from './Bye';
import './assets/style/App.css';
import v4 from './assets/image/v4Logo.png';
/**
* @author : wonseog
* @date : 2021/03/08
* @description : 현재 pathname을 파악 후 App으로 전달
**/
import App from './App';
import {BASE_URL} from './config/url';
const hi = 'hchoi won';
window.addEventListener('DOMContentLoaded', () => {
const $App = document.querySelector('#App');
const pathname = window.location.pathname.split('/')[1];
const hi1 = () => {
console.log(hi);
Bye();
document.body.addEventListener('click', async (e) => {
e.stopPropagation();
if((e.target as HTMLAnchorElement).matches("[data-link]")){
const href = (e.target as HTMLAnchorElement).href.split(BASE_URL)[1];
e.preventDefault();
$App && ($App.innerHTML = App(href));
} else if((e.target as HTMLAnchorElement).id === 'update-button') {
let result: any= null;
const insta_id = (document.querySelector('#id-input') as HTMLInputElement).value;
const tag = window.document.querySelector('#App');
if(tag) {
tag.innerHTML = `<img src=${v4} alt="image" />`;
if(insta_id){
try{
result = await (await fetch(BASE_URL + 'update?insta_id=' + insta_id)).json();
} catch (e){
console.log(e);
} finally {
console.log(result)
result && $App && ($App.innerHTML = App('main'))
}
}
};
}
});
window.addEventListener('popstate', ()=>{
$App && ($App.innerHTML = App(pathname))
});
hi1();
\ No newline at end of file
$App && ($App.innerHTML = App(pathname));
})
\ No newline at end of file
......
/**
* @author wonseog
* @date 2021-03-09
* @description state 관리
* 주로 instaId, followers, following 관리
**/
export interface StateType{
insta_id? : string,
followers? : Array<string>,
following? : Array<string>
}
export const state: StateType ={
insta_id : '',
followers : [''],
following : [''],
};
export const setState = (newState: StateType): StateType =>({
...state,
...newState
});
\ No newline at end of file
/**
* @author : wonseog
* @date : 2021/03/08
* @description : 페이지 내용
**/
import Home from "./contents/Home";
const Body = (pathname: string) : string => {
let contentsContainer = '';
switch (pathname){
case 'compare':
break;
case 'main':
break;
default:
contentsContainer = Home();
}
return `
<div class="Body">
${contentsContainer}
</div>
`;
}
export default Body;
\ No newline at end of file
/**
* @author wonseog
* @date 2021-03-09
* @description id 입력하는 메인 화면
* 조회 / 업데이트
**/
import {state} from "../../../state/state";
import Title from "../../../components/title";
const Home = (): string =>{
const onSubmit = (e : Event) => {
e.preventDefault();
alert('hi');
}
const literalTag = `<div class="home">
<lable>
${Title('인스타 조회하기').Large}
<input id="id-input" type="text" name="insta_id" />
<button id="update-button">조회</button>
</lable>
</div>`
return literalTag;
}
export default Home;
\ No newline at end of file
/**
* @author : wonseog
* @date : 2021/03/08
* @description : 페이지 푸터
**/
const Footer = () : string => {
return `
<div class="Footer">Its my Footer</div>
`;
}
export default Footer;
\ No newline at end of file
/**
* @author : wonseog
* @date : 2021/03/08
* @description : 페이지 헤더
**/
import Title from "../../components/title";
const Header = () : string => `
<div class="header">
${Title('im title').Large}
</div>
`;
export default Header;
\ No newline at end of file
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -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,16 +43,16 @@ def get_list(insta_id, driver):
following_list = check_people(driver, "following")
# update at firebase
update_data(insta_id, followers_list, following_list)
# update_data(insta_id, followers_list, following_list)
def crawler_instagram(insta_id):
driver = webdriver.Chrome(executable_path=LOCAL_PROJECT_PATH + '/crawler/chromedriver')
driver.get(url=INSTAGRAM_URL)
time.sleep(4)
time.sleep(2)
login(driver)
time.sleep(5)
time.sleep(2)
url="%s/%s"%(INSTAGRAM_URL, insta_id)
driver.get(url=url)
......
......@@ -2,9 +2,14 @@ import os
from flask import Flask, render_template, request, jsonify, send_from_directory
from crawler.crawler_instagram import crawler_instagram
my_path = '/Users/choewonseog/Documents/check-your-instagram/app/public'
# my_path = '/Users/choewonseog/Documents/check-your-instagram/app/public'
# my_path = 'C:/Users/goesnow/Documents/study/check-your-instagram/app/public'
root_dir = os.path.dirname(os.getcwd())
my_path = os.path.join(root_dir, 'check-your-instagram', 'app', 'public')
app = Flask(__name__, static_folder=os.path.abspath(my_path))
def update(insta_id):
crawler_instagram(insta_id)
......@@ -18,24 +23,16 @@ def update(insta_id):
def page_not_found():
return render_template('404.html')
@app.route("/", defaults={"path": ""})
@app.route("/<path:path>")
def home(path):
print("hi? your in '%s' !!"%(path))
# if path != "" and os.path.exists(app.static_folder + '/' + path):
# return send_from_directory(app.static_folder, path)
# else:
# return send_from_directory(app.static_folder, 'index.html')
if path == 'update':
insta_id = request.args.get('insta_id')
update(insta_id)
elif path == '' :
root_dir = os.path.dirname(os.getcwd())
return send_from_directory(os.path.join(root_dir, 'check-your-instagram', 'app', 'public'), filename='index.html')
return render_template('index.html')
# else:
# return render_template('index.html')
return update(insta_id)
return send_from_directory(my_path, filename='index.html')
if __name__ == "__main__":
print("-" * 60)
......