Skip to content

Commit

Permalink
Refactor file path and handle exceptions when reading from posted_job…
Browse files Browse the repository at this point in the history
…s.txt
  • Loading branch information
Intina47 authored Mar 26, 2024
1 parent adb78f3 commit cc94d07
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions bot_components/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ async def scrape_and_post_to_discord(self, channel):
jobs_json = json.load(f)

embeds = []
if not os.path.exists('posted_jobs.txt'):
open('posted_jobs.txt', 'w').close()
posted_jobs_file_path = '/app/config/posted_jobs.txt'
if not os.path.exists(posted_jobs_file_path):
open(posted_jobs_file_path, 'w').close()
try:
with open('posted_jobs.txt', 'r') as f:
with open( posted_jobs_file_path, 'r') as f:
posted_jobs = [line.strip() for line in f]
except Exception as e:
print(f"Failed to read from posted_jobs.txt: {str(e)}")
Expand All @@ -86,7 +87,7 @@ async def scrape_and_post_to_discord(self, channel):
if job_id in posted_jobs:
continue
else:
with open('posted_jobs.txt', 'a') as f:
with open(posted_jobs_file_path, 'a') as f:
f.write(f"{job_id}\n")
embed = discord.Embed(
title=job['title'],
Expand Down

0 comments on commit cc94d07

Please sign in to comment.