Skip to content

Commit

Permalink
Realtime Database firebase:
Browse files Browse the repository at this point in the history
  • Loading branch information
katmakhan committed Aug 16, 2022
1 parent 163e395 commit 0e57925
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Cloud Database/Database - Firebase/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#Firebase Imports
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db

cred = credentials.Certificate("/firebase-admin-key.json")


print("initilising firebase app")

#Initilising Database
firebase_admin.initialize_app(cred, {
'databaseURL' : 'https://<project-id>-<database-instance>.firebaseio.com/'
})

# Initilising Database 2
app2 = firebase_admin.initialize_app(cred, {
'databaseURL': 'https://<project-id>-<database-instance>.firebaseio.com/'
}, name='app2')



# Fetch Data from firebase
def fetch_data_firebase(path):
ref=db.reference('Users',app2).child(path)
data=ref.get()
print(data)
print("Succesfully fetched data from firebase ")

# Update Data from firebase
def update_data_firebase(path,data):
ref=db.reference('Users',app2).child(path)
ref.set(data)
print("Succesfully updated the data in firebase")

# Delete Data from firebase
def delete_data_firebase(path):
ref=db.reference('Users',app2).child(path)
ref.delete()
print("Succesfully deleted the data from firebase")

# Main Function
def main():
fetch_data_firebase("Registered")

data_to_update={"my-key": "value"}
update_data_firebase("Updated",data_to_update)

delete_data_firebase("UnRegistered")

#Main program
if __name__ == '__main__':
main()
53 changes: 53 additions & 0 deletions Cloud Database/Database - Firebase/sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#Firebase Imports
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db

cred = credentials.Certificate("/firebase-admin-key.json")


print("initilising firebase app")

#Initilising Database
firebase_admin.initialize_app(cred, {
'databaseURL' : 'https://<project-id>-<database-instance>.firebaseio.com/'
})

# Initilising Database 2
app2 = firebase_admin.initialize_app(cred, {
'databaseURL': 'https://<project-id>-<database-instance>.firebaseio.com/'
}, name='app2')



# Fetch Data from firebase
def fetch_data_firebase(path):
ref=db.reference('Users',app2).child(path)
data=ref.get()
print(data)
print("Succesfully fetched data from firebase ")

# Update Data from firebase
def update_data_firebase(path,data):
ref=db.reference('Users',app2).child(path)
ref.set(data)
print("Succesfully updated the data in firebase")

# Delete Data from firebase
def delete_data_firebase(path):
ref=db.reference('Users',app2).child(path)
ref.delete()
print("Succesfully deleted the data from firebase")

# Main Function
def main():
fetch_data_firebase("Registered")

data_to_update={"my-key": "value"}
update_data_firebase("Updated",data_to_update)

delete_data_firebase("UnRegistered")

#Main program
if __name__ == '__main__':
main()
15 changes: 15 additions & 0 deletions Data POST/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Fetching get request by setting User Agent parameter

### POST METHOD
- To add json data into some web api endpoint

```python

```

### Disclaimer
- Please use this scripts for educational purpose only
- Read the web scrapping policy of the website before scrapping it
- You can be subjected to legal formalities when you violate their policies
- Use web scraping for educational purpose only
- Scrap with websites which do allow web scrapping
21 changes: 21 additions & 0 deletions Data POST/post_json_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#For invoking http requests
import requests

#Json Parsing
import json


def main():
#For Testing
url='https://w'

#This website prevents normal Traffic, unlesss you specify the user agent, the server won't response
resp = requests.put(url,headers=headers)
print("Done..")
print(resp)
data = resp.json()
print(data)

#Main program
if __name__ == '__main__':
main()

0 comments on commit 0e57925

Please sign in to comment.