import sys, os
import importlib
import argparse
from mycityhall_scrapers import *
from pupa.cli import __main__
from pupa.cli.commands import update, base

# os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mycityhall_scraperreports.settings")


def scrape_people():
  jurisdictions = os.listdir('./mycityhall_scrapers')
  # scraper_path = os.path.abspath(os.path.join(os.path.abspath(__file__), os.pardir))+'/mycityhall_scrapers/'
  scraper_path = os.path.abspath(os.path.join(os.path.abspath(__file__), os.pardir))+'/'
  print scraper_path
  sys.path.insert(0,scraper_path)
  jurisdictions = [x for x in jurisdictions if os.path.exists(scraper_path+x+'/__init__.py')]


  reports = []


  for jurisdiction in jurisdictions:
    try:
      COMMAND_MODULES = (
          'pupa.cli.commands.update',
      )
      parser = argparse.ArgumentParser('pupa', description='pupa CLI')
      subparsers = parser.add_subparsers(dest='subcommand')

      subcommands = {}
      for mod in COMMAND_MODULES:
        cmd = importlib.import_module(mod).Command(subparsers)
        subcommands[cmd.name] = cmd

      # process args
      args = parser.parse_args(['update', '--people', jurisdiction])
      subcommands[args.subcommand].handle(args)

      report = {'name' : jurisdiction, 'status' : 'working', 'error' : 'none' }
      reports.append(report)

    except:
      report = {'name' : jurisdiction, 'status' : 'working' , 'error' : sys.exc_info()}
      reports.append(report)
  return reports

def scrape_events():
  jurisdictions = os.listdir('./mycityhall_scrapers')
  scraper_path = os.path.abspath(os.path.join(os.path.abspath(__file__), os.pardir))+'/'
  sys.path.insert(0,scraper_path)
  jurisdiction = [x for x in jurisdictions if os.path.exists(scraper_path+x+'/events.py')]

  reports = []

  for jurisdiction in jurisdictions:
    try:
      COMMAND_MODULES = (
          'pupa.cli.commands.update',
      )
      parser = argparse.ArgumentParser('pupa', description='pupa CLI')
      subparsers = parser.add_subparsers(dest='subcommand')

      subcommands = {}
      for mod in COMMAND_MODULES:
        cmd = importlib.import_module(mod).Command(subparsers)
        subcommands[cmd.name] = cmd

      # process args
      args = parser.parse_args(['update', '--events', jurisdiction])
      subcommands[args.subcommand].handle(args)

      report = {'name' : jurisdiction, 'status' : 'working', 'error' : 'none' }
      reports.append(report)

    except:
      report = {'name' : jurisdiction, 'status' : 'working' , 'error' : sys.exc_info()}
      reports.append(report)
  return reports
@@ -1488,1112 +1488,4 @@
 rts%0A
-%0Adef scrape_events():%0A  jurisdictions = os.listdir('./mycityhall_scrapers')%0A  scraper_path = os.path.abspath(os.path.join(os.path.abspath(__file__), os.pardir))+'/'%0A  sys.path.insert(0,scraper_path)%0A  jurisdiction = %5Bx for x in jurisdictions if os.path.exists(scraper_path+x+'/events.py')%5D%0A%0A  reports = %5B%5D%0A%0A  for jurisdiction in jurisdictions:%0A    try:%0A      COMMAND_MODULES = (%0A          'pupa.cli.commands.update',%0A      )%0A      parser = argparse.ArgumentParser('pupa', description='pupa CLI')%0A      subparsers = parser.add_subparsers(dest='subcommand')%0A%0A      subcommands = %7B%7D%0A      for mod in COMMAND_MODULES:%0A        cmd = importlib.import_module(mod).Command(subparsers)%0A        subcommands%5Bcmd.name%5D = cmd%0A%0A      # process args%0A      args = parser.parse_args(%5B'update', '--events', jurisdiction%5D)%0A      subcommands%5Bargs.subcommand%5D.handle(args)%0A%0A      report = %7B'name' : jurisdiction, 'status' : 'working', 'error' : 'none' %7D%0A      reports.append(report)%0A%0A    except:%0A      report = %7B'name' : jurisdiction, 'status' : 'working' , 'error' : sys.exc_info()%7D%0A      reports.append(report)%0A  return reports

Revert "scrape_events script"