-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathupload_test.py
73 lines (60 loc) · 1.88 KB
/
upload_test.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 25 01:05:35 2018
@author: Fasermaler
"""
import pickle
import firebase_admin
import datetime
import requests
import urllib
import time
from datetime import date
from firebase_admin import credentials
from firebase_admin import firestore
from google.cloud import storage
try:
firebase_admin.delete_app(firebase_admin.get_app())
except:
pass
# Use a service account
cred = credentials.Certificate('') # Add JSON key accordingly
firebase_admin.initialize_app(cred)
firebase_admin.get_app()
db = firestore.client()
for i in range(1, 2):
# test image available variable
image_available = 0
#
def upload_file():
global image_available
image_url = "%2Ftemp_img_1" #Append projecy URL accordingly
data = pickle.dumps(cv2.imread('1.jpg'))
files = {'file':'1.data'}
with open('1.pkl', 'wb') as outfile:
outfile.write(data)
files = {'1.pkl', open('1.pkl', 'wb')}
try:
my_request = requests.post(url=image_url, files=files)
image_available = 1
except:
print("Failed to get file from RPI 1 at: " + str(datetime.datetime.now()))
image_available = 0
upload_file()
doc_ref = db.collection(u'RPIs').document(u'1')
doc_ref.set({
u'1 rpi': u'1',
u'2 date': str(date.today()),
u'3 time': str(datetime.datetime.now().time()),
u'4 imagestate': u'available'
})
if image_available == 1:
doc_ref.update({
u'4 imagestate': u'available'
})
elif image_available == 0:
doc_ref.update({
u'4 imagestate': u'unavailable'
})
time.sleep(1)
firebase_admin.delete_app(firebase_admin.get_app())