Skip to content

Instantly share code, notes, and snippets.

@itspacchu
Created August 7, 2021 06:57
Show Gist options
  • Save itspacchu/7562defc9d4315b421461a109ef52d64 to your computer and use it in GitHub Desktop.
Save itspacchu/7562defc9d4315b421461a109ef52d64 to your computer and use it in GitHub Desktop.
fetch classes
import discord
from discord.ext import commands
from datetime import datetime, time, timedelta
import asyncio
from livclaz import create_calender_event_and_return_values
from discord.ext.commands.core import command
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(command_prefix=['p.', '_'], intents=intents)
client.remove_command('help')
dm = "" # pacchu dm
user = None
def utcnow_timenow():
nin = datetime.utcnow()
return time(nin.hour, nin.minute, nin.second)
@client.event
async def on_ready():
global user
user = client.get_user(int(dm))
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="over Pacchu's Classes"))
client.loop.create_task(backtask())
WHEN = time(14, 0, 0)
SCANTIME = time(19,30,0)
SCANTIME_1 = time(19, 31, 0)
"""async def called_once_a_day():
global WHEN
await client.wait_until_ready()
channel = client.get_channel(channel_id)
create_calender_event_and_return_values(cal_event=False)
await user.send()"""
async def the_task():
while(True):
pass
#forever loop
async def backtask():
hours, mins, day, start, hh, mm, AM_PM,link = 0, 0, 0, 0, 0, 0, 0, "kek"
await user.send("Hello")
while(True):
# hh and mm are UTC time stuff 1 AM make calender event
if(utcnow_timenow() > SCANTIME and utcnow_timenow() < SCANTIME_1):
await user.send("Going to fetch classes for today okay")
hours, mins, day, start, hh, mm, AM_PM , link = create_calender_event_and_return_values()
elif(utcnow_timenow() > time(hh, mm, 00) and utcnow_timenow() < time(hh, mm+1, 00)): # send the event now
hours, mins, day, start, hh, mm, AM_PM , link = create_calender_event_and_return_values(cal_event = False , fetchLink=True)
await user.send(f"Your class is starting now mate for {hours}hours .. here's the link --> {link}")
elif(hh == 0 and mm == 0):
if(link == "kek"):
param = True
else:
param = False
hours, mins, day, start, hh, mm, AM_PM , link = create_calender_event_and_return_values(cal_event=False,fetchLink=param)
#await user.send(datetime.utcnow())
await asyncio.sleep(120)
client.run('')
def time_in_range(start, end, x):
"""Return true if x is in the range [start, end]"""
if start <= end:
return start <= x <= end
else:
return start <= x or x <= end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment