Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import firebase_admin
- from firebase_admin import credentials
- from firebase_admin import firestore
- from utils import *
- import requests
- cred = credentials.Certificate("adminapp-df72a-firebase-adminsdk-aokok-0c9f7d23d3.json")
- firebase_admin.initialize_app(cred)
- db = firestore.client()
- def get_people():
- vals_ref = db.collection("PERSONS")
- vals = vals_ref.get()
- return [val.to_dict() for val in vals]
- def get_cars():
- vals_ref = db.collection("CARS")
- vals = vals_ref.get()
- return [val.to_dict() for val in vals]
- def match_car(num1, num2, data): #Return the owner of the car
- pairs = [[row["car_serial_number"].split("/")[0]] + [row["car_serial_number"].split("/")[2]] for row in data]
- for i, pair in enumerate(pairs):
- if (num1 == pair[0] and num2 == pair[1]) or (num1 == pair[1] and num2 == pair[0]):
- return data[i]
- return {"code":-1, "message": "Car doesn't exist in the database", "car_serial_number": num1 + " TUN " + num2}
- def get_carinfo(id):
- vals_ref = db.collection("CARS")
- vals = vals_ref.where("owner_id", "==", str(id)).get()
- if len(vals) > 0:
- return vals[0].to_dict()
- else:
- return -1
Advertisement
Add Comment
Please, Sign In to add comment