def fetchRandom(): #random 1 to 30 return that as json scrape_time = datetime.datetime.now().strftime("%Y_%m_%d_%H") rank = random.randint(1,30) if not database.tableExists(scrape_time): database.createTable(scrape_time) database.write(scrape_time,final) data = database.read(scrape_time,rank) return {"rank": data[0], "title": data[1], "time": data[2]}
def onConfirm(self, event): #create case dir dirPath = self.txtCaseFolder.GetValue() #get case folder path casePath = Path(dirPath) if casePath.is_dir(): #check if it exist print("dir exist") else: os.mkdir(dirPath) #create if does not #create case database dbFilePath = self.txtCaseDb.GetValue() #get case database path my_file = Path(dbFilePath) #print(dbFilePath) if my_file.is_file(): #check if file exist print("file exist") else: conn = connectdb.create_connection(dbFilePath) #creates db file and connection if it does not exist caseInfoTable = "CREATE TABLE 'CaseInfo' ( 'CaseID' INTEGER PRIMARY KEY AUTOINCREMENT, 'InvestigatorName' TEXT, 'CaseNum' INTEGER, 'CaseName' TEXT, 'CaseFolder' TEXT, 'CaseDb' TEXT, 'CaseDesc' TEXT, 'Datetime' TEXT);" evidenceInfoTable = "CREATE TABLE 'EvidenceInfo' ('CaseID' INTEGER, 'EvidenceName' TEXT, 'EvidenceDbPath' TEXT, 'EvidenceDatetime' TEXT, 'Md5' TEXT, 'EvidencePath' TEXT, 'EvidenceSize' TEXT);" bookmarksTable = "CREATE TABLE 'Bookmarks' ('fileName' TEXT, 'ctime' TEXT, 'crtime' TEXT, 'atime' TEXT, 'mtime' TEXT, 'uid' INTEGER, 'gid' INTEGER, 'md5' TEXT, 'size' INTEGER, 'parentPath' TEXT, 'extension' TEXT, 'image' TEXT);" connectdb.createTable(conn, caseInfoTable) #creates CaseInfo table connectdb.createTable(conn, evidenceInfoTable) #creates EvidenceInfo table connectdb.createTable(conn, bookmarksTable) #creates Bookmarsk table connectdb.createFilesEvidenceTable(conn) connectdb.createSessionsEvidenceTable(conn) connectdb.createDNSEvidenceTable(conn) connectdb.createCredentialsEvidenceTable(conn) #insert case details with conn: caseDetails = (self.txtInvestigatorName.GetValue(), self.txtCaseNum.GetValue(), self.txtCaseName.GetValue(), self.txtCaseFolder.GetValue(), self.txtCaseDb.GetValue(), self.txtCaseDescription.GetValue(), datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) connectdb.insertCaseDetails(conn, caseDetails) #insert case details to CaseInfo self.Close()
import database as db db = db.Database("python_crud_oop") db.setLocalhost("localhost") db.setUsername("root") db.setPassword("") db.createDatabase() db.setTableName("customers") db.createTable()
# Create the 'Add sample' dialog - the window where samples can be added def showAddSampleDialog(self): self.AddSampleDialog = AddSampleDialog() # closes the 'Add sample' dialog when the main window is closed def closeEvent(self, QCloseEvent): if hasattr(self, 'AddSampleDialog'): self.AddSampleDialog.close() if __name__ == '__main__': sample_db = sqlite3.connect(DATABASE_NAME) cursor = sample_db.cursor() database.createTable(cursor) data = database.getAllData(cursor) # instantiate all major objects; SAMPLES contains all stored samples SAMPLES = SampleLibrary() app = QApplication(sys.argv) main_window = MainWindow() # load samples from database into SAMPLES object and main window for sample in data: SAMPLES.addSample(sample[0], sample[1], sample[2]) main_window.addSample(sample[0]) # TODO: figure out how to simultaneously close db connection sys.exit(app.exec_())
Your selection: """ welcome = "Welcome to programming progress diary!" def prompt_new_entry(): entry_content = input("What did you learn today?") entry_date = input("Enter date: ") add_entry(entry_content, entry_date) def view_entries(entries): for entry in entries: print(f"{entry['entry_date']}\n{entry['entry_content']}\n\n") print(welcome) createTable() user_input = input(menu) while user_input != 3: if user_input == "1": prompt_new_entry() elif user_input == "2": view_entries(get_entries()) elif user_input == "3": break else: print("Please enter either 1, 2, or 3") user_input = input(menu)
self.setCentralWidget(self.tabWidget) mainPanel = MainPanel(self.tabWidget) self.tabWidget.addTab(mainPanel, 'Main Panel') self.resize(942, 563) def closeEvent(self, event): self.tabWidget.clear() if __name__ == '__main__': app = QApplication(sys.argv) main = MainContainer() # Enable plugins here will make activex turn on, it's important to taobao security activex control QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, True) QWebSettings.globalSettings().setAttribute(QWebSettings.AutoLoadImages, False) QWebSettings.globalSettings().enablePersistentStorage(StoragePath) # Uncomment thhis line for test purpose only. # database.db_location = './storage/database_test' # create table if there is no table. if not os.path.exists(database.db_location): database.createTable() main.setWindowTitle(u'淘宝随意拍') main.show() app.exec_()
import uuid import time import database ENUMS = {"NOTE_DATABASE_FILE": "data/notes", "NOTE_TABLE_NAME": "notes"} notes = {} database.createTable( ENUMS["NOTE_DATABASE_FILE"], ENUMS["NOTE_TABLE_NAME"], "uid TEXT NOT NULL PRIMARY KEY, content TEXT, timestamp sqlite3_uint64") class Note: def __init__(self, content, timestamp=time.time(), uid=uuid.uuid4(), exists=False): self.uid = uid self.content = content self.timestamp = timestamp if not exists: database.setQuery( ENUMS["NOTE_DATABASE_FILE"], "INSERT INTO {0} VALUES ('{1}', '{2}', {3})".format( ENUMS["NOTE_TABLE_NAME"], self.getUID(), self.getContent(), self.getTimestamp())) notes[self.getUID()] = self
sys.path.append(os.path.dirname(os.path.realpath('src/db/databse.py'))) import api as api import database as database import dht11sensor as dht11sensor import flamesensor as flamesensor import gassensor as gassensor import irsensor as irsensor import ultrasonicsensor as ultrasonicsensor # import pirsensor as pirsensor GPIO.setwarnings(False) GPIO.setmode(GPIO.BCM) GPIO.cleanup() database.createTable() while True: sensors = api.readDataFromServer() for sensor in sensors: if sensor["sensor"] == "temperature" and sensor["isEnabled"] == True: dht11Object = dht11.DHT11(pin=sensor["pin"]) dht11sensor.readTemperatureSensorData(dht11Object.read()) if sensor["sensor"] == "humidity" and sensor["isEnabled"] == True: dht11Object = dht11.DHT11(pin=sensor["pin"]) dht11sensor.readhumiditySensorData(dht11Object.read()) if sensor["sensor"] == "infrared" and sensor["isEnabled"] == True: GPIO.setup(sensor["pin"], GPIO.IN) irsensor.readSensorData(GPIO.input(sensor["pin"])) if sensor["sensor"] == "gas" and sensor["isEnabled"] == True: GPIO.setup(sensor["pin"], GPIO.IN)
import database TABLENAME = 'customers' # Creating the table names = database.listTables() if TABLENAME not in names: database.createTable(TABLENAME) else: print(f"SKIPPING - TABLE ALREADY EXISTS - {names} \n") dataList = [ ('Sipra Banerjee', '*****@*****.**', 9831790182, 55), ('Subir Banerjee', '*****@*****.**', 9831626265, 62), ('Swapna Mitra', '*****@*****.**', 9433851479, 57), ('Subhadeep Banerjee', '*****@*****.**', 7980207055, 21) ] database.insertData(TABLENAME, dataList=dataList) database.showAll(TABLENAME) dataList = [ ('Subhadeep Banerjee', '*****@*****.**', 7980207055, 21), ('Ria Gupta', '*****@*****.**', 5123456891, 22), ('Souma Mitra', '*****@*****.**', 6444848265, 21), ] database.insertData(TABLENAME, dataList=dataList) database.showAll(TABLENAME) data = ('Ria Gupta', '*****@*****.**', 5123456891, 22)