Exemplo n.º 1
0
    def post(self, user_id):
        request_body = EmailAddApi.parser.parse_args()
        email = Email(mail=request_body['mail'], user_id=user_id)

        try:
            email.save()
        except:
            return {
                "message": "An error occurred while inserting the email."
            }, 400
        return email.json(), 201
Exemplo n.º 2
0
def poll_for_new_listings_and_email_report():

    # scrape
    apartments = get_listings_scrape()

    # TODO: MOVE A LOT OF THIS LOGIC TO A CONTROLLER

    # gather apartment data as dictionaries
    polled_apt_data = []
    for apt in apartments:
        polled_apt_data.append(apt.__dict__)

    # compare to daily saved data and gather new listings
    new_listings = []
    daily_listings = None
    with open('data/daily_apartments.json') as apt_file:
        daily_listings = json.load(apt_file)

    for listing in polled_apt_data:
        if listing not in daily_listings:
            new_listings.append(listing)

    if len(new_listings) > 0:

        # add any new listings in daily data file
        daily_listings = daily_listings + new_listings
        with open('data/daily_apartments.json', 'w') as apt_file:
            json.dump(daily_listings, apt_file, indent=4)

        # get new listings instances
        new_listings_instances = []
        for listing_dict in new_listings:
            new_listings_instances.append(
                AptListing(property_location=listing_dict['property_location'],
                           baths=listing_dict['baths'],
                           beds=listing_dict['beds'],
                           rent=listing_dict['rent'],
                           square_feet=listing_dict['square_feet'],
                           amenities_display=listing_dict['amenities_display'],
                           available_date=listing_dict['available_date'],
                           apply_link=listing_dict['apply_link']))

        # send urgent email with new listings
        email_body = '\n\n'.join(
            [apt.get_formatted_string() for apt in new_listings_instances])

        email = Email(recipients=config.recipients,
                      subject='URGENT: New Essex Listings Available!',
                      body=email_body)
        email.send()

    else:
        print 'No new listings found...'
Exemplo n.º 3
0
    def put(self, email_id):
        request_body = EmailAddApi.parser.parse_args()
        email = Email.get_by_id(email_id)

        if email is None:
            return {'mail': request_body['mail']}
        else:
            email.mail = request_body['mail']
            email.save()

        return email.json()
Exemplo n.º 4
0
    def __init__(self, lastName, firstName, emails, phone_numbers):
        self.lastName = lastName
        self.firstName = firstName

        for email in list(emails):
            email = json.loads(email.replace("\'", "\""))
            self.emails.append(Email(email['mail'], self.id))

        for phone in list(phone_numbers):
            phone = json.loads(phone.replace("\'", "\""))
            self.phones.append(Phone(phone['number'], self.id))
Exemplo n.º 5
0
def scrape_and_email_report():

    # scrape
    apartments = get_listings_scrape()

    # gather apartment data as dictionaries
    apt_data = []
    for apt in apartments:
        apt_data.append(apt.__dict__)

    # save to daily data file
    with open('data/daily_apartments.json', 'w') as apt_file:
        json.dump(apt_data, apt_file, indent=4)

    # construct and send email
    email_body = '\n\n'.join(
        [apt.get_formatted_string() for apt in apartments])

    email = Email(recipients=config.recipients,
                  subject='Essex Apartment Report',
                  body=email_body)
    email.send()
Exemplo n.º 6
0
def create_email(content, status=EmailStatus.ERROR, time=datetime.utcnow()):
    email_failed = Email()
    email_failed.content = content
    email_failed.status = status
    email_failed.datetime = time
    return email_failed
Exemplo n.º 7
0
import config
from controllers.scraper import Scraper
from models.email import Email


# collect all apartment instances
apartments = []
for property_location, property_code in config.essex_properties.iteritems():

# get apartment instances
new_apts = Scraper.essex_listings_scrape(
    date='5-15-2017',
    appartment_criteria=config.appartment_criteria,
    property_location=property_location,
    property_code=property_code
)

apartments = apartments + new_apts


# construct and send email
email_body = '\n\n'.join([apt.get_formatted_string() for apt in apartments])

email = Email(
recipients=config.recipients,
subject='Essex Apartment Report',
body=email_body
)
email.send()