Skip to content

Commit

Permalink
update prod
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-yz committed Feb 9, 2024
1 parent 2b26c64 commit f1b9685
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
8 changes: 4 additions & 4 deletions assets/simplebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def lambda_handler(event, context):
event_hash = generate_event_hash(result)
if not result.done and not event_exists(event_hash):
counter += 1
send_message(chat_id, str(result), BASE_URL)
send_photo(chat_id, result.image, BASE_URL, str(result))
store_event(event_hash)
logger.info(f"Stored {result.title}")

Expand All @@ -55,7 +55,7 @@ def lambda_handler(event, context):
elif message == "/scrape all":
response = scrape_webpage()
for result in response:
send_message(chat_id, str(result), BASE_URL)
send_photo(chat_id, result.image, BASE_URL, str(result))
response = f"Sent {len(response)} events!"
send_message(chat_id, response, BASE_URL)
logger.info(response)
Expand All @@ -76,8 +76,8 @@ def lambda_handler(event, context):
elif message == "/testPhoto":
event_image = "https://eventro.ir/images/events/poster/44543.jpg"
response = "🎵🎶📣🎯\n" \
"📅 23 بهمن 1402\n" \
"<a href='https://eventro.ir/events/44543'>🎟️ منبع و خرید بلیت</a>"
"📅 23 بهمن 1402 \n" \
"<a href='https://eventro.ir/events/44543'>🎟️ منبع و خرید بلیت</a> \n"
send_photo(chat_id, event_image, BASE_URL, response)
logger.info(response)
else:
Expand Down
14 changes: 10 additions & 4 deletions assets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ class Event(BaseModel):
image: str
date_iran: str
date_world: str
code: str
image_poster_url: str
done: bool

def __str__(self):
return f"<a href='{self.title_link}'>{self.title}</a>\n" \
f"{self.date_iran}\n" \
f"{self.date_world}"
return f"📣 {self.title}\n " \
f"📅 {self.date_iran} \n " \
f"<a href='https://eventro.ir/events/{self.code}'>🎟️ منبع و خرید بلیت</a> \n"


def scrape_webpage():
Expand All @@ -47,6 +49,9 @@ def scrape_webpage():
.find('span', 'dt1').text
date_iran = date.strip().split('\n')[0].strip()
date_world = date.strip().split('\n')[-1].strip()
code = title_link.split('/')[-1]
image_poster_url = f"https://eventro.ir/images/events/poster/{code}.jpg"

done = False
for detail in event.find('div', class_='allmode_text') \
.find_all('div', class_='event_detail'):
Expand All @@ -57,7 +62,8 @@ def scrape_webpage():
done = True

result = Event(title=title, title_link=title_link, image=image,
date_iran=date_iran, date_world=date_world, done=done)
date_iran=date_iran, date_world=date_world,
code=code, image_poster_url=image_poster_url, done=done)
results.append(result)

logger.info(results)
Expand Down

0 comments on commit f1b9685

Please sign in to comment.