def main(): db = database.DatabaseHandler() fileR = open(dataDir + commFile) pubSet = set() for line in fileR: line = line.replace("\n", "") tokens = line.split("\t") pubSet.add(tokens[0]) print "len pubSet>>" + str(len(pubSet)) fileW = open("coauth_notPrime.tsv", "w") pubCitList = list() for i in range(130): #fileW = open("coauth_notPrime"+str(i+1)+".tsv", "w") lowerBound = i * 100000 + 1 upperBound = (i + 1) * 100000 pubCitList = db.getCitRef(lowerBound, upperBound) for item in pubCitList: if item[0] in pubSet or item[1] in pubSet: fileW.write(item[0] + "\t" + item[1] + "\n")
def RemoveFromFavorites(item, channel): try: db = database.DatabaseHandler() db.DeleteFavorites(item.name, item.url, channel) except: logFile.error("Settings :: Error removing from favorites", exc_info=True) return
def AddToFavorites(item, channel): """ Adds an items to the favorites """ try: db = database.DatabaseHandler() db.AddFavorite(item.name, item.url, channel) except: logFile.error("Settings :: Error adding favorites", exc_info=True)
def LoadFavorites(channel): """ Reads the favorites into items. """ try: db = database.DatabaseHandler() items = db.LoadFavorites(channel) for item in items: item.icon = channel.icon except: logFile.error("Settings :: Error loading favorites", exc_info=True) return items
def main(): db = database.DatabaseHandler() # create a dict of comm with pub and cit count print "hello" commDict = dict() fileR = open(dataDir + commFile) for line in fileR: line = line.replace("\n", "") tokens = line.split("\t") _id = tokens[0] comm = tokens[1] if comm not in commDict: commDict[comm] = list() else: citCount = db.getCitCount(_id) title = db.getTitle(_id) if title is None or citCount is None: continue commDict[comm].append((title, citCount)) fileW = open(dataDir + "topPub.tsv", "w") for comm in commDict: pubList = commDict[comm] pubList = sorted(pubList, key=itemgetter(1)) if len(pubList) > 10: for i in range(10): item = pubList[(i + 1) * -1] print comm + ">>" + str(item) fileW.write(comm + "\t" + str(item[0]) + ">>" + str(item[1]) + "\n")
import aiml import os import re import sys import google_search import urllib2 from bs4 import BeautifulSoup import urllib import json kernel = aiml.Kernel() import database message = "" db = database.DatabaseHandler("localhost", "root", "root", "chatbot") #db.setupDatabase() if os.path.isfile("bot_brain.brn"): kernel.bootstrap(brainFile="bot_brain.brn") else: kernel.bootstrap(learnFiles="std-startup.xml", commands="load aiml b") kernel.saveBrain("bot_brain.brn") #kernel.saveBrain("bot_brain.brn") # kernel now ready for use def weather(location):
intents.members = True intents.presences = True bot = commands.Bot(command_prefix=config_data["prefix"], description=config_data['description'], intents=intents) # ATTACH CONFIG DATA bot.config = config_data # ATTACH BOT INFO bot.version = str(discord.__version__) bot.start_time = datetime.datetime.utcnow() # CONNECT TO DATABASE databasehandler = database.DatabaseHandler(config_data['database']) bot.databasehandler = databasehandler # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~ IMPORT MODULES ~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ print("[!] LOADING MODULES:") for module in config_data["modules"]: try: bot.load_extension(f"modules.{module}.{module}") print(f" [✓] {module} Loaded") except Exception: print(f" [✘] ERROR Loading \'{module}\' module. Check config files.")
@requires_auth def save(): try: location = request.form['location'] quantity = request.form['quantity'] database_handler.insert_course(location, quantity) result = "OK" return render_template('save.html', result=result) except Exception as e: LOGGER.error("Error in save(): " + str(e)) @app.route('/export', methods=['POST']) @requires_auth def export(): try: data = database_handler.get_all_courses() pdfexport.export_courses(data) uploads = os.path.join(app.config['UPLOAD_FOLDER']) return send_from_directory(directory=uploads, filename='export.pdf') except Exception as e: LOGGER.error("Error in export(): " + str(e)) if __name__ == '__main__': create_logger() database_handler = database.DatabaseHandler() app.run(host='', port=80, debug=True) #http_server = WSGIServer(('', 80), app) #http_server.serve_forever()
def main(): db = database.DatabaseHandler() # store comm id fileR = open(dataDir + commDataset) fileW = open(dataDir + commFile, "w") for line in fileR: if line.find("Class") > 0: continue line = line.replace("\n", "") tokens = line.split(" ") comm = tokens[2] _id = tokens[1] if db.getTitle(_id) is None: continue fileW.write(_id + "\t" + comm + "\t" + db.getTitle(_id) + "\n") # store cit nw ''' # store pubCoauth fileR = open(dataDir + commFile) fileW = open(dataDir+pubCoauth, "w") for line in fileR: print line line = line.replace("\n", "") tokens = line.split("\t") _id = tokens[0] authList = db.getAuthList(_id) wLine = _id if authList is None: continue for auth in authList: wLine = wLine + "\t" + str(auth) wLine = wLine + "\n" print wLine fileW.write(wLine) ''' ''' # store citation nw fileR = open(dataDir + commFile) fileW = open(dataDir + citNw, "w") count = 0 for line in fileR: print line line = line.replace("\n", "") tokens = line.split("\t") pub = tokens[0] neighSet = db.getNeigh(pub) for neigh in neighSet: fileW.write(pub + "\t" +str(neigh) + "\n") count = count + 1 if count > 10000: break ''' #db.getTitle() print "hello"
def setUp(self): """ Set up the class, mocking the logger to silence it. """ Database.LOGGER = MagicMock() self.db_handler = Database.DatabaseHandler()
while True: mqtt_client.publish("status", self.name) sleep(1) except Exception as e: logging.error("Error in HealthCheck.run(): {}".format(e)) healthcheck = HealthCheck(app_name) healthcheck.daemon = True healthcheck.start() if __name__ == '__main__': try: signal.signal(signal.SIGTERM, signal_term_handler) database_handler = database.DatabaseHandler(":memory:") #database_handler = database.DatabaseHandler("database.db") regexs_handler = cep.RegexsHandler() rules_handler = cep.create_rules_handler(database_handler) mqtt_client = mqtt_client = create_mqtt_client(MQTT_HOST, MQTT_PORT, on_message, MQTT_TOPICS) config_handler = cep.ConfigHandler() sleep(1) parse_config() create_healthcheck("homevents") logging.info("Initializing server...") app.run(host='0.0.0.0', port=80) except Exception as e: logging.error('Error in main: ' + str(e))
app.debug = False app.config['MAX_CONTENT_LENGTH'] = int(config.MAX_CONTENT_LENGTH) BUCKET = os.environ['S3_BUCKET'] app.config['UPLOAD_FOLDER'] = os.path.join( os.path.dirname(__file__) + "/" + config.UPLOAD_FOLDER) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URI'] app.config['SQLALCHEMY_POOL_RECYCLE'] = 90 db_handler = database.DatabaseHandler(app) # Determines if a file's extension is allowed def allowed_file(filename): return '.' in filename and \ filename.rsplit('.', 1)[1].lower() in config.ALLOWED_EXTENSIONS @app.route("/") def start(): return render_template('index.html') @app.route('/features') def features():