Beispiel #1
0
 def offline(self, request, msisdn='', local='no'):
     api_log.info('%s - [PUT] %s/offline Data: msisdn: "%s"',
                  request.getClientIP(), self.path, msisdn)
     try:
         sub = Subscriber()
         sub.expire_lu(msisdn)
         data = {'status': 'success', 'error': ''}
     except SubscriberException as e:
         data = {'status': 'failed', 'error': str(e)}
         api_log.debug(data)
         return data
     # Take advantage to point this subscriber to the new location in our hlr
     # so we (at least) don't have to wait for the next hlr sync run
     try:
         if local == 'yes':
             current_bts = config['local_ip']
         else:
             current_bts = request.getClientIP()
         cur = db_conn.cursor()
         now = datetime.datetime.fromtimestamp(int(time.time()))
         cur.execute(
             'UPDATE hlr SET current_bts=%(current_bts)s, updated=%(updated)s WHERE msisdn=%(msisdn)s',
             {
                 'msisdn': msisdn,
                 'current_bts': current_bts,
                 'updated': now
             })
         db_conn.commit()
     except psycopg2.DatabaseError as e:
         data = {'status': 'failed', 'error': str(e)}
         api_log.debug(data)
         return data
     api_log.debug(data)
     return data
Beispiel #2
0
 def add_states_district(self, state_id, district_id):
     add_states_qs = '''insert into state_district (state_id, district_id) values ('{state_id}', '{district_id}') RETURNING id'''
     cursor.execute(
         add_states_qs.format(state_id=state_id, district_id=district_id))
     row = cursor.fetchone()
     if row:
         conn.commit()
         return row['id']
Beispiel #3
0
 def add_states(self, name, code):
     # values = ', '.join(map(str, address_data))
     try:
         add_states_qs = '''insert into state (name, code) values ('{name}', '{code}') on conflict (code) DO UPDATE SET name='{name}' RETURNING id'''
         cursor.execute(add_states_qs.format(name=name, code=code))
         row = cursor.fetchone()
         if row:
             conn.commit()
             return row['id']
     except Exception as e:
         print(e)