This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import packages and functions from local scripts | |
import pickle | |
from scraping import run_search, get_attributes, get_days | |
from mailer import generate_markup, send_email | |
# Constant variables | |
SEARCH_URL = "https://poshmark.com/brand/Naked_&_Famous_Denim-Men-Jeans?sort_by=added_desc" | |
DAYS = 4 | |
USER_EMAIL = "PERSONAL_ACCOUNT@gmail.com" | |
SENDER_EMAIL = "DUMMY_ACCOUNT@gmail.com" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def send_email(items, recipient): | |
sender_email = "DUMMY_ACCOUNT@gmail.com" | |
receiver_email = recipient | |
password = "DUMMY_ACCOUNT_PASSWORD" | |
message = MIMEMultipart("alternative") | |
message["Subject"] = "Latest Poshmark Listings" | |
message["From"] = sender_email | |
message["To"] = receiver_email |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from html2text import html2text | |
import smtplib, ssl | |
from email.mime.text import MIMEText | |
from email.mime.multipart import MIMEMultipart | |
USER_EMAIL = "PERSONAL_ACCOUNT@gmail.com" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
def generate_markup(title, collection): | |
html = "<div style='text-align: center;'>" | |
heading = f'<p style="font-size: 1.5rem; font-weight: bold;">{title} <span style="font-size: 1rem;">({len(collection)} items)</span></p>' | |
item_group = "" | |
for item in collection: | |
title = item[0] | |
price = item[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pickle.dump(recent_items, open("naked_and_famous.p", "wb")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<div style="margin: 0 auto;"> | |
<!-- Heading --> | |
<div> | |
<h1 style="text-align: center;">New Poshmark Listings</h1> | |
<hr> | |
</div> | |
<br> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
recent_items = [] | |
for card in product_cards: | |
difference = get_days(card) | |
if difference <= DAYS: | |
card_values = get_attributes(card) | |
recent_items.append(card_values) | |
else: | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_days(soup_obj): | |
"Convert to EST and return difference in days" | |
created_date = soup_obj['data-created-at'] | |
pst_date = parse(created_date, ignoretz=True) | |
est_date = pst_date + timedelta(hours=3) | |
now = datetime.now() | |
diff = abs((est_date-now).days) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_attributes(soup_obj): | |
"Extract product values from card" | |
price = soup_obj['data-post-price'] | |
url_tag = soup_obj.a | |
url = "https://poshmark.com" + url_tag['href'] | |
title = url_tag['title'] | |
img_tag = url_tag.img | |
img = img_tag['src'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def run_search(search_url): | |
"Pull down search results and extract out product cards" | |
response = get(search_url, headers=HEADER) | |
html_soup = BeautifulSoup(response.text, 'html.parser') | |
item_container = html_soup.find_all('div', class_ = 'tile') | |
return item_container | |
product_cards = run_search(SEARCH_URL) | |
print(product_cards) |
NewerOlder