def add_event(self, calendar_date: DateTypes, name: str): """ Adds an event to the calendar Args: calendar_date : date of the new event name : name of that event """ while name in self.find_events(calendar_date).keys(): overwrite = input( f"Another event is named {name} on that date. Do you wish to overwrite it? (Y/n) : " f"Other event : {self.get_event(calendar_date, name)}\n") overwrite = overwrite.upper() != "N" if not overwrite: name = input(f"Please enter a new name for the event : ") else: break description = input("Give us a brief description of the event : \n") if input("Do you wish to specify a time? (y/N)").upper() != "Y": self.events[self.ind_from_date(calendar_date, name)] = Event( calendar_date, name, description, ) else: self.events[self.ind_from_date(calendar_date, name)] = Event( calendar_date, name, description, prompt_user_time("What time do you want to set?"))
def __init__(self, name=None, shouldSetup=False): self.connection_status = 'not connected' self.ser = serial.Serial(timeout=1, write_timeout=1) self.sent_command_event = Event() self.emulator_mode = False if not name: self.name = 'Mysterial Serial Device' else: self.name = name if shouldSetup: self.Setup()
def get_timeline(self, issue): timeline = self._get_timeline_from_db(issue) if (timeline is not None and dateutil.parser.parse(issue.updated_at) <= dateutil.parser.parse(timeline['date'])): print 'HIT CACHE!!!' for event in json.loads(timeline['timeline']): yield Event.from_json(event) else: timeline = self._get_timeline_from_internet(issue) to_write = json.dumps([x.event for x in timeline]) print 'REPLACING CACHED ITEM!!!' self._insert_or_replace_timeline_in_db(issue, to_write) for event in timeline: yield Event.from_json(event)
def __call__(self, attrib): if not self.name: self.name = self._getName(attrib) if self._addUpdateEvent: self.updateEventSlot = initBy(initFunc=lambda inst: Event(), name="%s_updateEvent" % self.name) self.value = attrib return self
def __init__(self,delay=1.1): self.current_pos = SystemPosition(0,0,0,0,0,0,0,0) self.msg = None self.isActive = False self.axis_threshold = 0.1 #self.HandleInput() self.delay = delay self.axis_moved_event = Event() self.button_press_event = Event() self.button_release_event = Event() th = threading.Thread(target=self.HandleInput) th.start()
def _get_timeline_from_internet(self, issue): headers = {'Accept': 'application/vnd.github.mockingbird-preview'} url = self._url + '/repos/%s/issues/%d/timeline' % (issue.repo, issue.number) while url is not None: response = requests.get(url, headers=headers, auth=self._auth) url = None if response.status_code != 200: raise Exception(response.json()) if 'Link' in response.headers: url = re.split('<|>', [ link for link in response.headers['Link'].split(',') if link[-10:] == 'rel="next"' ][0])[1] for event in response.json(): yield Event.from_json(event)
def onClear(self): return Event() # () def __getitem__(self, index):
def onRemove(self): return Event() # (index) @initBy
def onInsert(self): return Event() # (index, value) @initBy
def _updateEvent(self): return Event()
while (i < 48): #loops through all times a = 0 while (a < timeUnits and a < len(bestTimes)): if i == bestTimes[a]: goodTimes.append(i) a = a + 1 i = i + 0.5 return goodTimes calendar = Calendar() firstMeeting = Event("Meeting", datetime(2019, 1, 4, 15, 30), 30) secondHomework = Event("Homework", datetime(2019, 1, 6, 12, 00), 60) thirdHomework = Event("Homework", datetime(2019, 1, 8, 15, 30), 30) fourthHomework = Event("Homework", datetime(2019, 1, 11, 15, 20), 30) fifthHomework = Event("Homework", datetime(2019, 1, 13, 12, 00), 60) sixthHomework = Event("Homework", datetime(2019, 1, 15, 15, 30), 30) monday = Day('Monday') tuesday = Day('Tuesday') wednesday = Day('Wednesday') thursday = Day('Thursday') friday = Day('Friday') saturday = Day('Saturday') sunday = Day("Sunday") monday.time_slots = {
@app.route("/show_img/<img_id>") async def show_image(img_id): with sqlite3.connect("main.sqlite") as conn: c = conn.cursor() if not c.execute(f"SELECT * FROM image WHERE id='{img_id}'").fetchone(): abort(404) return await render_template("Image/show_img.html", image=img_id, ext=c.execute(f"SELECT * FROM image WHERE id='{img_id}'").fetchone()[1]) @client.command() async def get_img(ctx, img_id): with sqlite3.connect("main.sqlite") as conn: c = conn.cursor() r = c.execute(f"SELECT * FROM image WHERE id='{img_id}'").fetchone() if not r: return await ctx.send("Image ID {} not found.".format(r[0])) await ctx.send(file=discord.File(f"./static/upload/image/{img_id}{r[1]}")) @app.errorhandler(flask_discord.exceptions.AccessDenied) async def access_denied(): pass app.jinja_env.globals.update(check_user=check_user) client.add_cog(Event(client)) app.run(host=gethostbyname(gethostname()), port=80, loop=l, start_now=False) client.run(data["TOKEN"])
if __name__ == "__main__": userBuilder = UserBuilder() user1 = userBuilder.create_user_full("A12345", "Kevin", "Bhunut", "*****@*****.**") print(user1) # Getting list of events that the users ha # ve events = user1.get_events() # Initialize Recommendation Engine events.attach(RecommendationEngineA()) # Create New Event event = Event(1234, "Cat Adoption Event") event.set_startDate( datetime.strptime("Dec 10 2020 10:30AM", '%b %d %Y %I:%M%p')) event.set_endDate( datetime.strptime("Dec 10 2020 6:00PM", '%b %d %Y %I:%M%p')) event.set_location("San Francisco, CA") # Invitation event.append_invitation(Invitation("1234", "A12345")) print(event.get_invitation_list()[0]) events.append(event) print(event) # Change Invitation Reponse print("Accepting Invite") response1 = event.get_invitation_list()[0]
class DeviceManagerBase(): def __init__(self, name=None, shouldSetup=False): self.connection_status = 'not connected' self.ser = serial.Serial(timeout=1, write_timeout=1) self.sent_command_event = Event() self.emulator_mode = False if not name: self.name = 'Mysterial Serial Device' else: self.name = name if shouldSetup: self.Setup() def ConnectToDevice(self, defPort=None, baud=9600, qrymsg=b'ping', retmsg='pong', trycount=1, ports=sc.serial_ports(), readsequence='\n'): if self.emulator_mode: print('starting in emulator mode') elif self.ser.is_open: print('already connected') else: print('attempting to connect to Device: %s' % self.name) s = sc.ping_controller(defPort, ports, baud, qrymsg, retmsg, trycount, readsequence) self.ser.port = s self.ser.baudrate = baud self.ser.open() self.connection_status = 'connected' return s def WaitForResponse(self, response='ok'): DeviceNotBusy = False while (DeviceNotBusy != True): ret = self.ser.readline().decode().rstrip() print('WaitForResponse: ', ret) if (response in ret): DeviceNotBusy = True print("got the response: " + response) def SendCommand(self, com, waitMsg=None, term="\n"): if not self.emulator_mode: print('Device %s sending command: %s' % (self.name, com)) self.sent_command_event.notify(com) command = str(com) + term self.ser.write(command.encode()) if waitMsg: print('waitMsg: ', waitMsg) self.WaitForResponse() #workaround to trigger busy:processing response from Marlin if waitMsg == 'M84\n': self.ser.write(waitMsg.encode()) self.WaitForResponse() else: print('Emulator %s sending command: %s' % (self.name, com)) self.sent_command_event.notify(com) def SetInitialState(self): raise NotImplementedError() def Setup(self): raise NotImplementedError()
class Xbox_Interface: def __init__(self,delay=1.1): self.current_pos = SystemPosition(0,0,0,0,0,0,0,0) self.msg = None self.isActive = False self.axis_threshold = 0.1 #self.HandleInput() self.delay = delay self.axis_moved_event = Event() self.button_press_event = Event() self.button_release_event = Event() th = threading.Thread(target=self.HandleInput) th.start() def get_pos(self): return self.current_pos def get_msg(self): return self.msg def HandleInput(self): try: self.isActive = True with Xbox360Controller(0, axis_threshold=0.0) as controller: # Button A events controller.button_a.when_pressed = self.on_button_pressed controller.button_a.when_released = self.on_button_released # Button B events controller.button_b.when_pressed = self.on_button_pressed controller.button_b.when_released = self.on_button_released # Button Y events controller.button_y.when_pressed = self.on_button_pressed controller.button_y.when_released = self.on_button_released # Button X events controller.button_x.when_pressed = self.on_button_pressed controller.button_x.when_released = self.on_button_released # Button Trigger L events controller.button_trigger_l.when_pressed = self.on_button_pressed # Button Trigger R events controller.button_trigger_r.when_pressed = self.on_button_pressed # Button Thumb L events controller.button_thumb_l.when_pressed = self.on_button_pressed # Button Thumb R events controller.button_thumb_r.when_pressed = self.on_button_pressed # Start Button events controller.button_start.when_pressed = self.on_button_pressed # Left and right axis move event controller.axis_l.when_moved = self.on_axis_moved controller.axis_r.when_moved = self.on_axis_moved signal.pause() except KeyboardInterrupt: self.isActive = False pass #button Y:pump0, B:pump1, A:pump2 def on_button_pressed(self, button): print('Button {0} was pressed'.format(button.name)) self.button_press_event.notify(button) def on_button_released(self, button): print('Button {0} was released'.format(button.name)) self.button_release_event.notify(button) def on_axis_moved(self, axis): #print('Axis {0} moved to {1} {2}'.format(axis.name, axis.x, axis.y)) if(abs(axis.x)>self.axis_threshold): self.axis_moved_event.notify(axis) elif(abs(axis.y)>self.axis_threshold): self.axis_moved_event.notify(axis)
class Calendar: def __init__(self): self.week1 = Week() self.week2 = Week() self.week3 = Week() self.week4 = Week() self.week5 = Week() # -- pre-populated data -- calendar = Calendar() firstHomework = Event("Homework", datetime(2019, 1, 4, 15, 30), 30) secondHomework = Event("Homework", datetime(2019, 1, 6, 12, 00), 60) thirdHomework = Event("Homework", datetime(2019, 1, 8, 15, 30), 30) fourthHomework = Event("Homework", datetime(2019, 1, 11, 15, 20), 30) fifthHomework = Event("Homework", datetime(2019, 1, 13, 12, 00), 60) sixthHomework = Event("Homework", datetime(2019, 1, 15, 15, 30), 30) calendar.week1.test calendar.week1.Friday.time_slots.append(firstHomework) calendar.week2.Sunday.time_slots.append(secondHomework) calendar.week2.Tuesday.time_slots.append(thirdHomework) calendar.week2.Friday.time_slots.append(fourthHomework) calendar.week3.Sunday.time_slots.append(fifthHomework) calendar.week3.Tuesday.time_slots.append(sixthHomework) firstTestPrep = Event("TestPrep", datetime(2019, 1, 5, 19, 00), 30)
def curSelectedSong_updateEvent(self): return Event()
def _updateEvent(self): return Event() def __init__(self, *args, **kwargs): # we must support an empty init for PersistentObject
def onClear(self): return Event() # () def insert(self, index, value):