def setUp(self): super(EventListTest, self).setUp() service = models.Service(name="Foo", slug="foo", description="Hello") service.put() status = models.Status(name="Up", slug="up", default=True, description="bar", image="cross-circle") status.put()
def get_status() -> models.Status: timestamp = int(time.time()) mail = check_mail() lab = check_lk() usos = check_usos() ssh = check_ssh() return models.Status(timestamp, mail, lab, usos, ssh)
def user_posts(twitter_id): """An endpoint that fetches the last 25 tweets of the user and puts them into Database. If called a second time it compares tweets in the database with the ones from Twitter, updates with more recent posts if needed. If query param '?local=true' was provided, it just returns saved data from the database.""" try: user = models.User.query.get(twitter_id) if not request.args.get('local') or request.args.get('local') != 'true': if not user: user = models.User(twitter_api.GetUser(user_id=twitter_id).AsDict()) db.session.add(user) statuses = twitter_api.GetUserTimeline(user_id=twitter_id, count=NUMBER_OF_POSTS) for status in statuses: new_status_dict = status.AsDict() new_status_dict['user_id'] = status.user.id old_status = models.Status.query.get(status.id) if old_status: old_status.update(new_status_dict) else: new_status = models.Status(new_status_dict) db.session.add(new_status) # TODO delete extra statuses db.session.commit() statuses = models.Status.query.with_parent(user) if not statuses.first(): abort(404) return paginate(statuses) except Exception as e: db.session.close() print >> sys.stderr, e abort(404)
def disAllowReApp(): q = models.Status().all().filter('number =', '1') rows = q.fetch(1) for row in rows: row.number = '1' row.reapplication = False row.put()
def openApplication(): q = models.Status().all().filter('number =', '1') rows = q.fetch(1) for row in rows: row.number = '1' row.open = True row.put()
def copy_with_new_timestamp(status: models.Status, timestamp: int) -> models.Status: return models.Status( timestamp=timestamp, mail=status.mail, lab=status.lab, usos=status.usos, ssh=status.ssh, )
def get_last(self) -> models.Status: cursor = self.connection.cursor() cursor.execute('SELECT * FROM status ORDER BY timestamp DESC LIMIT 1') last_status_tuple = cursor.fetchone() if not last_status_tuple: return else: return models.Status(*last_status_tuple)
def get_last_checks(how_many: int = 100) -> [models.Status]: results = [] cursor = get_db().cursor() cursor.execute( 'SELECT timestamp, mail, lab, usos, ssh ' 'FROM status ' 'ORDER BY timestamp DESC', ) for status in cursor.fetchmany(how_many): results.append(models.Status(status[0], *[bool(e) for e in status[1:]])) results.reverse() return results
def setUp(self): super(EventInstanceTest, self).setUp() service = models.Service(name="Foo", slug="foo", description="Hello") service.put() self.status = models.Status(name="Up", slug="up", default=True, description="bar", image="cross-circle") self.status.put() self.event = models.Event(service=service, status=self.status, message="Foo") self.event.put()
def _get_status_object(self, dict_status): self._status_obj = models.Status( id_str=dict_status['id_str'], text=dict_status['text'], in_reply_to_status_id=dict_status['in_reply_to_status_id'], in_reply_to_user_id=dict_status['in_reply_to_user_id'], user=self._get_user_object(dict_status['user']), retweet_count=dict_status['retweet_count'], is_favorite=dict_status['favorited'], is_retweet=dict_status['retweeted'], created_at=dict_status['created_at']) return self._status_obj
def setUp(self): super(RSSFeedTest, self).setUp() self.services = [] self.statuses = [] for name in ['web', 'billing', 'notifications']: service = models.Service(name=name.title(), slug=name, description="test service") service.put() self.services.append(service) for name in ['up', 'down', 'warning']: status = models.Status(name=name.title(), slug=name, description="test status", image="test image") status.put() self.statuses.append(status)
async def site_checker(website: models.Website) -> bool: success: bool = False try: # get the database session db: Session = next(get_db()) # create a new status object status: models.Status = models.Status() # connect the status to a site status.url_id = website.id # ping server and store onlineness status.online = await ping_site(website) # Check the site and store response code status.response_code = await test_site(website) # get the timestamp status.timestamp = datetime.now() # add the status to the DB # Make Dashboard Item item: schemas.DashboardItem = schemas.DashboardItem() item.set_values(website=website, status=status) # store status in the database db.add(status) db.commit() # Make the payload and broadcast it to all users payload: dict = {'action': schemas.PayloadAction.UPDATE, 'data': item} await broadcast(payload) log.critical(f"broadcast for payload: {payload} complete") success = True except sqlalchemy.exc.InvalidRequestError as e: # log the exception msg = f'Error commiting a status add for site {website.name} ({website.get_url()}):\n\t{e}' log.error(msg, exc_info=True) except Exception as e: # log unknown error msg = f'Unknown exception commiting/broadcasting a status add for site {website.name} ({website.get_url()}):\n\t{e}' log.error(msg, exc_info=True) finally: return success
def closeApplication(): q = models.Status().all().filter('number =', '1') rows = q.fetch(1) for row in rows: row.open = False row.put()