Maroxtn

Untitled

May 27th, 2021
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import firebase_admin
  2. from firebase_admin import credentials
  3. from firebase_admin import firestore
  4. from utils import *
  5. import requests
  6.  
  7. cred = credentials.Certificate("adminapp-df72a-firebase-adminsdk-aokok-0c9f7d23d3.json")
  8. firebase_admin.initialize_app(cred)
  9.  
  10. db = firestore.client()
  11.  
  12. def get_people():
  13.  
  14. vals_ref = db.collection("PERSONS")
  15. vals = vals_ref.get()
  16.  
  17. return [val.to_dict() for val in vals]
  18.  
  19.  
  20. def get_cars():
  21.  
  22. vals_ref = db.collection("CARS")
  23. vals = vals_ref.get()
  24.  
  25. return [val.to_dict() for val in vals]
  26.  
  27.  
  28. def match_car(num1, num2, data): #Return the owner of the car
  29.  
  30. pairs = [[row["car_serial_number"].split("/")[0]] + [row["car_serial_number"].split("/")[2]] for row in data]
  31.  
  32. for i, pair in enumerate(pairs):
  33. if (num1 == pair[0] and num2 == pair[1]) or (num1 == pair[1] and num2 == pair[0]):
  34. return data[i]
  35.  
  36. return {"code":-1, "message": "Car doesn't exist in the database", "car_serial_number": num1 + " TUN " + num2}
  37.  
  38. def get_carinfo(id):
  39.  
  40. vals_ref = db.collection("CARS")
  41. vals = vals_ref.where("owner_id", "==", str(id)).get()
  42.  
  43. if len(vals) > 0:
  44. return vals[0].to_dict()
  45. else:
  46. return -1
  47.  
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment