"""Our script that is exec'd from twistd via run.sh"""
# Base Python
import json
import os
import sys

# Twisted Bits
from twisted.application import service, internet
from twisted.web import server
from twisted.internet import reactor
from twisted.enterprise import adbapi
from txyam.client import YamClient

# Twisted 16.4 changes import logic
sys.path.insert(0, os.getcwd())

# Local Import
from iembot import iemchatbot, webservices

dbconfig = json.load(open('settings.json'))

application = service.Application("Public IEMBOT")
serviceCollection = service.IServiceCollection(application)

# This provides DictCursors!
dbrw = dbconfig.get('databaserw')
dbpool = adbapi.ConnectionPool("pyiem.twistedpg", cp_reconnect=True,
                               database=dbrw.get('openfire'),
                               host=dbrw.get('host'),
                               password=dbrw.get('password'),
                               user=dbrw.get('user'))

memcache_client = YamClient(reactor, ['tcp:iem-memcached3:11211', ])
memcache_client.connect()

jabber = iemchatbot.JabberClient("iembot", dbpool, memcache_client)

defer = dbpool.runQuery("select propname, propvalue from properties")
defer.addCallback(jabber.fire_client_with_config, serviceCollection)

# 2. JSON channel requests
json = server.Site(webservices.JSONRootResource(jabber), logPath='/dev/null')
x = internet.TCPServer(9003, json)  # pylint: disable=no-member
x.setServiceParent(serviceCollection)

# 3. Answer requests for RSS feeds of the bot logs
rss = server.Site(webservices.RSSRootResource(jabber), logPath="/dev/null")
r = internet.TCPServer(9004, rss)  # pylint: disable=no-member
r.setServiceParent(serviceCollection)

"""Our script that is exec'd from twistd via run.sh"""
# Base Python
import json

# Twisted Bits
from twisted.application import service, internet
from twisted.web import server
from twisted.internet import reactor
from twisted.enterprise import adbapi
from txyam.client import YamClient

# Local Import
from iembot import iemchatbot, webservices

dbconfig = json.load(open('settings.json'))

application = service.Application("Public IEMBOT")
serviceCollection = service.IServiceCollection(application)

# This provides DictCursors!
dbrw = dbconfig.get('databaserw')
dbpool = adbapi.ConnectionPool("pyiem.twistedpg", cp_reconnect=True,
                               database=dbrw.get('openfire'),
                               host=dbrw.get('host'),
                               password=dbrw.get('password'),
                               user=dbrw.get('user'))

memcache_client = YamClient(reactor, ['tcp:iem-memcached3:11211', ])
memcache_client.connect()

jabber = iemchatbot.JabberClient("iembot", dbpool, memcache_client)

defer = dbpool.runQuery("select propname, propvalue from properties")
defer.addCallback(jabber.fire_client_with_config, serviceCollection)

# 2. JSON channel requests
json = server.Site(webservices.JSONRootResource(jabber), logPath='/dev/null')
x = internet.TCPServer(9003, json)  # pylint: disable=no-member
x.setServiceParent(serviceCollection)

# 3. Answer requests for RSS feeds of the bot logs
rss = server.Site(webservices.RSSRootResource(jabber), logPath="/dev/null")
r = internet.TCPServer(9004, rss)  # pylint: disable=no-member
r.setServiceParent(serviceCollection)

remove un-neccessary path adjustment