Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -3,8 +3,6 @@
|
|
| 3 |
import io
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
-
import pyimgur
|
| 7 |
-
|
| 8 |
import os
|
| 9 |
import tempfile
|
| 10 |
import logging
|
|
@@ -55,27 +53,6 @@ app = Flask(__name__)
|
|
| 55 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 56 |
app.logger.setLevel(logging.INFO)
|
| 57 |
|
| 58 |
-
# === 初始化並測試pyimgur ===
|
| 59 |
-
|
| 60 |
-
IMGUR_CLIENT_ID = os.environ.get("IMGUR_CLIENT_ID")
|
| 61 |
-
im = pyimgur.Imgur(IMGUR_CLIENT_ID)
|
| 62 |
-
'''
|
| 63 |
-
test_image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
|
| 64 |
-
|
| 65 |
-
try:
|
| 66 |
-
uploaded_image = im.upload_image(test_image_url, title="Uploaded with PyImgur")
|
| 67 |
-
app.logger.info(uploaded_image.title)
|
| 68 |
-
app.logger.info(uploaded_image.link)
|
| 69 |
-
app.logger.info(uploaded_image.type)
|
| 70 |
-
app.logger.info(uploaded_image.type)
|
| 71 |
-
except FileNotFoundError:
|
| 72 |
-
app.logger.info("Error: test.png not found. Please ensure the image file exists in the current directory or provide the correct path.")
|
| 73 |
-
except Exception as e:
|
| 74 |
-
app.logger.info(f"An error occurred: {e}")
|
| 75 |
-
'''
|
| 76 |
-
|
| 77 |
-
# === 測試結束 ===
|
| 78 |
-
|
| 79 |
channel_secret = os.environ.get("YOUR_CHANNEL_SECRET")
|
| 80 |
channel_access_token = os.environ.get("YOUR_CHANNEL_ACCESS_TOKEN")
|
| 81 |
|
|
@@ -213,17 +190,6 @@ def handle_image_message(event):
|
|
| 213 |
app.logger.info(response.output_text)
|
| 214 |
'''
|
| 215 |
|
| 216 |
-
try:
|
| 217 |
-
uploaded_image = im.upload_image(f"/tmp/{filename}", title="Uploaded with PyImgur")
|
| 218 |
-
app.logger.info(uploaded_image.title)
|
| 219 |
-
app.logger.info(uploaded_image.link)
|
| 220 |
-
app.logger.info(uploaded_image.type)
|
| 221 |
-
app.logger.info(uploaded_image.type)
|
| 222 |
-
except FileNotFoundError:
|
| 223 |
-
app.logger.info("Error: File not found. Please ensure the image file exists in the current directory or provide the correct path.")
|
| 224 |
-
except Exception as e:
|
| 225 |
-
app.logger.info(f"An error occurred: {e}")
|
| 226 |
-
|
| 227 |
with ApiClient(configuration) as api_client:
|
| 228 |
line_bot_api = MessagingApi(api_client)
|
| 229 |
line_bot_api.reply_message(
|
|
|
|
| 3 |
import io
|
| 4 |
from PIL import Image
|
| 5 |
|
|
|
|
|
|
|
| 6 |
import os
|
| 7 |
import tempfile
|
| 8 |
import logging
|
|
|
|
| 53 |
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
|
| 54 |
app.logger.setLevel(logging.INFO)
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
channel_secret = os.environ.get("YOUR_CHANNEL_SECRET")
|
| 57 |
channel_access_token = os.environ.get("YOUR_CHANNEL_ACCESS_TOKEN")
|
| 58 |
|
|
|
|
| 190 |
app.logger.info(response.output_text)
|
| 191 |
'''
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
with ApiClient(configuration) as api_client:
|
| 194 |
line_bot_api = MessagingApi(api_client)
|
| 195 |
line_bot_api.reply_message(
|