Spaces:
Sleeping

File size: 1,369 Bytes
739f8ba
 
 
 
 
 
25ec9dc
 
739f8ba
 
 
25ec9dc
 
 
 
 
 
 
 
 
 
 
 
 
 
739f8ba
25ec9dc
 
 
739f8ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import streamlit as st
import time
import datetime
from sqlalchemy import create_engine
import pandas as pd

from sqlalchemy import create_engine, MetaData, Table, Column, Integer, DateTime

# Database connection
engine = create_engine('sqlite:///date_time.db')

# Define a table object using SQLAlchemy's Table construct
metadata = MetaData()
date_table = Table(
    'date_table', metadata,
    Column('id', Integer, primary_key=True),
    Column('date_time', DateTime)
)

# Create the table in the database
metadata.create_all(engine)
# Database connection

#engine = create_engine('sqlite:///date_time.db')

# Create a table in the database to store the date and time

#with engine.connect() as con:
    #con.execute('CREATE TABLE IF NOT EXISTS date_table (id INTEGER PRIMARY KEY, date_time TIMESTAMP)')

# Function to save date and time to the database
def save_to_database():
    with engine.connect() as con:
        con.execute("INSERT INTO date_table (date_time) VALUES (?)", datetime.datetime.now())

# Streamlit app
st.title('Date and Time Saver')

# Button to start the loop
start_button = st.button('Save Date and Time')

# Loop to save the date and time to the database every 2 minutes
if start_button:
    st.write('Saving date and time every 2 minutes...')
    while start_button:
        save_to_database()
        time.sleep(120)  # Sleep for 2 minutes