def main(): api = PoliceAPI() # Force print(api.get_forces()) # All forces force = Force(api, id='leicestershire') # Leicestershire Police print(force.description) # description of Leicestershire Police # all the Neighbourhood Policing Teams in this Leicestershire Police area print(force.neighbourhoods) print(force.telephone) # The force’s main switchboard number # Neighbourhood neighbourhood = Neighbourhood(api, force=force, id='NW02') # neighbourhood with NW02 id print(neighbourhood.name) # Name of neighbourhood (Abbey) print(neighbourhood.officers) # All Abbey officers print(neighbourhood.events) # Events in Abbey # Crimes anti_social_crimes = PoliceAPI().get_crimes_area( neighbourhood.boundary, category='anti-social-behaviour') print(anti_social_crimes) # All crimes in Abbey with anti-social behaviour # All crimes in Abbey in October 2008 crimes = api.get_crimes_area(neighbourhood.boundary, date='2018-10') crime = crimes[30] print(crime.location.name) # location of crime print(crime.category) # category of crime print(crime.outcomes) # crime outcomes
def filter_crimes(Ward_array): """ Creates an Array of Neighbourhood objects. (Array) -> Array """ api = PoliceAPI() neighbourhoods = Array() for force in api.get_forces(): for neighbourhood in force.neighbourhoods: if Ward(neighbourhood.name) in Ward_array: neighbourhoods.add(neighbourhood) return neighbourhoods
def main(t_current): # Call the police API api = PoliceAPI() # Define tables crime_categories = pd.DataFrame({'id': [], 'description': []}) outcome_categories = pd.DataFrame({'id': [], 'description': []}) streets = pd.DataFrame({'id': [], 'name': []}) crimes = pd.DataFrame({ 'persistent_id': [], 'category': [], 'street': [], 'city': [], 'latitude': [], 'longitude': [], 'date': [], 'context': [] }) outcomes = pd.DataFrame({ 'crime': [], 'category': [], 'date': [], 'person_id': [] }) # Transform dates into pandas Series for better manipulation dates = pd.Series(api.get_dates()) # Get Forces forces = api.get_forces() # Get neighbourhoods neighbourhoods = [f.neighbourhoods for f in forces] nb_flat = [n for sublist in neighbourhoods for n in sublist] s_nb_flat = pd.Series(nb_flat).unique() first_job(api, dates, t_current) t_last_update = api.get_latest_date() second_job(api, dates, t_last_update, t_current) last_job(api, t_current)
#!/usr/bin/env python2 import csv import json from police_api import PoliceAPI from police_api.forces import Force api = PoliceAPI() forces = api.get_forces() # creating new csv file with structure. with open("forces.csv", "w") as file: writer = csv.writer(file) writer.writerow([ "force id", "facebook page", ]) for dep in forces: # opening forces.csv in append mode. f = open("forces.csv", "a") force = Force(api, id=dep.id) # getting engagements methods json_engagements = force.engagement_methods for data in json_engagements: # searching for those who has facebook type of engagement if data["type"] == "Facebook": force_facebook = data["url"] csv_data = [dep.id, force_facebook] # appending to csv file. with f: writer = csv.writer(f)
for d in date_range: a = d.split('-') dt = month_dict[int(a[1])] + ' ' + a[0] new_date_range.append((dt)) return new_date_range new_dt_range = format_date_range((dt_range)) date_range = dict(zip(new_dt_range, dt_range)) date_dropdown = [{ 'label': str(k), 'value': str(v) } for k, v in date_range.items()] # Get the police force police_forces = police.get_forces() police_force_list = [{'label': p.name, 'value': p.name} for p in police_forces] def get_police_force_id(police_name): """A function to return the police id in str data format.""" police_id = [p.id for p in police_forces if p.name == police_name] if police_id != []: return police_id[0] else: return None # Get neighbourhood boundary for finding crime @cache.memoize(10) def get_neighbourhood_id(police_name, neighbourhood_name):