Skip to content

Commit 80bcbec

Browse files
authored
Merge pull request #127 from Mehmet-Alpergun/master
added motion project
2 parents 35b06d3 + 4564080 commit 80bcbec

File tree

6 files changed

+821
-0
lines changed

6 files changed

+821
-0
lines changed

Projects/motion/app.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
from flask import Flask, render_template,request
2+
import random
3+
from textbox import TextBoxDb
4+
5+
from db import Firebase
6+
app = Flask(__name__)
7+
8+
datas=[]
9+
link = "quick_note"
10+
11+
12+
f = Firebase()
13+
f.login("prof@university.edu", "password")
14+
15+
@app.route("/")
16+
def home_page():
17+
datas = paragraph()
18+
if len(datas) !=0:
19+
return render_template("index.html", items = datas)
20+
21+
22+
return render_template("index.html")
23+
24+
25+
26+
27+
@app.route("/yapilacaklar", methods=["GET","POST"])
28+
def add_textbox():
29+
if request.method == "POST":
30+
todo_name = request.form['input-box']
31+
cur_id = random.randint(1,10000)
32+
cur_id = str(cur_id)
33+
textBox= TextBoxDb( cur_id, link,f)
34+
textBox.class_ = link
35+
textBox.id = (
36+
cur_id)
37+
38+
textBox.paragraph = todo_name
39+
textBox.create()
40+
41+
return render_template("index.html", items = paragraph())
42+
43+
else:
44+
return render_template("error.html")
45+
46+
47+
48+
@app.route("/delete/<todo_id>", methods=["GET","POST"])
49+
def delete(todo_id):
50+
datas = []
51+
52+
ref = f.ref
53+
for i in link.split('/'):
54+
ref = ref.child(i)
55+
56+
for j in ref.get():
57+
item = ref.child(j).get()
58+
if item and "id" in item and str(item["id"]) == todo_id:
59+
datas= paragraph()
60+
if len(datas) >1:
61+
ref.child(j).delete()
62+
datas =paragraph()
63+
64+
return render_template("index.html", items = datas)
65+
66+
67+
@app.route("/update/<int:todo_id>", methods=["GET", "POST"])
68+
def update(todo_id):
69+
todo_paragraph = request.form['box']
70+
print(todo_paragraph)
71+
update_data = {
72+
'paragraph': todo_paragraph,
73+
'id': todo_id,
74+
'class_': ''
75+
}
76+
ref = f.ref
77+
for i in link.split('/'):
78+
ref = ref.child(i)
79+
80+
for j in ref.get():
81+
item = ref.child(j).get()
82+
if item and "id" in item and str(item["id"]) == str(todo_id):
83+
ref.child(j).update(update_data)
84+
85+
return render_template("index.html", items = paragraph())
86+
87+
88+
def paragraph():
89+
datas = []
90+
91+
ref = f.ref
92+
for i in link.split('/'):
93+
ref = ref.child(i)
94+
95+
for j in ref.get():
96+
if "paragraph" in ref.child(j).get():
97+
paragraph = ref.child(j).get()["paragraph"]
98+
id = ref.child(j).get()["id"]
99+
datas.append({"paragraph": paragraph, "id": id})
100+
101+
return datas
102+
103+
"""
104+
105+
@app.route('/route', methods=['POST'])
106+
def button_click():
107+
data = request.get_json()
108+
link = data['buttonId']
109+
# Buton idsini işle
110+
print("Buton ID'si:", link)
111+
112+
return redirect(url_for('home_page'))
113+
114+
115+
116+
"""
117+
118+
119+
120+
if __name__ == "__main__":
121+
122+
123+
app.run()

Projects/motion/db.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import firebase_admin # pip install firebase-admin
2+
from firebase_admin import credentials, db
3+
import pyrebase # pip install pyrebase4
4+
5+
6+
class Firebase:
7+
def __init__(self):
8+
9+
CREDENTIALS_FILE = "smoke.json"
10+
DATABASE_URL = "https://catb-535cd-default-rtdb.europe-west1.firebasedatabase.app/"
11+
12+
API_KEY = "AIzaSyDRu3t0msAtmaQl8NILK76erH0e1EB5F5A"
13+
# You can find your project ID in your Firebase project settings. #
14+
PROJECT_ID = "catb-535cd"
15+
16+
self.cred = credentials.Certificate(CREDENTIALS_FILE)
17+
firebase_admin.initialize_app(
18+
self.cred,
19+
{
20+
"databaseURL": DATABASE_URL,
21+
},
22+
)
23+
self.ref = db.reference("/")
24+
self.config = {
25+
"apiKey": API_KEY,
26+
"authDomain": f"{PROJECT_ID}.firebaseapp.com",
27+
"databaseURL": DATABASE_URL,
28+
"storageBucket": f"{PROJECT_ID}.appspot.com",
29+
}
30+
self.firebase = pyrebase.initialize_app(self.config)
31+
self.auth = self.firebase.auth()
32+
33+
def login(self, email, password):
34+
user = self.auth.sign_in_with_email_and_password(email, password)
35+
return user
36+
37+
def register(self, email, password):
38+
user = self.auth.create_user_with_email_and_password(email, password)
39+
return user
40+
41+
def get_current_user(self):
42+
return self.auth.current_user
43+
44+
def get_user_id(self):
45+
return self.auth.current_user["localId"]
46+
47+
def get_user_email(self):
48+
return self.auth.current_user["email"]
49+
50+
def logout(self):
51+
self.auth.current_user = None
52+
53+
54+
if __name__ == "__main__":
55+
f = Firebase()
56+
print(f.ref.get())
57+
f.ref.set({"name": "Borssdsdfa Canbula"})
58+
print(f.ref.get())
59+
f.ref.set({"n": "Bsadaora"})
60+
print(f.ref.get())
61+
try:
62+
f.login("prof@university.edu", "password")
63+
except Exception as e:
64+
f.register("prof@university.edu", "password")
65+
print(f.get_current_user())
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
function sendButtonId(buttonId) {
3+
console.log("Button ID: " + buttonId);
4+
5+
// Veriyi Flask'a gönder
6+
fetch('/route', {
7+
method: 'POST',
8+
headers: {
9+
'Content-Type': 'application/json'
10+
},
11+
body: JSON.stringify({ buttonId: buttonId })
12+
})
13+
.then(response => response.json())
14+
.then(data => {
15+
console.log('Success:', data);
16+
})
17+
.catch((error) => {
18+
console.error('Error:', error);
19+
});
20+
}

0 commit comments

Comments
 (0)