Skip to content

Commit

Permalink
Add ability to specify single date or range of dates for scrape.py, d…
Browse files Browse the repository at this point in the history
…elete_dates.py and initialize.py.
  • Loading branch information
ThomasThoren committed Oct 28, 2015
1 parent 8513db4 commit 25da970
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 42 deletions.
28 changes: 19 additions & 9 deletions realestate/lib/delete_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,28 @@ def delete_cleaned(self):
session.close()

if __name__ == '__main__':
if len(sys.argv) == 2:
date = sys.argv[1]
if len(sys.argv) < 2:
print (
"No date(s) specified. Enter a single date to delete that " +
"one day or enter two days to delete a range of days. " +
"Use the format 'YYYY-MM-DD'.")
elif len(sys.argv) == 2: # One argument
day = sys.argv[1]

DeleteDates(
initial_date=date,
until_date=date
initial_date=day,
until_date=day
).main()
else:
initial_date = sys.argv[1]
until_date = sys.argv[2]
elif len(sys.argv) == 3: # Two arguments
initial_day = sys.argv[1]
until_day = sys.argv[2]

DeleteDates(
initial_date=initial_date,
until_date=until_date
initial_date=initial_day,
until_date=until_day
).main()
elif len(sys.argv) > 3:
print (
"Too many arguments. Enter a single date to delete that one " +
"day or enter two days to delete a range of days. " +
"Use the format 'YYYY-MM-DD'.")
14 changes: 8 additions & 6 deletions realestate/lib/scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,9 @@ def main(self):
log.info('Done!')

if __name__ == '__main__':
if len(sys.argv) == 2: # One argument
if len(sys.argv) < 2: # No arguments, default to yesterday date.
Scrape().main()
elif len(sys.argv) == 2: # One argument
day = sys.argv[1]

Scrape(
Expand All @@ -492,8 +494,8 @@ def main(self):
until_date=until_day
).main()
elif len(sys.argv) > 3:
print "Too many arguments. Enter a single date to scrape that one " + \
"day, enter two days to scrape that range of days, or do not " + \
"enter any days at all to scrape yesterday."
else: # No arguments, default to yesterday date.
Scrape().main()
print (
"Too many arguments. Enter a single date to scrape that one " +
"day, enter two days to scrape a range of days, or do not " +
"enter any days at all to scrape yesterday. " +
"Use the format 'YYYY-MM-DD'.")
53 changes: 26 additions & 27 deletions scripts/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
cleaned table. Can receive a date range or determine the dates on its own.
'''

import sys

from realestate.lib.build import Build
from realestate.lib.clean import Clean
from realestate.lib.geocode import Geocode
Expand Down Expand Up @@ -85,38 +87,35 @@ def __init__(self, initial_date=None, until_date=None):
# until_date=self.until_date
# ).check_permanent_status_of_temp_sales()

# Mail(
# subject=EmailTemplate(
# initial_date=self.initial_date,
# until_date=self.until_date
# ).generate_subject(),
# body=EmailTemplate(
# initial_date=self.initial_date,
# until_date=self.until_date
# ).generate_body(),
# frm='tthoren@thelensnola.org',
# to=['tthoren@thelensnola.org']
# ).send_as_html()

# check_assessor_urls().check(
# initial_date=initial_date, until_date=until_date)


if __name__ == '__main__':
try:
# Default is to build and clean anything that needs it.
# Specify custom date range in 'YYYY-mm-dd' string format
# or use variables such as OPENING_DAY, YESTERDAY_DAY.
# e.g. Initialize(initial_date='2014-02-18', until_date=YESTERDAY_DAY)
# Initialize()
Initialize(initial_date='2015-07-05', until_date='2015-07-07')
if len(sys.argv) < 2: # No arguments
# Default is to build and clean anything that needs it.
# Specify custom date range in 'YYYY-mm-dd' string format
# or use variables such as OPENING_DAY, YESTERDAY_DAY.
Initialize()
if len(sys.argv) == 2: # One argument
day = sys.argv[1]

Initialize(
initial_date=day,
until_date=day)
elif len(sys.argv) == 3: # Two arguments
initial_day = sys.argv[1]
until_day = sys.argv[2]

Initialize(
initial_date=initial_day,
until_date=until_day)
elif len(sys.argv) > 3:
print (
"Too many arguments. Enter a single date to build that one " +
"day, enter two days to build a range of days, or do not " +
"enter any days at all to build all days that need it. " +
"Use the format 'YYYY-MM-DD'.")
except Exception, error:
log.exception(error, exc_info=True)
# Mail(
# subject="Error running realestate's initialize.py script",
# body='Check log for more details.',
# frm='tthoren@thelensnola.org',
# to=['tthoren@thelensnola.org']
# ).send_with_attachment(
# files=['%s/realestate.log' % LOG_DIR]
# )

0 comments on commit 25da970

Please sign in to comment.