-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdatabase.py
More file actions
29 lines (23 loc) · 756 Bytes
/
database.py
File metadata and controls
29 lines (23 loc) · 756 Bytes
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
from firebase import firebase
import hashlib
class Database:
def __init__(self):
self.fb = firebase.FirebaseApplication(
'https://hariket.mic.firebaseio.com/', None)
def get_data(self, category):
data = self.fb.get('/{}'.format(category), None)
return data
def write_data(self, category, data, flag=False):
if not flag:
gen = data['name']
hash_object = hashlib.sha1(gen.encode())
hex_dig = hash_object.hexdigest()
else:
hex_dig = flag
result = self.fb.put('/' + category, hex_dig[-15:], data)
return True
if __name__ == '__main__':
db = Database()
db.write_data('enterprises', {
'name': 'P&G Inc.',
})