In an oil and gas context, create an application to register post card.
To upload files, please first save the app
import streamlit as st
from datetime import datetime
from sqlalchemy import create_engine, Column, Integer, String, DateTime, Text
from sqlalchemy.orm import Session, DeclarativeBase
# Database setup
class Base(DeclarativeBase):
pass
class PostCard(Base):
__tablename__ = "postcards"
id = Column(Integer, primary_key=True)
date = Column(DateTime, nullable=False)
well_name = Column(String(100), nullable=False)
field = Column(String(100), nullable=False)
operator = Column(String(100), nullable=False)
rig_contractor = Column(String(100))
current_depth = Column(Integer)
formation = Column(String(100))
operation = Column(Text)
comments = Column(Text)
# Create database and tables
engine = create_engine("sqlite:///oilgas_postcards.sqlite")
Base.metadata.create_all(bind=engine)
# Streamlit UI
st.title("Oil & Gas Post Card Registration")
with st.form("postcard_form"):
st.subheader("Well Information")
col1, col2 = st.columns(2)
with col1:
date = st.date_input("Date", datetime.now())
well_name = st.text_input("Well Name")
field = st.text_input("Field")
operator = st.text_input("Operator")
with col2:
rig_contractor = st.text_input("Rig Contractor")
current_depth = st.number_input("Current Depth (ft)", min_value=0)
formation = st.text_input("Current Formation")
st.subheader("Operations")
operation = st.text_area("Current Operations")
comments = st.text_area("Comments/Observations")
submitted = st.form_submit_button("Submit Post Card")
if submitted:
if not well_name or not field or not operator:
st.error("Please fill in all required fields: Well Name, Field, and Operator")
else:
# Create new post card entry
new_postcard = PostCard(
date=datetime.combine(date, datetime.min.time()),
well_name=well_name,
field=field,
operator=operator,
rig_contractor=rig_contractor,
current_depth=current_depth,
formation=formation,
operation=operation,
comments=comments
)
# Save to database
with Session(engine) as session:
session.add(new_postcard)
session.commit()
st.success("Post Card successfully registered!")
st.balloons()
# Display existing postcards
st.subheader("Recent Post Cards")
with Session(engine) as session:
recent_postcards = session.query(PostCard).order_by(PostCard.date.desc()).limit(5).all()
if recent_postcards:
for card in recent_postcards:
with st.expander(f"{card.well_name} - {card.date.strftime('%Y-%m-%d')}"):
st.write(f"**Field:** {card.field}")
st.write(f"**Operator:** {card.operator}")
st.write(f"**Rig Contractor:** {card.rig_contractor}")
st.write(f"**Current Depth:** {card.current_depth} ft")
st.write(f"**Formation:** {card.formation}")
st.write("**Current Operations:**")
st.write(card.operation)
st.write("**Comments:**")
st.write(card.comments)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?