Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
majorbruteforce committed Jun 1, 2024
2 parents 3096e97 + ee4fc59 commit f1e0a49
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions time_check.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
from datetime import datetime, time, timedelta
import pytz
from db import connect_to_database
initial = 15
final= 18
initial = 16
final= 12

def is_in_time_bracket(msg_sending_time):

ist = pytz.timezone('Asia/Kolkata')
msg_sending_time_ist = msg_sending_time.astimezone(ist)
msg_time = msg_sending_time_ist.time()


start_time = time(initial, 0)
end_time = time(final, 0)

if msg_sending_time_ist.time() >= start_time or msg_sending_time_ist.time() < end_time:
start_time = time(initial, 0)
end_time = time(final, 0)

if start_time <= msg_time or msg_time <= end_time:
return True
return False


def is_unique_in_time_bracket(discord_user_id, msg_sending_time):
conn = connect_to_database()
cur = conn.cursor()

ist = pytz.timezone('Asia/Kolkata')

msg_sending_time_ist = msg_sending_time.astimezone(ist)
msg_sending_date_ist = msg_sending_time_ist.date()

bracket_start = ist.localize(datetime.combine(msg_sending_date_ist, time(initial, 0)))
bracket_end = ist.localize(datetime.combine(msg_sending_date_ist + timedelta(days=1), time(final, 0)))

if msg_sending_time_ist.time() >= time(initial, 0):
bracket_start = msg_sending_time_ist.replace(hour=initial, minute=0, second=0, microsecond=0)
bracket_end = (bracket_start + timedelta(hours=14)).replace(hour=final, minute=0, second=0, microsecond=0)
else:
bracket_start = (msg_sending_time_ist.replace(hour=initial, minute=0, second=0, microsecond=0) - timedelta(days=1))
bracket_end = msg_sending_time_ist.replace(hour=final, minute=0, second=0, microsecond=0)
print(f"Bracket start: {bracket_start}, Bracket end: {bracket_end}")

cur.execute("""
SELECT COUNT(*)
Expand All @@ -41,10 +40,13 @@ def is_unique_in_time_bracket(discord_user_id, msg_sending_time):

result = cur.fetchone()
cur.close()
conn.close()

print(f"Query result: {result}")

if result[0] > 0:
return False

return True

def can_send_message(discord_user_id, msg_sending_time):
Expand Down

0 comments on commit f1e0a49

Please sign in to comment.