Skip to content

Instantly share code, notes, and snippets.

@WDBell
Last active June 15, 2017 21:55
Show Gist options
  • Save WDBell/1010de7fee6c604e00e80b52559ca424 to your computer and use it in GitHub Desktop.
Save WDBell/1010de7fee6c604e00e80b52559ca424 to your computer and use it in GitHub Desktop.
Follow the price of apples
url = '''https://www.marketnews.usda.gov/mnp/fv-report-top-filters?&navClass=FRUITS&commAbr=APL&navType=byComm&repType=termPriceDaily&className=FRUITS&commName=%(commName)s&locName=&type=termPrice&repDate=%(theDate)s&endDate=%(theDate)s&format=excel&rebuild=false'''
import pendulum
from selenium import webdriver
commName = 'APPLES'
first_date = pendulum.parse('2017.6.13')
last_date = pendulum.parse('2017.6.17')
finish = last_date.add(days=+1)
day = first_date.add(days=-1)
if not(first_date.is_today() or first_date.is_past()):
print('request for future information')
driver = webdriver.Chrome()
while True:
day = day.add(days=+1)
if day == last_date: break
if day.is_weekend(): continue
theDate = day.strftime('%m%%2F%d%%2F%Y')
driver.get(url % locals())
driver.quit()
@StefanoUS
Copy link

Hi again Bill, so I am trying to understand the code here. What this code is trying to do is to obtain a url that would download all the Excel files that belong to the date range I state as first_date and last_date?

@StefanoUS
Copy link

When I run the code, all it downloads is a 0bytes document "d64e048c-d12e-4a8a-b9b1-500cf3141117.tmp"
Any explanation why this is happening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment