firebase.py
1.1 KB
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
45
46
47
48
49
50
from pyrebase import pyrebase
import os
from config.key import *
config = {
"apiKey": FIREBASE_APIKEY,
"authDomain": FIREBASE_AUTHDOMAIN,
"projectId": FIREBASE_PROJECTID,
"storageBucket": FIREBASE_STORAGEBUCKET,
"messagingSenderId": FIREBASE_MESSAGINGSENDERID,
"appId": FIREBASE_APPID,
"databaseURL": FIREBASE_DATABASEURL,
"measurementId": FIREBASE_MEASUREMENTID
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
def id_encrypt(user_insta_id):
return user_insta_id.replace('_', '').replace('.', '')
def update_data(user_insta_id, data):
insta_id = id_encrypt(user_insta_id)
db.child("insta").child(insta_id).update(data)
def get_data_by_id(user_insta_id):
insta_id = id_encrypt(user_insta_id)
data = {};
try:
data = db.child("insta").child(insta_id).get()
except Exception as e:
print(e)
return {
'result' : 'no'
}
finally:
if data:
return data.val()
else:
return {
'followers': [],
'following': []
}