def insert(self, chan): c = Channel() c.name = chan['Name'] c.stream = chan['Stream'] c.url = chan['Url'] c.logo = chan['Logo'] c.feed = chan['Feed'] self.db.session.add(c) try: self.db.session.commit() except IntegrityError as e: self.db.session.rollback()
def post(self): """Handles a POST to the /channel/ resource Creates a new channel resource (/channel/{id}) and returns its Location with a 201 """ channel = Channel() name = self.request.get('name').rstrip('\n') channel.name = name channel.put() # Not sure I like this ... re-put()ing if len(channel.name) == 0: channel.name = 'channel-' + str(channel.key().id()) channel.put() # If we've got here from a web form, redirect the user to the # channel list, otherwise return the 201 if self.request.get('channelsubmissionform'): self.redirect('/channel/') else: self.response.headers['Location'] = self.request.url + str(channel.key().id()) + '/' self.response.set_status(201)
def create_channel(session, station_id, client_id=None, name="TestChannel"): channel = Channel() channel.station_id = station_id channel.name = name channel.ecc_id = 159 channel.frequency = "00917" channel.pi = "C00F" channel.type_id = "fm" if client_id: channel.fk_client = client_id session.add(channel) session.commit() time.sleep(config.SPI_GENERATION_INTERVAL * 3) return channel
def request_chat(): request_data = request.get_json() from_user = request_data.get('from_user', '') to_user = request_data.get('to_user', '') to_user_channel = "private-notification_user_%s" % (to_user) from_user_channel = "private-notification_user_%s" % (from_user) try: bot = User.query.filter(User.id == to_user).one() except NoResultFound: print('Error! No bot (yet).') except MultipleResultsFound: print('Error! Wait what?') try: yolo.get_model(bot.username) except: print('Error! Cannot load model!') # check if there is a channel that already exists between this two user channel = Channel.query.filter( Channel.from_user.in_([from_user, to_user]) ) \ .filter( Channel.to_user.in_([from_user, to_user]) ) \ .first() if not channel: # Generate a channel... chat_channel = "private-chat_%s_%s" % (from_user, to_user) new_channel = Channel() new_channel.from_user = from_user new_channel.to_user = to_user new_channel.name = chat_channel db_session.add(new_channel) db_session.commit() else: # Use the channel name stored on the database chat_channel = channel.name data = { "from_user": from_user, "to_user": to_user, "from_user_notification_channel": from_user_channel, "to_user_notification_channel": to_user_channel, "channel_name": chat_channel, } # Trigger an event to the other user pusher.trigger(to_user_channel, 'new_chat', data) return jsonify(data)
def post(self): request_data = request.get_json() from_user = request_data.get('from_user', '') to_user = request_data.get('to_user', '') #to_user_channel = "private-notification_user_%s" % (to_user) #from_user_channel = "private-notification_user_%s" % (from_user) # check if there is a channel that already exists between this two user channel = Channel.query.filter(Channel.from_user.in_([from_user, to_user])) \ .filter(Channel.to_user.in_([from_user, to_user])) \ .first() if not channel: # Generate a channel... chat_channel = "private-chat_%s_%s" % (from_user, to_user) new_channel = Channel() new_channel.from_user = from_user new_channel.to_user = to_user new_channel.name = chat_channel db_session.add(new_channel) db_session.commit() db_session.remove() else: # Use the channel name stored on the database chat_channel = channel.id data = { "from_user": from_user, "to_user": to_user, #"from_user_notification_channel": from_user_channel, #"to_user_notification_channel": to_user_channel, "channel_name": chat_channel, } # Trigger an event to the other user #pusher.trigger(to_user_channel, 'new_chat', data) return make_response(jsonify(data))
def request_chat(): request_data = request.get_json() from_user = request_data.get('from_user', '') to_user = request_data.get('to_user', '') to_user_channel = "private-notification_user_%s" % (to_user) from_user_channel = "private-notification_user_%s" % (from_user) # check if a channel exists between the two users channel = Channel.query.filter(Channel.from_user.in_([from_user, to_user])) \ .filter(Channel.to_user.in_([from_user, to_user])) \ .first() if not channel: # generate new channel chat_channel = "private-chat_%s_%s" % (from_user, to_user) new_channel = Channel() new_channel.from_user = from_user new_channel.to_user = to_user new_channel.name = chat_channel db_session.add(new_channel) db_session.commit() else: # Use existing channel chat_channel = channel.name data = { "from_user": from_user, "to_user": to_user, "from_user_notification_channel": from_user_channel, "to_user_notification_channel": to_user_channel, "channel_name": chat_channel, } # an event is triggered to the other use pusher.trigger(to_user_channel, 'new_chat', data) return jsonify(data)
def get_channel_entity(some_id): if not some_id: return None exist_channel = None if type(some_id) == int: exist_channel = session.query(Channel).filter_by(id=int(some_id)).first() if not exist_channel: exist_channel = session.query(Channel).filter_by(name=some_id).first() channel_dict = dict() if exist_channel: channel_dict['id'] = exist_channel.id channel_dict['name'] = exist_channel.name else: channel = client.get_entity(some_id) new_channel = Channel() new_channel.id = channel.id print(channel) new_channel.name = channel.title session.add(new_channel) session.commit() channel_dict['id'] = new_channel.id channel_dict['name'] = new_channel.name return channel_dict
def string_to_channel(linedata, station): object = Channel() object.station_id = station # Split line data = linedata.split(',') if len(data) < 2: return None # Define Type object.name = data[0] object.type_id = data[1] # FM # name fm ecc pid frequency if object.type_id == 'fm': if len(data) < 5: return None # ECC cc_obj = Ecc.query.filter_by(iso=data[2].upper()).first() if not cc_obj: ecc_pi = data[2][:1].upper() ecc_ecc = data[2][1:].upper() cc_obj = Ecc.query.filter_by(pi=ecc_pi, ecc=ecc_ecc).first() if cc_obj: object.ecc_id = cc_obj.id # PI object.pi = data[3] object.frequency = data[4] # DAB # name dab ecc eid sid scids UAType PA elif object.type_id == 'dab': if len(data) < 6: return None # ECC cc_obj = Ecc.query.filter_by(iso=data[2].upper()).first() if not cc_obj: ecc_pi = data[2][:1].upper() ecc_ecc = data[2][1:].upper() cc_obj = Ecc.query.filter_by(pi=ecc_pi, ecc=ecc_ecc).first() if cc_obj: object.ecc_id = cc_obj.id # eid object.eid = data[3] object.sid = data[4] object.scids = data[5] # Optional Elements if len(data) >= 7: object.appty_uatype = data[6] if len(data) >= 8: object.pa = data[7] # DRM # name drm sid elif object.type_id == 'drm': if len(data) < 3: return None # sid object.sid = data[2] # AMSS elif object.type_id == 'amss': if len(data) < 3: return None # sid object.sid = data[2] # HD Radio # name hd cc tx elif object.type_id == 'hd': if len(data) < 4: return None # cc object.cc = data[2] object.tx = data[3] # IP # name ip fqdn service id elif object.type_id == 'ip': if len(data) < 4: return None # cc object.fqdn = data[2] object.serviceIdentifier = data[3] else: return None return object