: Micro-framework that allows us to make a website with Python. It has a basic to make a website.
https://flask.palletsprojects.com/en/1.1.x/
1) repl에서 flask 패키지를 다운로드 해준다.
2) Flask를 import 해주고 아래와 같은 코드를 작성해준다. @는 decorator로 데코레이터는 바로 아래 있는 함수를 찾아 그 함수를 꾸며주는 역할을 한다. So as soon as Python sees a code like below, python knows that if somebody goes to "/contact", we want to execute the function under that decorator. Because decorators look for functions, if it's not a function under a decorator, I will get an error.
마지막줄의 host="0.0.0.0"은 repl에서 작업하기 때문에 넣어둔 것. As we include this, repl knows that we want to expose this as a website.
아래의 코드로 쉽게 두 개의 페이지를 만들어준 것.


: What we want to do is making a form for users to write a job they are looking for, and to click with a button.




우리가 원하는 화면은 보여지게 됐으나 검색어를 입력하고 search 버튼을 눌러도 아무 일도 일어나지 않는다. 무엇을 해야하나?
1) Action : The URL that processes the form submission.
2) Method : The HTTP method to submit the form with. Possible (case insensitive) values
get : The GET method; form data appended to the action URL with a ? separator. Use this method when the form has no side-effects.
3) name : The name of the form. The value must not be the empty string, and must be unique among the form elements in the forms collection that it is in, if any.




get https://werkzeug.palletsprojects.com/en/0.14.x/datastructures/#werkzeug.datastructures.MultiDict.get
MultiDict
https://werkzeug.palletsprojects.com/en/0.14.x/datastructures/#werkzeug.datastructures.MultiDict


: Connect the scraper I built with this website.
만약 링크에 ?word=keyword가 존재하지 않는 "https://webscraperadvanced.elliottjeong.repl.co/report" 이런 상태라면 위와 같은 코드로는 "You are looking for"만 출력되게 된다. However, what we want is to redirect users to the home page when nothing is searched.

python뿐만 아니라 다른 직업들에 대해서도 검색을 할 수 있도록 scraper 코드를 수정해줘야 한다.
1) scraper.py 파일에서 job을 추출하는 최초함수의 변수에 입력된 키워드, 즉 검색어가 될 word를 입력해주고

2) from scraper에서 imprt get_jobs 함수를 불러와 주고, if word가 존재할시, jobs라는 변수에 get_jobs(word)가 저장되도록 한다.

3) get_jobs(word)이 부른 get_last_page(word)가 다음과 같이 url에 정보를 request할 것이므로, URL은 맨 상단이 아닌 get_jobs(word) 안으로 옮겨와 키워드가 들어갈 란을 {word}로 바꿔줘야 한다.
-> 최초함수 get_jobs가 검색어인 word를 받아와 url을 생성하고 그 url이 get_last_page에 인자로 들어가 result에 해당 url에 대한 정보를 저장.


4) last_page 값을 get한 후, extract_jobs 함수가 실행되는데, 이 역시 url을 요구하므로 수정을 해줘야 한다. extract_jobs란 함수가 두 개의 인자를 가질 수 있도록.


6: fake 데이터베이스를 만들어 준 것(dictionary type)
18: fromDb라는 변수는 6의 딕셔너리 db에서 word라는 키에 해당하는 value이다.
19: 만약 그렇게 입력된 키워드에 대한 value가 frmoDb에 존재한다면, 즉 already 저장된 값이라면 jobs= fromDB를 하고 pass
22: 존재하지 않는다면, 즉 새로 입력된 값이라면 jobs = get_jobs(word) function 실행한 후
24: db에 저장. 키는 word, value는 jobs.즉 만약 react 잡을 검색했다면, 키는 react 그리고 value는 추출된 react 잡들이 되는 것.


1) 표를 만들어서 결과를 보여주고 싶다면? 아래와 같이 html에 섹션을 만들어주고, css로 grid를 먼저 만든다.

Output :

2) scraping한 잡들을 해당 grid에 넣어 보여주고 싶다면? 31번째 줄과 같이 추출된 jobs들을 html에 보내줄 수 있도록 render_template에 jobs=jobs를 해준다.

3) Flask는 html 안에서도 파이썬 코드를 입력할 수 있게 해준다. When you type python code on html for Flask, we need to write it in {% code here %}

Output :

Try and Except



Output :
한번의 추출의 결과로 fake DB에 해당 내용이 저장되어 있으므로 export?word=nest 링크가 Exception block으로 가지 않고 제대로 작동





: flask에서 send_file function을 다운 받아준 후, export function의 return으로 send_file 해주면, 원하는 내용이 담긴 "jobs.csv" 파일이 다운로드된다.


: If I want to build a website with DB, it would be better to keepy studying Django because doing it in Flask incldues more manual works than in Django.