import arcgis import os import re from arcgis.gis import GIS # Constantes SURVEY_ID = "19c53fb2f2f04c8eb551be3fd4b89d1a" FOLDER_TITLE = "RELATÓRIOS ITBI" def connect_to_gis(): return GIS("home") def get_folder(gis, title): for folder in gis.users.me.folders: if folder['title'] == title: return folder return gis.content.create_folder(title) def get_survey(gis, survey_id): survey_manager = arcgis.apps.survey123.SurveyManager(gis) return survey_manager.get(survey_id) def get_related_item(gis): survey_by_id = gis.content.get(SURVEY_ID) return survey_by_id.related_items('Survey2Service','forward')[0] def get_template_index(templates, template_name): for i, template in enumerate(templates): if template.title == template_name: return i return None def get_feature_layer(rel_item, gis): rel_fs = arcgis.features.FeatureLayer(rel_item.url, gis) rel_fs_collection = arcgis.features.FeatureLayerCollection(rel_item.url, gis) layer_index = 0 # substitua por seu índice de camada return rel_fs_collection.layers[layer_index] def generate_report(survey, objectid, titulo, pasta_itbi, template_index): templates = survey.report_templates pdf_report = survey.generate_report(templates[template_index], where=f"objectid={objectid}",report_title=titulo,folder_id=pasta_itbi['id'], output_format="pdf") arcpy.AddMessage(pdf_report) print(f"Single report as PDF: ", pdf_report) def main(): arcpy.AddMessage("Iniciando a execução...") gis = connect_to_gis() processo = arcpy.GetParameterAsText(0) pasta_itbi = get_folder(gis, FOLDER_TITLE) survey = get_survey(gis, SURVEY_ID) rel_item = get_related_item(gis) rel_fs_layer = get_feature_layer(rel_item, gis) titulo = f"Avalia_Imovel_ITBI_Processo:" + processo arcpy.AddMessage(titulo) query_result = rel_fs_layer.query(where=f"processo = '{processo}'") if query_result.features: objectid = max([feature.attributes['objectid'] for feature in query_result.features]) # Obter o índice do template template_name = "ITBI" template_index = get_template_index(survey.report_templates, template_name) if template_index is not None: generate_report(survey, objectid, titulo, pasta_itbi, template_index) else: print(f"Não foi encontrado um template com o nome '{template_name}'") else: print("Nenhum registro encontrado para o processo informado.") arcpy.AddMessage("Execução concluída.") if __name__ == "__main__": main()