def setUpClass(cases):
     # set up a seperate database for testing
     (cursor, conn) = conn_to_test_psql()
     
     # set up a seperate logger
     logger = setup.setup_logger()
     
     # set up the test tables with the same schema as the ones the tested functions operate on
     cursor.execute(slurp('schema.sql'))
     
     # load "police-neighborhoods.csv" into the test database
     setup.load_hood_base()
Example #2
0
#!/usr/bin/env python
import atexit
import posix_ipc as ipc
import sys
from amqplib import client_0_8 as amqp
import simplejson as json
import time
import setup

count = 0

log = setup.setup_logger("sms.reciever")

exchange = sys.argv[1]
routing_key = sys.argv[2]

semaphore = setup.setup_semaphore()

sm = setup.setup_gammu_state_machine()

qconn, chan = setup.setup_queue()

while True:

    log.debug("Aquiring lock")
    semaphore.acquire()
    log.debug("Lock aquired")
    status = sm.GetSMSStatus()
    semaphore.release()
    log.debug("Lock released")
    total = status["PhoneUsed"]
Example #3
0
        if count >= len(message_list):
            count = 0
        else:
            count += 1
 
    # Check if message starts with a command - if yes, return
    if command in bot.commands:
        log.debug("--- caught a command")
        return
    # Check if BotBoy wrote the message
    if message.author != bot.user:
        # Check if the message has attachments
        if not message.attachments:
            # log.debug(message.author)
            # log.debug("No attachments found in message")
            # TODO: get rid of return when we add an await
            # await bot.send_message(message.channel, "You know the rules.")
            return
    else:
        # TODO: do async's need an await every time? Or is return sufficient?
        return

setup.setup_logger()

log = logging.getLogger('BotBoy')

# bot.loop.create_task(background_tasks(60))
bot.run(TOKEN)
conn.close()
Example #4
0
# Qian Yang (qyang1)

# This script coarsely filters the input crime data.
# 1) accepts the name of a CSV file as an argument
# 2) filter the data, only including OFFENSE 2.0 reports of pre-identified kinds AND crimes with legal neighbor and zone attributes.
# 3) print the result as a CSV file to STDOUT.

import psycopg2
import csv
import sys
import setup

# ===================== setup database connection and logger ===================== #

(cursor, conn) = setup.conn_to_psql()
logger = setup.setup_logger()

# ================== Extract Offense 2.0 codes from PSQL ================== #

try:
    offense2_section_list = []
    cursor.execute('select section from crime_code;')
    for section in cursor.fetchall():
        offense2_section_list.append(section[0])

    # print offense2_section_list
except:
    print 'Unable to pull offense 2.0 section codes from the crime_code table.'

# ======================== Load input csv file ======================== #
Example #5
0
#!/usr/bin/env python
import atexit
import posix_ipc as ipc
from amqplib import client_0_8 as amqp
import simplejson as json
import gammu
import logging
import setup

log = setup.setup_logger("sms.dispatcher")

semaphore = setup.setup_semaphore()

conn, chan = setup.setup_queue()

sm = setup.setup_gammu_state_machine()


def send_sms(msg):
    log.debug("Waiting for lock")
    semaphore.acquire()
    log.debug("Acquired lock")
    data = json.loads(msg.body)
    data["SMSC"] = {"Location": 1}
    try:
        sm.SendSMS(data)
        chan.basic_ack(msg.delivery_tag)
        log.info("Sent %s message: %s" % (data["Number"], data["Text"]))
    finally:
        semaphore.release()
        log.debug("Lock released")