def main(city): con = db.connect() db.create_table(con) response = weather.get_weather(city) record = weather.format_response(response) db.insert_record(con, record) con.close()
def result_collector(psycho_cursor, result_queue): """ Stores result from result_queue to a database. """ while True: result = result_queue.get() if result is None: break # Store result in database if psycho_cursor is not None: db.insert_record(psycho_cursor, db.SCHEMAS[0], result) else: db.save_to_file(result) logger.debug("result_collector stopped.")
def post(self, database, table, rowid=None): """INSERT or UPDATE records""" # Prepare request (POST) vars. We only have to do this because # we get a dict of lists and our funcs want a dict of single # values kwargs = {} for k, v in self.request.arguments.iteritems(): kwargs[k] = v[0] try: if rowid: # Perform UPDATE json = dumps(db.update_record(database, table, rowid, **kwargs)) self.write(json) else: # Perform INSERT id = db.insert_record(database, table, **kwargs) self.set_status = 201 # HTTP 201 Created loc = "/%s/%s/%d" % (database, table, id) self.set_header("Location", loc) self.write(loc) except db.NoSuchDatabase: raise HTTPError(404)
def post(self, database, table, rowid=None): """INSERT or UPDATE records""" # Prepare request (POST) vars. We only have to do this because # we get a dict of lists and our funcs want a dict of single # values kwargs = {} for k, v in self.request.arguments.iteritems(): kwargs[k] = v[0] try: if rowid: # Perform UPDATE json = dumps(db.update_record(database, table, rowid, **kwargs)) self.write(json) else: # Perform INSERT id = db.insert_record(database, table, **kwargs) self.set_status = 201 # HTTP 201 Created loc = '/%s/%s/%d' % (database, table, id) self.set_header('Location', loc) self.write(loc) except db.NoSuchDatabase: raise HTTPError(404)
def event_create_record(): app_name = ent_app_name.get() url = ent_url.get() email = ent_email.get() password = ent_password.get() if app_name == '' or url == '' or email == '' or password == '': messagebox.showinfo("Alert", "All details must be filled!") return # add the record into the database db.insert_record((app_name, url, email, password)) # clear all the inputs event_reset() update_view('')
def test_update_record(self): # TODO: define behavior for when a record does not exist id = db.insert_record(TEST_DB, TEST_TABLE, col1=123, col2='abc') db.update_record(TEST_DB, TEST_TABLE, 999, col2='def') res = db.get_record(TEST_DB, TEST_TABLE, id) self.assertEqual(res, {'rowid': id, 'col1': 123, 'col2': 'abc'}) db.update_record(TEST_DB, TEST_TABLE, id, col2='def') res = db.get_record(TEST_DB, TEST_TABLE, 1) self.assertEqual(res, {'rowid': id, 'col1': 123, 'col2': 'def'})
def test_update_record(self): # TODO: define behavior for when a record does not exist id = db.insert_record(TEST_DB,TEST_TABLE,col1=123,col2='abc') db.update_record(TEST_DB,TEST_TABLE,999,col2='def') res = db.get_record(TEST_DB,TEST_TABLE,id) self.assertEqual(res, {'rowid':id,'col1':123,'col2':'abc'}) db.update_record(TEST_DB,TEST_TABLE,id,col2='def') res = db.get_record(TEST_DB,TEST_TABLE,1) self.assertEqual(res, {'rowid':id,'col1':123,'col2':'def'})
def test_delete_record(self): # TODO: define behavior for when a record does not exist id = db.insert_record(TEST_DB, TEST_TABLE, col1=123, col2='abc') db.delete_record(TEST_DB, TEST_TABLE, id) res = db.get_record(TEST_DB, TEST_TABLE, id) self.assertEqual(res, None)
def test_replace_record(self): # TODO: define behavior for when a record does not exist id = db.insert_record(TEST_DB, TEST_TABLE, col1=123, col2='abc') db.replace_record(TEST_DB, TEST_TABLE, id, [555, 'def']) res = db.get_record(TEST_DB, TEST_TABLE, id) self.assertEqual(res, {'rowid': id, 'col1': 555, 'col2': 'def'})
def test_insert_record(self): id = db.insert_record(TEST_DB, TEST_TABLE, col1=123, col2='abc') res = db.get_record(TEST_DB, TEST_TABLE, 1) self.assertNotEqual(id, None) self.assertEqual(res, {'rowid': id, 'col1': 123, 'col2': 'abc'})
def test_delete_record(self): # TODO: define behavior for when a record does not exist id = db.insert_record(TEST_DB,TEST_TABLE,col1=123,col2='abc') db.delete_record(TEST_DB,TEST_TABLE,id) res = db.get_record(TEST_DB,TEST_TABLE,id) self.assertEqual(res, None)
def test_replace_record(self): # TODO: define behavior for when a record does not exist id = db.insert_record(TEST_DB,TEST_TABLE,col1=123,col2='abc') db.replace_record(TEST_DB,TEST_TABLE,id,[555,'def']) res = db.get_record(TEST_DB,TEST_TABLE,id) self.assertEqual(res, {'rowid':id,'col1':555,'col2':'def'})
def test_insert_record(self): id = db.insert_record(TEST_DB,TEST_TABLE,col1=123,col2='abc') res = db.get_record(TEST_DB,TEST_TABLE,1) self.assertNotEqual(id, None) self.assertEqual(res, {'rowid':id,'col1':123,'col2':'abc'})
def add_record(id_input, name_input, marks_input): db.insert_record(id_input, name_input, marks_input) add_window.destroy() update_table()