'Python for loop for multiple postgres queries based on dates

I want to create a for loop that queries data from my database one week at a time for three months.

For example:

import tempfile
import pandas as pd

DB_URL = 'db/url/here:1234'
engine = sqlalchemy.create_engine(DB_URL)
conn = engine.connect()

queries=
{'d_week1_start':2017-12-1, 
'd_week1_end':2017-12-7, 
'd_week2_start':2017-12-7,  
'd_week2_end':2017-12-14,
'd_week3_start': 2017-12-14,
'd_week3_end':2017-12-21, 
'd_week4_start': 2017-12-21,
'd_week4_end':2017-12-31}

for qr in queries:
     one_week_df = pd.read_sql(qr, conn)
     one_week_df.to_pickle('one_week.pkl')

How would I go about doing something like this?

Update: I realized I wasn't passing any queries. I changed the items in the dictionary to queries like:

'''SELECT * FROM table WHERE time > '20180201T120000'' AND time < '20180207T120000' ORDER BY time ASC'''


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source