Skip to content

Instantly share code, notes, and snippets.

@policevideorequests
Last active August 29, 2015 14:11
Show Gist options
  • Save policevideorequests/e753557942ad4424dfe5 to your computer and use it in GitHub Desktop.
Save policevideorequests/e753557942ad4424dfe5 to your computer and use it in GitHub Desktop.
# Copyright 2014 by Timothy Clemans released as free open source under GPL
"""You would setup an email address dedicated to this automated
requesting of GO reports.
(1) DONE: Computer code would download the GO Reports data from
https://data.seattle.gov/Public-Safety/Seattle-Police-Department-Police-Report-Incident/7ais-f98f
and extract the GO #s for types of incidents you care about in the
zones/beats for your zone.
(2) DONE: Computer would generate one request per report asking for the
report to be emailed in PDF format without exemption log as a reply to
that particular email with subject "Request for GO report #XXXXXXX"
(3) DONE: Computer sends the request if the given Go report hasn't already been requested
(4) (Use Gmail auto forwarder by filter instead) When computer checks the email inbox setup for this if there is a
PDF attached to an email then the computer would email the PDF to your
main email address with date/time of the incident and type of
incident in the subject."""
import json
import urllib2
response = urllib2.urlopen('https://data.seattle.gov/resource/7ais-f98f.json?district_sector=W&year=2014&month=12')
go_reports = response.read()
go_reports = json.loads(go_reports)
#zone_beats_to_extract = ['W1', 'W2', 'W3']
district_sector_to_extract = 'W'
#types_to_extract = ['VEHICLE THEFT', 'ASSAULT']
already_done = []
f = open('already_done.txt', 'r')
already_done.extend(f.read().split('\n'))
f.close()
for go_report in go_reports:
if 'SW' in go_report.get('hundred_block_location') and str(go_report.get('general_offense_number')) not in already_done:
import time
#time.sleep(60*11) # 11 minutes
#print go_report
email_subject = "PDR for %s at %s on %s GO #%s" % (go_report.get("offense_type"), go_report.get("hundred_block_location"), go_report.get("occurred_date_range_end"), go_report.get("general_offense_number"))
body_of_email = "I request the GO Report for GO #%s be provided via email in PDF format. I waive the need for an exemption log.\n\nThis request is made on behalf of Tracy Record by a computer program created by Timothy Clemans. PDFs sent to this email get auto forwarded to editor@westseattleblog.com Call Tracy at (206) 293-6302 to confirm this bot works on her behalf.\nThe bot's code is at https://gist.github.com/policevideorequests/e753557942ad4424dfe5 Tracy wants GO Report narratives to be provided in real time. Here's code for overredacting narratives https://gist.github.com/policevideorequests/f5304fd0a5d2c67d4f1e" % (go_report.get("general_offense_number"))
#print go_report
print
import smtplib
recipient = "spdpdr@seattle.gov"
session = smtplib.SMTP('smtp.gmail.com', 587)
session.ehlo()
session.starttls()
GMAIL_USERNAME = "wsbpdr"
session.login("wsbpdr", "XXXXXXXXXXXXXXXXXXXX")
headers = "\r\n".join(["from: Tracy Record <wsbpdr@gmail.com>",
"subject: " + email_subject,
"to: " + recipient,
"mime-version: 1.0",
"content-type: text/html"])
# body_of_email can be plaintext or html!
content = headers + "\r\n\r\n" + body_of_email
session.sendmail(GMAIL_USERNAME, recipient, content)
session.quit()
f = open('already_done.txt', 'r')
before = f.read()
f.close()
f = open('already_done.txt', 'w')
f.write(before+'\n%s'%(go_report.get("general_offense_number")))
f.close()
for i in range(11):
print i
time.sleep(60) # 11 minutes
#print go_reports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment