def gen_report_new(uid,field_address,field_lat,field_long,imagedate,fieldid,field_area,lang,failed, whitelabel):
import pdfkit
import io
import codecs
from create_bargraph import create_bargraph
from create_linegraph import create_linegraph
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
from firebase_admin import messaging
import time
import datetime
from google.cloud import storage
from get_weather_data import get_weather_data
from datetime import date
from create_temperature_bargraph import create_temperature_bargraph
from create_weather_line_graph import create_weather_line_graph
import cv2
from PIL import Image
from create_index_piechart import create_index_piechart
from get_weather_forecast import get_weather_forecast
from column_img import column_img
import csv
import os.path
from upload_file import upload_file
import os
from pyvirtualdisplay import Display
from pdf_compressor import compress
from geopy.geocoders import Nominatim
#from docx_to_pdf import docx_to_pdf
# Fetch the service account key JSON file contents
geolocator = Nominatim(user_agent ="geoapiExercises")
location = geolocator.reverse(str(field_lat)+"," + str(field_long))
address_obj = location.raw['address']
temp_field_address = address_obj.get('suburb','') + ", " + address_obj.get('city','') + ", " + address_obj.get('state','') + ", " + address_obj.get('country','')
temp_field_address = field_address
storage_client = storage.Client()
bucket_name = 'farmbase-b2f7e.appspot.com'
cred = credentials.Certificate('servicekey.json')
try:
firebase_admin.initialize_app(cred, {'databaseURL': 'https://farmbase-b2f7e-31c0c.firebaseio.com/'})
except:
print('fire running')
all_langs = lang.split(",")
for lang in all_langs:
lang = lang.replace(" ","")
lang_num = 0
all_strings = []
row_num = 0
print(lang)
all_strings.append(lang)
try:
reportStrings = db.reference('ReportStrings').child(lang).get()
except:
reportStrings = db.reference('ReportStrings').child('en').get()
#print(reportStrings)
for i in reportStrings:
all_strings.append(i)
#print(all_strings)
print(all_strings[5])
today = date.today()
date_d = today.strftime('%Y%m%d')
year = date_d[0:4]
month = date_d[4:6]
day = date_d[6:]
report_date = year+'-'+month+'-'+day+' (in yyyy-mm-dd)'
pageno = 1
sensed_year = imagedate[0:4]
sensed_month = imagedate[4:6]
sensed_day = imagedate[6:]
sensed_imagedate = sensed_year+'-'+sensed_month+'-'+sensed_day+' (in yyyy-mm-dd)'
sensed_day = int(sensed_day)
sensed_month = int(sensed_month)
print('report_date')
print(report_date)
print(sensed_imagedate)
tci_image = uid+'/TCI.png'
etci_image = uid+'/ETCI.png'
ndvi_image = uid+'/ndvi.png'
evi_image = uid+'/evi.png'
savi_image = uid+'/savi.png'
ndwi_image = uid+'/ndwi.png'
ndmi_image = uid+'/ndmi.png'
ndre_image = uid+'/ndre.png'
hybrid_image = uid+'/hybrid.png'
hybrid_blind_image = uid+'/hybrid_blind.png'
soc_image = uid+'/soc.png'
evapo_image = uid+'/evapo.png'
ndvi_image_cmap2 = uid+'/ndvi_cmap2.png'
evi_image_cmap2 = uid+'/evi_cmap2.png'
ndwi_image_cmap2 = uid+'/ndwi_cmap2.png'
ndre_image_cmap2 = uid+'/ndre_cmap2.png'
savi_image_cmap2 = uid+'/savi_cmap2.png'
soc_image_cmap2 = uid+'/soc_cmap2.png'
savi_image_cmap2 = uid+'/savi_cmap2.png'
ndmi_image_cmap2 = uid+'/ndmi_cmap2.png'
# Initialize the app with a service account, granting admin privileges
#whitelabel = "nothing"
health = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Health').get()
ndvi = try_index(health, "ndvi")
evi = try_index(health, "evi")
ndwi = try_index(health, "ndwi")
ndre = try_index(health, "ndre")
ndmi = try_index(health, "ndmi")
savi = try_index(health, "savi")
soc = try_index(health, "soc")
#if lang == 'ar':
# alignmentType = WD_ALIGN_PARAGRAPH.RIGHT
#else:
# alignmentType = WD_ALIGN_PARAGRAPH.LEFT
header_img_url = 'APIOrganizations/'+uid + '.jpeg'
if os.path.isfile(header_img_url):
header_img_url = 'https://farmonaut.com/Images/'+uid + '.jpeg'
else:
header_img_url = 'APIOrganizations/'+whitelabel + '.jpg'
if os.path.isfile(header_img_url):
header_img_url = 'https://farmonaut.com/Images/'+whitelabel + '.jpg'
else:
header_img_url ='https://farmonaut.com/Images/Farmonaut_Logo_1.jpg'
f_lat = str(field_lat)
f_lat = f_lat[0:6]
f_long = str(field_long)
f_long = f_long[0:6]
cur_date = imagedate
cur_weather_data = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).get()
try:
min_temp = cur_weather_data["min_temp"]
except:
min_temp = None
past_weather_url = 'https://farmonaut.com/Images/data_not_found.jpg'
#min_temp = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).child('min_temp').get()
if min_temp is None:
print('Weather data not available')
min_temp = "not available"
max_temp = "not available"
humidity = "not available"
pressure = "not available"
station = "not available"
wind_speed = "not available"
wind_deg = "not available"
cloud_cover = "not available"
else:
min_temp = float(min_temp)-273
min_temp = str(min_temp)
min_temp = min_temp[0:5]
max_temp = cur_weather_data["max_temp"]
#max_temp = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).child('max_temp').get()
max_temp = float(max_temp)-273
max_temp = str(max_temp)
max_temp = max_temp[0:5]
humidity = cur_weather_data["humidity"]
#humidity = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).child('humidity').get()
pressure = cur_weather_data["pressure"]
#pressure = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).child('pressure').get()
station = cur_weather_data["station"]
#station = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).child('station').get()
wind_speed = cur_weather_data["wind_speed"]
#wind_speed = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).child('wind_speed').get()
try:
wind_deg = cur_weather_data["wind_deg"]
except:
wind_deg = 'Not Available'
#wind_deg = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').child(cur_date).child('wind_deg').get()
try:
cloud_cover = cur_weather_data["cloud_cover"]
except:
cloud_cover = 'Not Available'
weather_data = db.reference('PaidMonitoredFields').child('PMF').child(uid).child(fieldid).child('Weather').get()
if weather_data is None:
print('weather data not available yet')
else:
cloud_array = []
humidity_array = []
max_temp_array = []
min_temp_array = []
pressure_array = []
wind_deg_array = []
wind_speed_array = []
dates_array = []
for (key,val) in weather_data.items():
weather_date = key
date_data = weather_data[weather_date]
dates_array.append(weather_date)
dates_array.sort()
for key in dates_array:
weather_date = key
date_data = weather_data[weather_date]
try:
cloud_array.append(date_data["cloud_cover"])
except:
cloud_array.append('not availabe')
try:
humidity_array.append(date_data["humidity"])
except:
humidity_array.append('not available')
try:
t_max_temp = date_data["max_temp"]-273
except:
t_max_temp = 'not available'
try:
t_min_temp = date_data["min_temp"]-273
except:
t_min_temp = 'not available'
max_temp_array.append(t_max_temp)
min_temp_array.append(t_min_temp)
try:
pressure_array.append(date_data["pressure"])
except:
pressure_array.append('not available')
try:
wind_deg_array.append(date_data["wind_deg"])
except:
wind_deg_array.append('not available')
try:
wind_speed_array.append(date_data["wind_speed"])
except:
wind_speed_array.append('not available')
if len(dates_array)>1:
try:
line_types = ['min_temp','max_temp','cloud_cover','humidity','pressure','wind_speed']
weather_array = [min_temp_array,max_temp_array,cloud_array,humidity_array,pressure_array,wind_speed_array]
create_weather_line_graph(uid,line_types,weather_array,dates_array)
past_weather_url = upload_file(uid, fieldid, imagedate,(uid+'_weather_linegraph.png'),'past_weather.png')
except:
past_weather_url = 'https://farmonaut.com/Images/data_not_found.jpg'
if len(ndvi)>1:
create_linegraph(uid,'ndvi',ndvi)
create_linegraph(uid,'evi',evi)
create_linegraph(uid,'savi',savi)
create_linegraph(uid,'ndre',ndre)
create_linegraph(uid,'ndwi',ndwi)
create_linegraph(uid,'ndmi',ndmi)
create_linegraph(uid,'soc',soc)
hybrid_url = upload_file(uid, fieldid,imagedate,(uid + '/hybrid.png'), 'hybrid')
hybrid_scale_url = 'https://farmonaut.com/Images/hybrid_scale.jpg'
hybrid_blind_url = upload_file(uid, fieldid, imagedate, (uid + '/hybrid_blind.png'), 'hybrid_blind')
hybrid_blind_scale_url = 'https://farmonaut.com/Images/hybrid_blind_scale.jpg'
ndvi_url = upload_file(uid, fieldid, imagedate, (uid + '/ndvi.png'), 'ndvi')
rvi_url = upload_file(uid, fieldid, imagedate, (uid + '/rvi.png'), 'rvi')
ndvi_scale_url = 'https://farmonaut.com/Images/ndvi_scale.jpg'
ndvi2_url = upload_file(uid, fieldid, imagedate, (uid + '/ndvi_cmap2.png'), 'ndvi_cmap2')
ndvi_line_url = upload_file(uid, fieldid, imagedate, (uid + '/ndvi_linegraph.png'), 'ndvi_linegraph')
ndvi_pie_url = upload_file(uid, fieldid, imagedate, (uid + '/ndvi_piechart.png'), 'ndvi_piechart')
evi_url = upload_file(uid, fieldid, imagedate, (uid + '/evi.png'), 'evi')
evi_scale_url = 'https://farmonaut.com/Images/evi_scale.jpg'
evi2_url = upload_file(uid, fieldid, imagedate, (uid + '/evi_cmap2.png'), 'evi_cmap2')
evi_line_url = upload_file(uid, fieldid, imagedate, (uid + '/evi_linegraph.png'), 'evi_linegraph')
evi_pie_url = upload_file(uid, fieldid, imagedate, (uid + '/evi_piechart.png'), 'evi_piechart')
savi_url = upload_file(uid, fieldid, imagedate, (uid + '/savi.png'), 'savi')
savi_scale_url = 'https://farmonaut.com/Images/savi_scale.jpg'
savi2_url = upload_file(uid, fieldid, imagedate, (uid + '/savi_cmap2.png'), 'savi_cmap2')
savi_line_url = upload_file(uid, fieldid, imagedate, (uid + '/savi_linegraph.png'), 'savi_linegraph')
savi_pie_url = upload_file(uid, fieldid, imagedate, (uid + '/savi_piechart.png'), 'savi_piechart')
ndre_url = upload_file(uid, fieldid, imagedate, (uid + '/ndre.png'), 'ndre')
ndre_scale_url = 'https://farmonaut.com/Images/ndre_scale.jpg'
ndre2_url = upload_file(uid, fieldid, imagedate, (uid + '/ndre_cmap2.png'), 'ndre_cmap2')
ndre_line_url = upload_file(uid, fieldid, imagedate, (uid + '/ndre_linegraph.png'), 'ndre_linegraph')
ndre_pie_url = upload_file(uid, fieldid, imagedate, (uid + '/ndre_piechart.png'), 'ndre_piechart')
ndwi_url = upload_file(uid, fieldid, imagedate, (uid + '/ndwi.png'), 'ndwi')
ndwi_scale_url = 'https://farmonaut.com/Images/ndwi_scale.jpg'
ndwi2_url = upload_file(uid, fieldid, imagedate, (uid + '/ndwi_cmap2.png'), 'ndwi_cmap2')
ndwi_line_url = upload_file(uid, fieldid, imagedate, (uid + '/ndwi_linegraph.png'), 'ndwi_linegraph')
ndwi_pie_url = upload_file(uid, fieldid, imagedate, (uid + '/ndwi_piechart.png'), 'ndwi_piechart')
ndmi_url = upload_file(uid, fieldid, imagedate, (uid + '/ndmi.png'), 'ndmi')
ndmi_scale_url = 'https://farmonaut.com/Images/ndmi_scale.jpg'
ndmi2_url = upload_file(uid, fieldid, imagedate, (uid + '/ndmi_cmap2.png'), 'ndmi_cmap2')
ndmi_line_url = upload_file(uid, fieldid, imagedate, (uid + '/ndmi_linegraph.png'), 'ndmi_linegraph')
ndmi_pie_url = upload_file(uid, fieldid, imagedate, (uid + '/ndmi_piechart.png'), 'ndmi_piechart')
soc_url = upload_file(uid, fieldid, imagedate, (uid + '/soc.png'), 'soc')
soc_scale_url = 'https://farmonaut.com/Images/soc_scale.jpg'
soc2_url = upload_file(uid, fieldid, imagedate, (uid + '/soc_cmap2.png'), 'soc_cmap2')
soc_line_url = upload_file(uid, fieldid, imagedate, (uid + '/soc_linegraph.png'), 'soc_linegraph')
soc_pie_url = upload_file(uid, fieldid, imagedate, (uid + '/soc_piechart.png'), 'soc_piechart')
evapo_url = upload_file(uid, fieldid, imagedate, (uid + '/evapo.png'), 'evapo')
evapo_scale_url = 'https://farmonaut.com/Images/evapo_scale.jpg'
tci_url = upload_file(uid, fieldid, imagedate, (uid + '/TCI.png'), 'tci')
etci_url = upload_file(uid, fieldid, imagedate, (uid + '/ETCI.png'), 'etci')
all_weather_data = get_weather_forecast(field_lat,field_long)
all_days = []
min_temps = []
max_temps = []
rain_probs = []
max_preps = []
cloud_covers = []
final_days = []
weather_infos = []
for (key,val) in all_weather_data.items():
all_days.append(key)
all_days.sort()
all_days = all_days[1:]
for key in all_days:
#print('kk')
#print(key)
single_w_data = all_weather_data[key]
w_date = datetime.datetime.fromtimestamp(int(key))
final_days.append(str(w_date)[0:10])
weather_infos.append(single_w_data["summary"])
cloud_covers.append(str(int(float(single_w_data["cloudcover"])*100)))
try:
temp_min_temp = (str(round(((float(single_w_data["templow"])-32)*(5/9)),2)))
temp_min_temp = temp_min_temp + ((' at '+str(datetime.datetime.fromtimestamp(int(single_w_data["templowtime"])))[11:16]))
min_temps.append(temp_min_temp)
temp_max_temp = (str(round(((float(single_w_data["temphigh"])-32)*(5/9)),2)))
temp_max_temp = temp_max_temp +((' at '+str(datetime.datetime.fromtimestamp(int(single_w_data["temphightime"])))[11:16]))
max_temps.append(temp_max_temp)
except:
min_temps.append('not available')
max_temps.append('not available')
try:
rain_probs.append(str(round((float(single_w_data["preciprob"])*100),2)))
temp_prep = (str((single_w_data["precimax"])))
temp_prep = temp_prep + ((' at '+str(datetime.datetime.fromtimestamp(int(single_w_data["precimaxtime"])))[11:16]))
max_preps.append(temp_prep)
except:
rain_probs.append('not available')
max_preps.append('not available')
#document.add_page_break()
try:
present_ndvi = float(ndvi[imagedate])/100
except:
present_ndvi = 0
try:
present_ndwi = float(ndwi[imagedate])/100
except:
present_ndwi = 0
try:
present_ndre = float(ndre[imagedate])/100
except:
present_ndre = 0
try:
present_savi = float(savi[imagedate])/100
except:
present_savi = 0
try:
present_evi = float(evi[imagedate])/100
except:
present_evi = 0
try:
present_ndmi = float(ndmi[imagedate])/100
except:
present_ndmi = float(0)
try:
present_soc = float(soc[imagedate])/100
except:
present_soc = 0
html_message = """"""
html_message = html_message+ """
"""
html_message = html_message+all_strings[1]+"""
|
|
|
|
"""
html_message = html_message+ all_strings[2]+"""
|
"""
html_message = html_message + str(report_date)+"""
|
|
"""
html_message = html_message+ all_strings[11]+"""
|
"""
html_message = html_message + str(sensed_imagedate)+"""
|
|
|
"""
html_message = html_message+ all_strings[3]+"""
|
|
|
|
|
"""
html_message = html_message + all_strings[4]+"""
|
"""
html_message = html_message + temp_field_address + """
|
|
|
"""
html_message = html_message + all_strings[6]+"""
|
"""
html_message = html_message + str(field_area) + " " + all_strings[7] +"""
|
|
|
"""
html_message = html_message + all_strings[8] + """
|
"""
html_message = html_message + all_strings[9] +" " + str(f_lat) + ", " + all_strings[10] + " " + str(f_long)+ """
|
|
|
"""
html_message = html_message + all_strings[13] +"""
|
|
|
"""
html_message = html_message + all_strings[14] + """
|
"""
html_message = html_message + station + """
|
|
"""
html_message = html_message + all_strings[21] + """
|
"""
html_message = html_message + str(cloud_cover) +"""
|
|
"""
html_message = html_message + all_strings[15] + """
|
"""
html_message = html_message + str(min_temp) + """
|
"""
html_message = html_message + all_strings[16] + """
|
"""
html_message = html_message + str(max_temp) + """
|
|
|
"""
html_message = html_message + all_strings[17]+"""
|
"""
html_message = html_message + str(pressure) +"""
|
|
"""
html_message = html_message + all_strings[18] +"""
|
"""
html_message = html_message + str(humidity) + """
|
|
"""
html_message = html_message + all_strings[19] + """
|
"""
html_message = html_message + str(wind_speed) + """
|
|
"""
html_message = html_message + all_strings[20]+"""
|
"""
html_message = html_message + str(wind_deg) + """
|
|
|
"""
html_message = html_message + all_strings[22] + """
|
"""
html_message = html_message + all_strings[23]+ ": " + station +"""
|
|
|
"""
html_message = html_message + str(final_days[0]) + """
|
"""
html_message = html_message + weather_infos[0] + """
|
|
"""
html_message = html_message + all_strings[15]+"""
|
"""
html_message = html_message + str(min_temps[0]) + """
|
|
"""
html_message = html_message + all_strings[16] + """
|
"""
html_message = html_message + str(max_temps[0]) + """
|
|
"""
html_message = html_message + all_strings[28] + """
|
"""
html_message = html_message + str(rain_probs[0]) + """
|
|
"""
html_message = html_message + all_strings[29] + """
|
"""
html_message = html_message + str(max_preps[0]) + """
|
|
"""
html_message = html_message + all_strings[24] + """
|
|
|
"""
html_message = html_message + str(final_days[1]) + """
|
"""
html_message = html_message + weather_infos[1] + """
|
|
"""
html_message = html_message + all_strings[25]+ """
|
"""
html_message = html_message + str(min_temps[1])+"""
|
|
"""
html_message = html_message + all_strings[16] +"""
|
"""
html_message = html_message + str(max_temps[1]) +"""
|
|
"""
html_message = html_message + all_strings[28] + """
|
"""
html_message = html_message + str(rain_probs[1]) + """
|
|
"""
html_message = html_message + all_strings[29] + """
|
"""
html_message = html_message + str(max_preps[1]) + """
|
|
"""
html_message = html_message + all_strings[24] + """
|
"""
html_message = html_message + str(cloud_covers[1]) + """
|
|
|
"""
html_message = html_message + str(final_days[2]) + """
|
"""
html_message = html_message + weather_infos[2] + """
|
|
"""
html_message = html_message + all_strings[25] + """
|
"""
html_message = html_message + str(min_temps[2]) + """
|
|
"""
html_message = html_message + all_strings[16] + """
|
"""
html_message = html_message + str(max_temps[2])+"""
|
|
"""
html_message = html_message + all_strings[28] + """
|
"""
html_message = html_message + str(rain_probs[2]) + """
|
|
"""
html_message = html_message + all_strings[29] + """
|
"""
html_message = html_message + str(max_preps[2]) + """
|
|
"""
html_message = html_message + all_strings[24] + """
|
"""
html_message = html_message + str(cloud_covers[2]) + """
|
|
|
"""
html_message = html_message + str(final_days[3]) + """
|
"""
html_message = html_message + weather_infos[3] + """
|
|
"""
html_message = html_message + all_strings[25] + """
|
"""
html_message = html_message + str(min_temps[3]) + """
|
|
"""
html_message = html_message + all_strings[26] + """
|
"""
html_message = html_message + str(max_temps[3]) + """
|
|
"""
html_message = html_message + all_strings[28] + """
|
"""
html_message = html_message + str(rain_probs[3]) + """
|
|
"""
html_message = html_message + all_strings[29] + """
|
"""
html_message = html_message + str(max_preps[3]) + """
|
|
"""
html_message = html_message + all_strings[24] + """
|
"""
html_message = html_message + str(cloud_covers[3]) + """
|
|
|
"""
html_message = html_message + str(final_days[4]) + """
|
"""
html_message = html_message + weather_infos[4] + """
|
|
"""
html_message = html_message + all_strings[25] + """
|
"""
html_message = html_message + str(min_temps[4]) + """
|
|
"""
html_message = html_message + all_strings[26] + """
|
"""
html_message = html_message + str(max_temps[4]) + """
|
|
"""
html_message = html_message + all_strings[28] + """
|
"""
html_message = html_message + str(rain_probs[4]) + """
|
|
"""
html_message = html_message + all_strings[29] + """
|
"""
html_message = html_message + str(max_preps[4]) + """
|
|
"""
html_message = html_message + all_strings[24] + """
|
"""
html_message = html_message + str(cloud_covers[4]) + """
|
|
|
"""
html_message = html_message + str(final_days[5]) + """
|
"""
html_message = html_message + weather_infos[5] + """
|
|
"""
html_message = html_message + all_strings[25] + """
|
"""
html_message = html_message + str(min_temps[5]) + """
|
|
"""
html_message = html_message + all_strings[26] + """
|
"""
html_message = html_message + str(max_temps[5]) + """
|
|
"""
html_message = html_message + all_strings[28] + """
|
"""
html_message = html_message + str(rain_probs[5]) + """
|
|
"""
html_message = html_message + all_strings[29] + """
|
"""
html_message = html_message + str(max_preps[5]) + """
|
|
"""
html_message = html_message + all_strings[24] + """
|
"""
html_message = html_message + str(cloud_covers[5]) + """
|
|
|
"""
html_message = html_message + str(final_days[6]) + """
|
"""
html_message = html_message + weather_infos[6] + """
|
|
"""
html_message = html_message + all_strings[25] + """
|
"""
html_message = html_message + str(min_temps[6]) + """
|
|
"""
html_message = html_message + all_strings[26] +"""
|
"""
html_message = html_message + str(max_temps[6]) + """
|
|
"""
html_message = html_message + all_strings[28] +"""
|
"""
html_message = html_message + str(rain_probs[6]) + """
|
|
"""
html_message = html_message + all_strings[29] + """
|
"""
html_message = html_message + str(max_preps[6]) + """
|
|
"""
html_message = html_message + all_strings[24] + """
|
"""
html_message = html_message + str(cloud_covers[6]) + """
|
|
|
"""
if failed == 0:
html_message = html_message + """
"""
html_message = html_message + all_strings[84] + """
|
"""
if present_ndvi <0.3 or present_evi<0.3:
html_message = html_message + all_strings[32]
elif (present_ndvi>=0.3 and present_ndvi<0.55) or (present_evi>=0.3 and present_evi<0.55):
html_message = html_message + all_strings[34]
else:
html_message = html_message + all_strings[36]
html_message = html_message + """
|
|
"""
html_message = html_message + all_strings[85] + """
|
"""
if present_ndwi <0.3:
html_message = html_message + all_strings[38]
elif (present_ndwi>=0.3 and present_ndwi<0.4):
html_message = html_message + all_strings[40]
else:
html_message = html_message + all_strings[42]
html_message = html_message + """
|
|
|
"""
html_message = html_message + all_strings[86] + """
|
|
|
"""
html_message = html_message + all_strings[87] + """
|
|
|
"""
html_message = html_message + """
"""
html_message = html_message + all_strings[102] + """
|
|
|
"""
if failed == 0:
html_message = html_message + """
"""
html_message = html_message + all_strings[88] + """
|
|
|
"""
html_message = html_message + all_strings[48]+"""
|
"""
html_message = html_message + all_strings[89] + """
|
"""
html_message = html_message + all_strings[49] + """
|
|
|
"""
html_message = html_message + all_strings[90] +"""
|
"""
html_message = html_message + all_strings[72] +"""
|
"""
html_message = html_message + all_strings[52] + """
|
|
"""
html_message = html_message + all_strings[91] + """
|
"""
html_message = html_message + all_strings[50] + """
|
|
|
"""
html_message = html_message + all_strings[56] + """
|
|
|
"""
html_message = html_message+ all_strings[90] + """
|
"""
html_message = html_message + all_strings[58] + """
|
"""
html_message = html_message + all_strings[59] +"""
|
|
"""
html_message = html_message + all_strings[91] + """
|
"""
html_message = html_message + all_strings[57]+"""
|
|
|
"""
html_message = html_message + all_strings[92] + """
|
|
|
"""
html_message = html_message + all_strings[90] + """
|
"""
html_message = html_message + all_strings[58] +"""
|
"""
html_message = html_message + all_strings[93]+"""
|
|
"""
html_message = html_message + all_strings[91] +"""
|
"""
html_message = html_message + all_strings[94] + """
|
|
|
"""
html_message = html_message+all_strings[95]+"""
|
|
|
"""
html_message=html_message+all_strings[63]+"""
|
|
|
"""
html_message = html_message+all_strings[90]+"""
|
"""
html_message = html_message+ all_strings[72]+"""
|
"""
html_message = html_message + all_strings[66]+"""
|
|
"""
html_message = html_message +all_strings[91] +"""
|
"""
html_message = html_message + all_strings[64] + """
|
|
|
"""
html_message = html_message + all_strings[97] + """
|
"""
html_message = html_message + all_strings[70] + """
|
|
|
"""
html_message = html_message + all_strings[90] + """
|
"""
html_message = html_message + all_strings[65] + """
|
"""
html_message = html_message + all_strings[73] + """
|
|
"""
html_message = html_message + all_strings[91] + """
|
"""
html_message = html_message + all_strings[71] + """
|
|
|
"""
html_message = html_message + all_strings[98] + """
|
|
|
"""
html_message = html_message + all_strings[90] + """
|
"""
html_message = html_message + all_strings[72] + """
|
"""
html_message = html_message + all_strings[99] + """
|
|
"""
html_message = html_message + all_strings[91] + """
|
"""
html_message = html_message + all_strings[100] + """
|
|
|
"""
html_message = html_message + all_strings[77] + """
|
|
|
|
"""
html_message = html_message + all_strings[78] + """
|
|
|
"""
html_message = html_message + all_strings[101] + """
|
"""
html_message = html_message + all_strings[79] + """
|
|
|
"""
html_message = html_message + all_strings[90] + """
|
|
"""
html_message = html_message + all_strings[91] + """
|
"""
html_message = html_message + all_strings[80] + """
|
|
|
|
"""
else:
html_message = html_message + """"""
html_message = html_message + """
"""
#print(html_message)
field_address = field_address.replace(" ","_")
field_address = field_address.replace(",","_")
pdf_name=uid+'/' + whitelabel + '_report_' + lang +'_'+str(imagedate)+'_'+field_address+'.pdf'
htmlfilename = uid + '/report.html'
destination_blob_name = 'PaidMonitoredFields/'+str(uid)+'/'+str(fieldid)+'/'+str(imagedate)+'/report.html'
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_string(html_message)
blob = bucket.blob(destination_blob_name)
blob.download_to_filename(htmlfilename)
# with codecs.open('marathi.txt', 'w', encoding='utf-8') as file:
# file.write(all_strings[80])
# with codecs.open(htmlfilename, 'w', encoding='utf-8') as file:
# file.write(html_message)
#htmlfile = open((uid + '/report.html'),"w")
#htmlfile.write(html_message)
#htmlfile.close()
with Display():
pdfkit.from_url((uid + '/report.html'),pdf_name)
#compress(pdf_name,pdf_name)
def try_index(health, index):
new_index = {}
try:
new_index = health[index]
except:
new_index = {}
return new_index