def loadAnswerSet(path, pattern = "default"): database.open() if os.path.isfile(path): files = [path] elif os.path.isdir(path): files = glob.glob(path + "/*/*/*") else: print("\"" + path + "\" is neither a file nor a folder. We assume that it is a file pattern...") files = glob.glob(path) for file in files: print("Looking at " + file) (trial,student,solution) = parseFilename(file, pattern) history = loadCSV(file) n = 1 nm = NodeMap(trial) data = {} for row in history: src = nm.get(row["Source"]) dst = nm.get(row["Destination"]) if row["Action"] == "Connecting": database.addProgress(solution, n, "create", src, dst, "") data[(src,dst)] = (n, "") elif row["Action"] == "Renaming": database.addProgress(solution, n, "rename", src, dst, row["to"]) data[(src,dst)] = (n, row["to"]) elif row["Action"] == "Disconnecting": database.addProgress(solution, n, "remove", src, dst, "") del data[(src,dst)] n += 1 for d in data: ordering,desc = data[d] database.addAnswer(solution, ordering, d[0], d[1], desc)
def __init__(self, path): self.db = database.open(path) self.backreferences = registry.BackreferenceRegistry() self.instances = registry.ModelInstanceRegistry() self.models = {} self.context = None self.Model = model.create(self)
def selectTrial(): database.open() print("Please select one of these experiments:") trials = database.listTrials() valid = [] for t in trials: print("\t" + str(t[0]) + "\t" + str(t[1])) valid.append(str(t[0])) res = input("> ") if res.isdigit() and (res in valid): print() return int(res) else: print("Your input was invalid.") print() return selectTrial()
def loadAnswerSet(path, pattern="default"): database.open() if os.path.isfile(path): files = [path] elif os.path.isdir(path): files = glob.glob(path + "/*/*/*") else: print( "\"" + path + "\" is neither a file nor a folder. We assume that it is a file pattern..." ) files = glob.glob(path) for file in files: print("Looking at " + file) (trial, student, solution) = parseFilename(file, pattern) history = loadCSV(file) n = 1 nm = NodeMap(trial) data = {} for row in history: src = nm.get(row["Source"]) dst = nm.get(row["Destination"]) if row["Action"] == "Connecting": database.addProgress(solution, n, "create", src, dst, "") data[(src, dst)] = (n, "") elif row["Action"] == "Renaming": database.addProgress(solution, n, "rename", src, dst, row["to"]) data[(src, dst)] = (n, row["to"]) elif row["Action"] == "Disconnecting": database.addProgress(solution, n, "remove", src, dst, "") del data[(src, dst)] n += 1 for d in data: ordering, desc = data[d] database.addAnswer(solution, ordering, d[0], d[1], desc)
import shapely.wkt import database import mapGenerator ############################################################################# METERS_PER_MILE = 1609.344 ############################################################################# # Open the database. database.open() # Get our CGI parameters. form = cgi.FieldStorage() countryID = int(form['countryID'].value) radius = int(form['radius'].value) x = int(form['x'].value) y = int(form['y'].value) mapWidth = int(form['mapWidth'].value) mapHeight = int(form['mapHeight'].value) # Calculate the lat/long bounds for the map the user clicked on. details = database.get_country_details(countryID)
def test_is_open_opened(self): database.create_menu_table('speedy') database.open('speedy') self.assertTrue(database.is_open('speedy'))
def test_close_an_open_restaurant(self): database.create_menu_table('subway') database.open('subway') self.assertTrue(database.close('subway'))
def test_open_an_opened_restaurant(self): database.create_menu_table('subway') database.open('subway') self.assertFalse(database.open('subway'))
def test_open_closed_restaurant(self): database.create_menu_table('speedy') self.assertTrue(database.open('speedy'))
def open(): restaurant = input("Which restaurant you want to open: ") if database.is_there_such_restaurant(restaurant): database.open(restaurant) else: print("There is no such restaurant")
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType import vk_group_bot import database import bot import user_message_handler import admin_message_handler if __name__ == "__main__": vk_group_bot.initialize() database.open() bot.initialize() longpool = VkBotLongPoll(vk_group_bot.vk, vk_group_bot.GROUP_ID) Running = True while Running: for event in longpool.listen(): if not Running: break # handle events if event.type == VkBotEventType.MESSAGE_NEW: if event.object.peer_id != vk_group_bot.ADMIN_CHAT_ID: user_message_handler.handle(event.object) else: admin_message_handler.handle(event.object)
"--db", dest="db_path", help="Path to the database file to be used", type=str, default=DEFAULT_DB_PATH) argparser.add_argument("--broker", dest="mqtt_broker", help="The MQTT broker URI", type=str, default=DEFAULT_MQTT_BROKER) args = argparser.parse_args() # make database instance db_path = args.db_path database_path = os.path.dirname(db_path) database_name = os.path.basename(db_path) if not os.path.exists(database_path): logging.info('Creating directory "{}"'.format(database_path)) os.mkdir(database_path) db_path = os.path.join(database_path, database_name) logging.info("Connecting to database '{}'".format(db_path)) database.open(db_path) # first off, get all existing data from the database topics = database.get_topics() for topic in topics: data = database.get_data(topic) # sensor type is the last part in the topic sensor_type_str, sensor_name_str = sensor_type_and_name_from_db_name( topic) with g_topic_data_lock: if sensor_type_str in g_topic_data: sensor_type: SensorType = g_topic_data[sensor_type_str] the_data = sensor_type.add_series(sensor_name_str) else:
import database database.open('BotDB.db') with open('CreationScript.sql') as SQLFile: sqlText = SQLFile.read() tableTexts = sqlText.split('=====\n') for text in tableTexts: database.cursor.execute(text) database.connection.commit() print(text.split('\n')[1]) print('tables created') database.close()