[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Generator - Provide parameters to url - requests


I am struggling to figure out how I can create a generator to provide values to my url. My url needs to insert the year month and day in the url not as params to the url.

import json
import requests
import datetime

# using this I can create a list of dates for the first 210 days of this year.

base = datetime.datetime(2017,1,1)

def datesRange(max, min):
    date_list = (base - datetime.timedelta(days=x) for x in range(max,min))
    DAY = date_list.day
    MONTH = date_list.month
    YEAR = date_list.year
    yield DAY, MONTH, YEAR

dateValues = datesRange(-210,0)
def create_url(day, month, year):
    return url

Then I want to insert them in this url one at a time from the generator

   r = requests.get(INSERT_URL_HERE)
   if r.status_code == requests.codes.ok then:
      # open a file for writing using url paramters
      with open(SR + DAY + MONTH + YEAR + '.json', 'w') as f:
      # Do stuff from here not relevant to question.

I have just gotten lost.

Is there an easier way to go about this?