Spaces:
Sleeping
Sleeping
removed discord
Browse files- config.py +0 -5
- linkedin_api.py +0 -4
- utils.py +0 -36
config.py
CHANGED
|
@@ -21,7 +21,6 @@ class Config:
|
|
| 21 |
self.token = os.getenv("token", "").strip()
|
| 22 |
self.post_api_url = os.getenv("postApiUrl", "").strip()
|
| 23 |
self.service_trigger = os.getenv("ServiceTrigger", "").strip()
|
| 24 |
-
self.discord_webhook_url = os.getenv("DISCORD_WEBHOOK_URL", "").strip()
|
| 25 |
|
| 26 |
# Validate environment variables on startup
|
| 27 |
self._validate_config()
|
|
@@ -52,10 +51,6 @@ class Config:
|
|
| 52 |
def get_missing_vars(self):
|
| 53 |
"""Return list of missing configuration variables"""
|
| 54 |
return self._validate_config()
|
| 55 |
-
|
| 56 |
-
def is_discord_configured(self):
|
| 57 |
-
"""Check if Discord webhook is configured"""
|
| 58 |
-
return bool(self.discord_webhook_url)
|
| 59 |
|
| 60 |
# Create global config instance
|
| 61 |
config = Config()
|
|
|
|
| 21 |
self.token = os.getenv("token", "").strip()
|
| 22 |
self.post_api_url = os.getenv("postApiUrl", "").strip()
|
| 23 |
self.service_trigger = os.getenv("ServiceTrigger", "").strip()
|
|
|
|
| 24 |
|
| 25 |
# Validate environment variables on startup
|
| 26 |
self._validate_config()
|
|
|
|
| 51 |
def get_missing_vars(self):
|
| 52 |
"""Return list of missing configuration variables"""
|
| 53 |
return self._validate_config()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
# Create global config instance
|
| 56 |
config = Config()
|
linkedin_api.py
CHANGED
|
@@ -3,7 +3,6 @@ import time
|
|
| 3 |
import logging
|
| 4 |
import gradio as gr
|
| 5 |
from config import config
|
| 6 |
-
from utils import notify_discord
|
| 7 |
|
| 8 |
logger = logging.getLogger(__name__)
|
| 9 |
|
|
@@ -137,19 +136,16 @@ def post_to_linkedin(name, job_post):
|
|
| 137 |
logger.info(f"Post URL retrieved: {post_url}")
|
| 138 |
print(f"Post URL: {post_url}")
|
| 139 |
|
| 140 |
-
notify_discord(name, job_post, post_url)
|
| 141 |
|
| 142 |
yield "β
Post published successfully!", gr.update(value=f"### π [Click here to view your post on LinkedIn β]({post_url})", visible=True)
|
| 143 |
return
|
| 144 |
|
| 145 |
# Fallback if URL retrieval fails
|
| 146 |
logger.warning("Could not retrieve post URL, using fallback")
|
| 147 |
-
notify_discord(name, job_post, "https://www.linkedin.com/company/109539782/posts/")
|
| 148 |
yield "β
Post published! (Could not auto-retrieve post link. Please check the LinkedIn page.)", gr.update(visible=False)
|
| 149 |
|
| 150 |
except Exception as fetch_error:
|
| 151 |
logger.error(f"Error fetching post: {fetch_error}")
|
| 152 |
-
notify_discord(name, job_post, "https://www.linkedin.com/company/109539782/posts/")
|
| 153 |
yield f"β
Post published! (Error retrieving link: {fetch_error})", gr.update(visible=False)
|
| 154 |
|
| 155 |
else:
|
|
|
|
| 3 |
import logging
|
| 4 |
import gradio as gr
|
| 5 |
from config import config
|
|
|
|
| 6 |
|
| 7 |
logger = logging.getLogger(__name__)
|
| 8 |
|
|
|
|
| 136 |
logger.info(f"Post URL retrieved: {post_url}")
|
| 137 |
print(f"Post URL: {post_url}")
|
| 138 |
|
|
|
|
| 139 |
|
| 140 |
yield "β
Post published successfully!", gr.update(value=f"### π [Click here to view your post on LinkedIn β]({post_url})", visible=True)
|
| 141 |
return
|
| 142 |
|
| 143 |
# Fallback if URL retrieval fails
|
| 144 |
logger.warning("Could not retrieve post URL, using fallback")
|
|
|
|
| 145 |
yield "β
Post published! (Could not auto-retrieve post link. Please check the LinkedIn page.)", gr.update(visible=False)
|
| 146 |
|
| 147 |
except Exception as fetch_error:
|
| 148 |
logger.error(f"Error fetching post: {fetch_error}")
|
|
|
|
| 149 |
yield f"β
Post published! (Error retrieving link: {fetch_error})", gr.update(visible=False)
|
| 150 |
|
| 151 |
else:
|
utils.py
CHANGED
|
@@ -4,42 +4,6 @@ from config import config
|
|
| 4 |
|
| 5 |
logger = logging.getLogger(__name__)
|
| 6 |
|
| 7 |
-
def notify_discord(name, job_post, post_url):
|
| 8 |
-
"""
|
| 9 |
-
Send notification to Discord webhook about new job post
|
| 10 |
-
|
| 11 |
-
Args:
|
| 12 |
-
name (str): Name of the person posting
|
| 13 |
-
job_post (str): Content of the job post
|
| 14 |
-
post_url (str): URL to the LinkedIn post
|
| 15 |
-
"""
|
| 16 |
-
if not config.is_discord_configured():
|
| 17 |
-
logger.warning("DISCORD_WEBHOOK_URL is not set. Skipping Discord notification.")
|
| 18 |
-
return
|
| 19 |
-
|
| 20 |
-
discord_message = {
|
| 21 |
-
"content": "β¨ New Job Posted! β¨",
|
| 22 |
-
"embeds": [
|
| 23 |
-
{
|
| 24 |
-
"title": f"Job Post by {name}",
|
| 25 |
-
"description": job_post[:2048] + ('...' if len(job_post) > 2048 else ''),
|
| 26 |
-
"url": post_url,
|
| 27 |
-
"color": 16744704 # Orange color code
|
| 28 |
-
}
|
| 29 |
-
]
|
| 30 |
-
}
|
| 31 |
-
|
| 32 |
-
try:
|
| 33 |
-
logger.info(f"Sending Discord notification for post by {name}")
|
| 34 |
-
response = requests.post(config.discord_webhook_url, json=discord_message, timeout=10)
|
| 35 |
-
|
| 36 |
-
if response.status_code == 204:
|
| 37 |
-
logger.info("Discord notification sent successfully")
|
| 38 |
-
else:
|
| 39 |
-
logger.warning(f"Discord notification failed with status {response.status_code}")
|
| 40 |
-
except Exception as e:
|
| 41 |
-
logger.error(f"Error sending Discord notification: {e}")
|
| 42 |
-
|
| 43 |
|
| 44 |
def check_website_status():
|
| 45 |
"""
|
|
|
|
| 4 |
|
| 5 |
logger = logging.getLogger(__name__)
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def check_website_status():
|
| 9 |
"""
|