Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor relative date formatting #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions MuckRock_lambda.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
import requests
from datetime import datetime
import dateutil.relativedelta
import os
from dateutil.relativedelta import relativedelta
import os

username = os.environ['my_username']
passphrase = os.environ['my_passphrase']
Expand All @@ -25,27 +25,22 @@ def get_headers(token=None):
return {'content-type': 'application/json'}


def lambda_handler(event, context):
def lambda_handler(event, context):
print("Received event")
# first get today's month then subtract one month to grab previous

s = str(datetime.now())[0:10]
d = datetime.strptime(s, "%Y-%m-%d")
d2 = d - dateutil.relativedelta.relativedelta(months=1)
# strip day of the week + other timedate objects
d2 = str(d2)[0:7]

one_month_ago = datetime.now() - relativedelta(months=1)
year_month = one_month_ago.strftime("%Y-%m")
# use test agencies from MuckRock
foia_doc = json.dumps({
'jurisdiction': 10,
'agency': 248,
'title': 'Last Month\'s 1505 checks',
'document_request':
'For the year and month of ' + d2 +
'For the year and month of ' + year_month +
', I am requesting a list of all 1505 checks expenditures issues by the Bureau of Organized Crime. '
'I am requesting the full list of checks spent by the BoC during the full month of ' + d2 + '. ',
'I am requesting the full list of checks spent by the BoC during the full month of ' + year_month + '. ',
})

header = get_headers(token)
foia_url = api_url+'foia/'
r = requests.post(foia_url, data=foia_doc, headers=header)
Expand Down