-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsneakers.py
47 lines (40 loc) · 1.61 KB
/
sneakers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import requests
import discord
import os
from bs4 import BeautifulSoup
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')
source = requests.get('https://sneakernews.com/release-dates/').text
soup = BeautifulSoup(source, 'lxml')
release_section = soup.find('div', {'class': 'sneaker-con-main'})
releases = release_section.findAll('div', {'class': 'releases-box'})
cleaned_releases = []
for release in releases:
image = release.find('img', {'alt': 'Release page image'})
h2 = release.find('h2')
if not image:
continue
cleaned_releases.append({
'page': h2.find('a')['href'],
'image_url': image['src'],
'release_date': release.find('span', {'class': 'release-date'}).text.strip() or 'n/a',
'name': h2.text.strip(),
'price': release.find('span', {'class': 'release-price'}).text.strip(),
'color': release.find('div', {'class': 'post-data'}).findAll('p')[1].text.strip().split(':')[1]
})
client = discord.Client()
@client.event
async def on_ready():
guild = discord.utils.get(client.guilds, name=GUILD)
print(f'{client.user} is connected to Discord')
@client.event
async def on_message(message):
for shoe in cleaned_releases:
if message.content == 'lil sneaker bby':
embed = discord.Embed(title=shoe['name'], description=shoe['color'], url=shoe['page'])
embed.set_image(url=shoe['image_url'])
embed.set_footer(text='Releases on ' + shoe['release_date'] + ' for ' + shoe['price'])
await message.channel.send(embed=embed)
client.run(TOKEN)