거의 일주일가까이 안했더니..이제 큰일났다!🤨
이번 주도 학원에 있는 시간아니면 거의 시간없을 것 같은데 밤샘. 예정인가 혹쉬
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python3 get-pip.py
sudo easy_install pip
pip install gspread
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = [
'https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive',
]
json_file_name = 'lego-hangang-2020-e30ccd2df9c8.json'
credentials = ServiceAccountCredentials.from_json_keyfile_name(json_file_name, scope)
gc = gspread.authorize(credentials)
spreadsheet_url = 'https://docs.google.com/spreadsheets/d/1RjMijAbTt2K1WIQlTPX5_hxu2xS6qNQQx0EXtTgc6gg/edit#gid=0'
# 스프레스시트 문서 가져오기
doc = gc.open_by_url(spreadsheet_url)
# 시트 선택하기
worksheet = doc.worksheet('여의도')
https://towardsdatascience.com/connecting-to-a-graphql-api-using-python-246dda927840
그 개발자도구에 뜨는 json을 이용해서 하려고 했더니만 내 생각에는 graphql..? 이게 또 뭔가 있는 거 같다. 근데 알아보고 싶지 않다.
😩🤨😫
아니 어떻게 혼자 스스로 찾냐구... ... 쒸익쉬익🤨
@app.route('/date', methods=['POST'])
def post_article():
# 1. 클라이언트로부터 데이터를 받기
name_receive = request.form['nickname']
title_receive = request.form['title']
loc_receive = request.form['parkLoc']
img_receive = request.form['img']
comment_receive = request.form['comment']
review = {'nickname': name_receive, 'title': title_receive, 'parkLoc': loc_receive, 'img': img_receive, 'comment': comment_receive}
# 3. mongoDB에 데이터를 넣기
db.reviews.insert_one(review)
return jsonify({'result': 'success', 'data': review})
@app.route('/date', methods=['GET'])
def read_reviews():
result = list(db.reviews.find({}, {'_id': 0}))
return jsonify({'result': 'success', 'reviews': result})
<script>
function postArticle() {
let nickname = $("#post-nickname").val();
let title = $("#post-title").val();
let parkLoc = $("#post-location").val();
let img = $("#post-img").val()
let comment = $("#post-comment").val();
// 2. memo에 POST 방식으로 메모 생성 요청하기
$.ajax({
type: "POST",
url: "/date",
data: {nickname, title, parkLoc, img, comment}, // 데이터를 주는 방법
success: function (response) { // 성공하면
if (response["result"] == "success") {
alert("포스팅 성공!");
// 3. 성공 시 페이지 새로고침하기
window.location.reload();
} else {
alert("서버 오류!")
}
}
})
}
function showArticles() {
$.ajax({
type: "GET",
url: "/date",
data: {},
success: function (response) {
let reviews = response["reviews"];
console.log(reviews);
for (let i = 0; i < reviews.length; i++) {
makeCard(reviews[i]["title"], reviews[i]["nickname"], reviews[i]["parkLoc"], reviews[i]["img"], reviews[i]["comment"]);
}
}
})
}
function makeCard(title, nickname, parkLoc, img, comment) {
let tempHtml = `<div class="card">
<div class="card-body">
<a class="card-title">${title}</a>
<p class="card-text nickname">${nickname}</p>
<p class="card-text">${parkLoc}</p>
<p class="card-img">${img}</p>
<p class="card-text comment">${comment}</p>
</div>
</div>`;
$("#cards-box").append(tempHtml);
}
</script>