-
Notifications
You must be signed in to change notification settings - Fork 0
/
Firebase.py
44 lines (31 loc) · 1.15 KB
/
Firebase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import pyrebase
import datetime
import uuid
import firestore
config = {
"apiKey": "AIzaSyDR7jMMHJrMtJ10cGW21NCnQA8dYscdotE",
"authDomain": "agritech-1947ls.firebaseapp.com",
"projectId": "agritech-1947ls",
"storageBucket": "agritech-1947ls.appspot.com",
"messagingSenderId": "88388988117",
"appId": "1:88388988117:web:18ac81dd73344ef653465c",
"measurementId": "G-25KHE0BG20",
"databaseURL" : 'https://agritech-1947ls-default-rtdb.firebaseio.com/'
}
firebase = pyrebase.initialize_app(config)
auth = firebase.auth()
storage = firebase.storage()
def upload_image(img_path:str, label:str, result:str):
unique_id = str(uuid.uuid1())
path = 'notification_images/{}'.format(unique_id)
storage.child(path).put(img_path)
email = 'admin@gmail.com'
user = auth.sign_in_with_email_and_password(email,'admin@shyam')
url = storage.child(path).get_url(user['idToken'])
firestore.add_record(email, unique_id, url, label, result)
return url
def main():
img_path = "images/test.png"
upload_image(img_path, 'label', 'result')
if __name__ == '__main__' :
main()