Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,8 @@ from slack_sdk.errors import SlackApiError
|
|
| 8 |
import aiojobs
|
| 9 |
import asyncio
|
| 10 |
from datetime import datetime, timedelta
|
| 11 |
-
from apscheduler.
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
DISCORD_TOKEN = os.getenv('DISCORD_TOKEN')
|
|
@@ -147,13 +148,21 @@ def post_to_slack_create_thread(channel, text, thread_ts=None):
|
|
| 147 |
|
| 148 |
#----------------------------------------------------------------------------------------------
|
| 149 |
|
| 150 |
-
|
| 151 |
global daily_pings
|
| 152 |
if daily_pings:
|
| 153 |
print("sending daily pings...")
|
| 154 |
# combine into one message
|
| 155 |
combined_message = '\n'.join(f"{ping['author']} in #{ping['channel']} said: {ping['content']} (link: {ping['url']})" for ping in daily_pings)
|
| 156 |
-
await post_to_slack(None, combined_message, SLACK_CHANNEL_ID_TEST, None, None, None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
daily_pings = [] # reset after posting
|
| 158 |
|
| 159 |
# pings -------------------------------------------------------------------------------------------
|
|
@@ -168,8 +177,9 @@ async def post_to_slack(author, content, channel, url, slack_mention, trigger):
|
|
| 168 |
print(f"Error posting to Slack: {e.response['error']}")
|
| 169 |
|
| 170 |
|
| 171 |
-
|
| 172 |
-
scheduler
|
|
|
|
| 173 |
scheduler.start()
|
| 174 |
|
| 175 |
|
|
|
|
| 8 |
import aiojobs
|
| 9 |
import asyncio
|
| 10 |
from datetime import datetime, timedelta
|
| 11 |
+
from apscheduler.executors.pool import ThreadPoolExecutor
|
| 12 |
+
from apscheduler.schedulers.background import BackgroundScheduler
|
| 13 |
|
| 14 |
|
| 15 |
DISCORD_TOKEN = os.getenv('DISCORD_TOKEN')
|
|
|
|
| 148 |
|
| 149 |
#----------------------------------------------------------------------------------------------
|
| 150 |
|
| 151 |
+
def send_daily_pings():
|
| 152 |
global daily_pings
|
| 153 |
if daily_pings:
|
| 154 |
print("sending daily pings...")
|
| 155 |
# combine into one message
|
| 156 |
combined_message = '\n'.join(f"{ping['author']} in #{ping['channel']} said: {ping['content']} (link: {ping['url']})" for ping in daily_pings)
|
| 157 |
+
#await post_to_slack(None, combined_message, SLACK_CHANNEL_ID_TEST, None, None, None)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
response = slack_client.chat_postMessage(
|
| 161 |
+
channel=SLACK_CHANNEL_ID_TEST,
|
| 162 |
+
text=combined_message
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
|
| 166 |
daily_pings = [] # reset after posting
|
| 167 |
|
| 168 |
# pings -------------------------------------------------------------------------------------------
|
|
|
|
| 177 |
print(f"Error posting to Slack: {e.response['error']}")
|
| 178 |
|
| 179 |
|
| 180 |
+
executor = ThreadPoolExecutor(max_workers=1)
|
| 181 |
+
scheduler = BackgroundScheduler(executors={'default': executor})
|
| 182 |
+
scheduler.add_job(send_daily_pings, trigger='interval', seconds=10)
|
| 183 |
scheduler.start()
|
| 184 |
|
| 185 |
|