Skip to content

Commit e3bc493

Browse files
authored
Update README.md
Added cb
1 parent cd9b25d commit e3bc493

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

README.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,53 +62,52 @@ firebase.setURL(URL)
6262
Set the current Firebase URL.
6363
### get
6464
```python
65-
firebase.get(PATH, DUMP, bg=False, id=0)
65+
firebase.get(PATH, DUMP, bg=False, id=0, cb=None)
6666
```
6767
Takes the given storage location `PATH`, gets the data from there and stores it as `DUMP`. The data can later be read out by `firebase.[DUMP]`.
6868
- Optional run in the background with the keyword `bg`.
6969
- Set socket id with the keyword `id`. This makes it possible to establish multiple connections to the server instead of just one. Recommended if you know what you are doing, only makes sense if the command is running in the background.
70+
- 🆕 Set an callback function after getting the `DATA`.
7071
- Example:
7172
```python
72-
firebase.get("testtag1", "VAR1", bg=True, id=0)
73-
firebase.get("testtag2", "VAR2", bg=True, id=1) #runs at the same time
74-
time.sleep(10) #Do some other things, or wait a bit, or use bg=False with id=0
75-
print("1:"+firebase.VAR1+" 2:"+firebase.VAR2)
73+
def hereweare(name, id, varname):
74+
print("\nname: ",str(name)+", id: "+str(id)+", value: "+str(eval("firebase."+varname)))
75+
firebase.get("testtag1", "VAR1", bg=True, id=0, cb=(hereweare, ("testtag1", "0", "VAR1")))
76+
firebase.get("testtag2", "VAR2", bg=True, id=1, cb=(hereweare, ("testtag2", "1", "VAR2"))) #runs at the same time
7677
```
7778
### getfile
7879
```python
79-
firebase.get(PATH, FILE, bg=False, id=0)
80+
firebase.get(PATH, FILE, bg=False, id=0, cb=None)
8081
```
8182
Takes the given storage location `PATH`, gets the data from there and stores it as file at the location `FILE`. Recommeded to download larger amounts of data to avoid ram overflow.
8283
- Optional run in the background with the keyword `bg`.
8384
- Set socket id with the keyword `id`. This makes it possible to establish multiple connections to the server instead of just one. Recommended if you know what you are doing, only makes sense if the command is running in the background.
85+
- 🆕 Set an callback function after getting the `DATA`.
8486
- Example:
8587
```python
86-
firebase.getfile("testlarge1", "FILE1.txt", id=0)
87-
firebase.getfile("testlarge2", "FILE2.txt", id=1) #runs at the same time
88-
time.sleep(20) #Do some other things, or wait a bit, or use bg=False with id=0
89-
LOCAL_FILE1=open("FILE1.txt")
90-
LOCAL_FILE2=open("FILE2.txt")
91-
print("1:"+LOCAL_FILE1.read()+" 2:"+LOCAL_FILE2.read())
92-
LOCAL_FILE1.close()
93-
LOCAL_FILE2.close()
94-
del LOCAL_FILE1
95-
del LOCAL_FILE2
88+
def herewefile(name, id, filename):
89+
LOCAL_FILE=open(str(filename))
90+
print("\nname: ",str(name)+", id: "+str(id)+", value: "+str(LOCAL_FILE.read()))
91+
LOCAL_FILE.close()
92+
firebase.getfile("testlarge1", "FILE1.txt", id=0, cb=(herewefile, ("testlarge1", "0", "FILE1.txt")))
93+
firebase.getfile("testlarge2", "FILE2.txt", id=1, cb=(herewefile, ("testlarge2", "1", "FILE2.txt"))) #runs at the same time
9694
```
9795
### put
9896
```python
99-
firebase.put(PATH, DATA, bg=True, id=0)
97+
firebase.put(PATH, DATA, bg=True, id=0, cb=None)
10098
```
10199
Takes the given storage location `PATH` and uploads the given value `DATA` there.
102100
- Optional run in the background with the keyword `bg`.
103101
- Set socket id with the keyword `id`. This makes it possible to establish multiple connections to the server instead of just one. Recommended if you know what you are doing, only makes sense if the command is running in the background. (Example at get)
102+
- 🆕 Set an callback function after getting the `DATA`.
104103
- Example:
105104
```python
106105
firebase.put("testtag1", "1", id=0)
107106
firebase.put("testtag2", "2", id=1) #runs at the same time
108107
```
109108
### patch
110109
```python
111-
firebase.patch(PATH, DATATAG, bg=True, id=0)
110+
firebase.patch(PATH, DATATAG, bg=True, id=0, cb=None)
112111
```
113112
Takes the given storage location `PATH` and patches the given key `DATATAG` there, without touching any other tag in the Database.
114113
- Example:
@@ -119,28 +118,32 @@ Takes the given storage location `PATH` and patches the given key `DATATAG` ther
119118
![image](https://user-images.githubusercontent.com/77546092/114471016-30e98a00-9bf0-11eb-90ec-baec7f10e03c.png)
120119
- Optional run in the background with the keyword `bg`.
121120
- Set socket id with the keyword `id`. This makes it possible to establish multiple connections to the server instead of just one. Recommended if you know what you are doing, only makes sense if the command is running in the background. (Example at get)
121+
- 🆕 Set an callback function after patching the `DATA`.
122122
### addto
123123
```python
124-
firebase.addto(PATH, DATA, DUMP=None, bg=True, id=0)
124+
firebase.addto(PATH, DATA, DUMP=None, bg=True, id=0, cb=None)
125125
```
126126
Takes the given storage location `PATH` and adds the given value `DATA` there, the randomly generated tag can be optionally stored in the DUMP variable.
127127
- Example:
128128
```python
129129
firebase.addto("testsensor", 128)
130130
firebase.addto("testsensor", 124)
131131
firebase.addto("testsensor", 120, DUMP="tagname")
132-
print(firebase.tagname) #returns {'name': '-MY7GTy4pp2LSpQp5775'}
132+
print(firebase.tagname) #returns '-MY7GTy4pp2LSpQp5775' (example)
133133
```
134134
![image](https://user-images.githubusercontent.com/77546092/114472221-1fa17d00-9bf2-11eb-804d-21e0ac425a87.png)
135135
- Optional run in the background with the keyword `bg`.
136136
- Set socket id with the keyword `id`. This makes it possible to establish multiple connections to the server instead of just one. Recommended if you know what you are doing, only makes sense if the command is running in the background. (Example at get)
137+
- Retuns the tag under which the data was saved.
138+
- 🆕 Set an callback function after adding the `DATA`.
137139
### delete
138140
```python
139-
firebase.delete(PATH, bg=True, id=0)
141+
firebase.delete(PATH, bg=True, id=0, cb=None)
140142
```
141143
Takes the given storage location `PATH` deletes the data there.
142144
- Optional run in the background with the keyword `bg`.
143145
- Set socket id with the keyword `id`. This makes it possible to establish multiple connections to the server instead of just one. Recommended if you know what you are doing, only makes sense if the command is running in the background. (Example at get)
146+
- 🆕 Set an callback function after deleting the `DATA`.
144147
## Constants
145148
### FIREBASE_GLOBAL_VAR.GLOBAL_URL
146149
```python

0 commit comments

Comments
 (0)