from flask import Flask, request, jsonify import pytesseract from google.oauth2 import service_account from googleapiclient.discovery import build from googleapiclient.errors import HttpError app = Flask(__name__) # Google App Script API credentials SCOPES = ['https://www.googleapis.com/auth/script.projects'] SERVICE_ACCOUNT_FILE = 'service_account.json' # Load credentials from service account file creds = service_account.Credentials.from_service_account_file( SERVICE_ACCOUNT_FILE, SCOPES) # Create Google App Script API client script_service = build('script', 'v1', credentials=creds) @app.route('/ocr', methods=['POST']) def ocr(): # Get image from request img = request.get_json()['image'] # Perform OCR using Tesseract text = pytesseract.image_to_string(img) # Log OCR result print(f'OCR result: {text}') # Insert OCR result into Google Chat insert_into_google_chat(text) return jsonify({'message': 'OCR successful'}) def insert_into_google_chat(text): # Create Google Chat message message = { 'text': f'////////⭐️⭐️⭐️⭐️ Bot_gas_main_dev 個人情報の確認 {text}' } # Insert message into Google Chat try: script_service.scripts().run(body={'function': 'insertMessage', 'parameters': [message]}).execute() except HttpError as e: print(f'Error inserting message into Google Chat: {e}') if __name__ == '__main__': app.run(debug=True)