Code: Select all
def extract_signal_data(message):
signal_data = {}
bla bla bla and a very long code
message_date_ist = message_date_utc.astimezone(indian_tz) # Convert to IST
signal_data['date'] = message_date_ist.strftime('%d-%b-%y') # Format date to 'DD-MMM-YY'
signal_data['time'] = message_date_ist.strftime('%H:%M:%S') # Only the time part
signal_data['message_id'] = message.id
print(f"Converted Message Date (UTC): {message_date_utc.strftime('%Y-%m-%d %H:%M:%S')}")
print(f"Converted Message Date (IST): {message_date_ist.strftime('%Y-%m-%d %H:%M:%S')}")
except Exception as e:
print(f"Error extracting data from message {message.id}: {e}")
return signal_data
Ich versuche, in einer anderen Funktion darauf zuzugreifen
Code: Select all
def bla bla bla():
# Update reply date, days active, and times
reply_date = response_message.date
reply_time = reply_date.strftime('%H:%M:%S') # Extract time in HH:MM:SS format
reply_date_naive = reply_date.replace(tzinfo=None) # Convert to naive datetime
signal_date_str = signal_data['date'] + " " + signal_data['time']
# Convert the "Time Exited" to IST
indian_tz = pytz.timezone('Asia/Kolkata')
if reply_date.tzinfo is None:
reply_date_utc = reply_date.replace(tzinfo=pytz.utc)
else:
reply_date_utc = reply_date # Already timezone-aware
reply_date_ist = reply_date_utc.astimezone(indian_tz)
# Populate "Time Exited" in IST
time_exited_cell.value = reply_date_ist.strftime('%H:%M:%S') # Format time to HH:MM:SS
signal_date_cell = ws.cell(row=row, column=2) # Assuming "Signal Date" is column 2
signal_date = datetime.strptime(signal_date_cell.value, '%d-%b-%y')
days_active = (reply_date_naive - signal_date).days
ws.cell(row=row, column=11, value=reply_date_naive.strftime('%d-%b-%y')) # Update reply date (column 11)
ws.cell(row=row, column=12, value=days_active) # Update days active (column 12)
# Populate "Time Entered" as Signal Date + Time
if not time_entered_cell.value:
# Combine Signal Date and the Time Entered (time extracted from the original message)
#signal_time = signal_date_cell.value + " " + reply_time # Format as "DD-MMM-YY HH:MM:SS"
signal_date_str = signal_data['date'] + ' ' + signal_data['time']
signal_time = signal_date_str
# Convert to datetime to adjust the time
signal_datetime = datetime.strptime(signal_time, '%d-%b-%y %H:%M:%S')
Code: Select all
signal_time = signal_date_cell.value + " " + reply_time # Format as "DD-MMM-YY HH:MM:SS"
Code: Select all
signal_date_str = signal_data['date'] + ' ' + signal_data['time']
signal_time = signal_date_str
Jede Hilfe wäre sehr dankbar. Danke!