9
9
import requests
10
10
import os
11
11
import sqlite3
12
- import logging
13
12
14
13
# Build paths inside the project like this: BASE_DIR / 'subdir'.
15
14
BASE_DIR = Path (__file__ ).resolve ().parent .parent
23
22
24
23
DATABASE_FILE = os .path .join (DATABASE_DIR , "group_data.db" )
25
24
26
- # Get an instance of the logger
27
- logger = logging .getLogger (__name__ )
28
-
29
25
30
26
# Load group chat ID from the database
31
27
def load_group_chat_id ():
@@ -104,9 +100,9 @@ def edit_post(request, post_id):
104
100
f"Neuer Post: { post .content } "
105
101
)
106
102
107
- # Debugging: logger.info available threads
108
- logger . info ("Available THREADS in TOPICS:" , TOPICS ) # Debugging
109
- logger . info ("Post Topic ID:" , post .topic_id ) # Debugging
103
+ # Debugging: print available threads
104
+ print ("Available THREADS in TOPICS:" , TOPICS ) # Debugging
105
+ print ("Post Topic ID:" , post .topic_id ) # Debugging
110
106
111
107
# Retrieve the thread information by matching the topic_id
112
108
thread_info = next (
@@ -130,7 +126,7 @@ def edit_post(request, post_id):
130
126
image_path = image_path ,
131
127
)
132
128
else :
133
- logger . info ("Thread information not found in TOPICS based on topic_id." )
129
+ print ("Thread information not found in TOPICS based on topic_id." )
134
130
135
131
messages .success (request , "Post updated and sent to Telegram!" )
136
132
return redirect ("index" )
@@ -148,6 +144,10 @@ def delete_post(request, post_id):
148
144
post = get_object_or_404 (Post , id = post_id )
149
145
post .delete () # Delete the post from the database
150
146
messages .success (request , "Post deleted successfully!" )
147
+
148
+ # Log successful deletion
149
+ print (f"Post with ID { post_id } has been deleted." )
150
+
151
151
return redirect (
152
152
"index"
153
153
) # Redirect back to the post listing or wherever appropriate
@@ -165,12 +165,10 @@ def create_post(request):
165
165
) # Check for 'True' to confirm pin status
166
166
167
167
# Debugging statement
168
- logger .info ("Create Post - Content:" , content )
169
- logger .info ("Create Post - Image:" , image )
170
- logger .info (
171
- "Create Post - Pinned Status:" , pinned
172
- ) # Debugging the pinned status
173
- logger .info ("Create Post - Selected Thread:" , selected_thread )
168
+ print ("Create Post - Content:" , content )
169
+ print ("Create Post - Image:" , image )
170
+ print ("Create Post - Pinned Status:" , pinned ) # Debugging the pinned status
171
+ print ("Create Post - Selected Thread:" , selected_thread )
174
172
175
173
# Get the thread information from the configuration
176
174
thread_info = TOPICS .get (selected_thread )
@@ -228,7 +226,7 @@ def send_to_telegram(
228
226
229
227
if response_photo .status_code == 200 :
230
228
message_id = result_photo ["result" ]["message_id" ]
231
- logger . info ("Photo sent successfully, message ID:" , message_id )
229
+ print ("Photo sent successfully, message ID:" , message_id )
232
230
233
231
# Pin the message only if pinned is True
234
232
if pinned :
@@ -242,23 +240,23 @@ def send_to_telegram(
242
240
pin_result = pin_response .json ()
243
241
244
242
# Debugging output for pinning response
245
- logger . info (
243
+ print (
246
244
f"Attempting to pin message ID { message_id } in chat { chat_id } ."
247
245
)
248
- logger . info ("Pin Data:" , data_pin )
249
- logger . info (
246
+ print ("Pin Data:" , data_pin )
247
+ print (
250
248
"Pin Response:" , pin_result
251
249
) # Log the pinning response # Log the pinning response
252
250
253
251
if pin_response .status_code != 200 :
254
- logger . info (
252
+ print (
255
253
f"Error pinning message (status code { pin_response .status_code } ):" ,
256
254
pin_result ,
257
255
)
258
256
else :
259
- logger . info ("Message pinned successfully." )
257
+ print ("Message pinned successfully." )
260
258
else :
261
- logger . info ("Error sending photo:" , result_photo )
259
+ print ("Error sending photo:" , result_photo )
262
260
263
261
else :
264
262
# Send the message
@@ -274,7 +272,7 @@ def send_to_telegram(
274
272
275
273
if response_send .status_code == 200 :
276
274
message_id = result_send ["result" ]["message_id" ]
277
- logger . info ("Message sent successfully, message ID:" , message_id )
275
+ print ("Message sent successfully, message ID:" , message_id )
278
276
279
277
# Pin the message only if pinned is True
280
278
if pinned :
@@ -290,16 +288,16 @@ def send_to_telegram(
290
288
pin_result = pin_response .json ()
291
289
292
290
# Debugging output for pinning response
293
- logger . info ("Pin Response:" , pin_result ) # Log the pinning response
291
+ print ("Pin Response:" , pin_result ) # Log the pinning response
294
292
295
293
if pin_response .status_code != 200 :
296
- logger . info (
294
+ print (
297
295
f"Error pinning message (status code { pin_response .status_code } ):" ,
298
296
pin_result ,
299
297
)
300
298
else :
301
- logger . info ("Message pinned successfully." )
299
+ print ("Message pinned successfully." )
302
300
else :
303
- logger . info (
301
+ print (
304
302
"Error sending message:" , result_send
305
303
) # Print error if sending message failed
0 commit comments