Skip to content

Commit

Permalink
Covosk will run mask veritifcaitons on pictures
Browse files Browse the repository at this point in the history
  • Loading branch information
staging committed Jul 14, 2020
1 parent 8357401 commit c9d9cd5
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 1 deletion.
15 changes: 15 additions & 0 deletions authlibs/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import base64
import random,string
import tempfile
import subprocess


# You must call this modules "register_pages" with main app's "create_rotues"
blueprint = Blueprint("api", __name__, template_folder='templates', static_folder="static",url_prefix="/api")
Expand Down Expand Up @@ -378,6 +380,19 @@ def api_v1_kiosklog():

authutil.log(e,member_id=m.id,message=imagename,commit=0)
db.session.commit()
try:
cam_slackchan = current_app.config['globalConfig'].Config.get('cameras','slackchan')
s = subprocess.Popen(['/home/bkg/covid-mask-detector/covid-mask-detector/testone.py',imagecode],stdout=subprocess.PIPE)
txt = s.stdout.read().strip()
res = s.wait()
if (res != 0):
url="https://auth.makeitlabs.com"+url_for("logs.kioskentry",ke=imagecode)
res = send_slack_message(
"#project-covid-kiosk",
":alert: {0} {1} at kiosk {2}".format(m.member,txt,url)
)
except BaseException as e:
logger.error("Kiosk mask check error {0}".format(e))
try:
url=""
if imagecode:
Expand Down
3 changes: 3 additions & 0 deletions authlibs/logs/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ def kioskentry(ke):
ke = ke.replace("/","")
ke = ke.replace(".","")
ke = ke.replace("kioskimages:","")
if not current_user.is_arm() and (len(current_user.effective_roles()) == 0):
flash("Not authorized for this page","warning")
return redirect_url_for("index")
return render_template('kiosk_entry.html',entry=ke)

blueprint.route('/large.csv')
Expand Down
7 changes: 6 additions & 1 deletion slacktest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from flask import Flask, request, session, g, redirect, url_for, \
abort, render_template, flash, Response
from flask_user import current_user, login_required, roles_required, UserManager, UserMixin, current_app
from authlibs.slackutils import automatch_missing_slack_ids,add_user_to_channel,send_slack_message
from flask_sqlalchemy import SQLAlchemy
from authlibs import utilities as authutil
from slackclient import SlackClient
Expand Down Expand Up @@ -81,10 +82,14 @@
"conversations.join",
channel="CTN7EK3A9"
)
res = sc.api_call(
"conversations.join",
channel="C014U9VPH16"
)
print res

res = sc.api_call(
"conversations.invite",
channel="CTN7EK3A9",
users="U03126YLY"
)
print res
95 changes: 95 additions & 0 deletions test/slacktest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/usr/bin/python2
"""
vim:tabstop=2:expandtab:shiftwidth=2
MakeIt Labs Authorization System, v0.4
This is a daemon only used to log stuff via MQTT
"""

from authlibs.eventtypes import *
import sqlite3, re, time
from authlibs.db_models import db, Role, UserRoles, Member, Resource, AccessByMember, Logs, Tool, UsageLog, Node
import argparse
from flask import Flask, request, session, g, redirect, url_for, \
abort, render_template, flash, Response
from flask_user import current_user, login_required, roles_required, UserManager, UserMixin, current_app
from authlibs.slackutils import automatch_missing_slack_ids,add_user_to_channel,send_slack_message
from flask_sqlalchemy import SQLAlchemy
from authlibs import utilities as authutil
from slackclient import SlackClient
import json
import ConfigParser,sys,os
import paho.mqtt.client as mqtt
import paho.mqtt.subscribe as sub
from datetime import datetime
from authlibs.init import authbackend_init, createDefaultUsers
import requests,urllib,urllib2
import logging, logging.handlers
from authlibs import eventtypes

Config = ConfigParser.ConfigParser({})
Config.read('makeit.ini')
slack_api_token = Config.get('Slack','BOT_API_TOKEN')
admin_api_token = Config.get('Slack','ADMIN_API_TOKEN')

if __name__ == '__main__':
parser=argparse.ArgumentParser()
parser.add_argument("--command",help="Special command",action="store_true")
(args,extras) = parser.parse_known_args(sys.argv[1:])

print "ADMIN API TOKEN",admin_api_token
sc1 = SlackClient(slack_api_token)
#if sc1.rtm_connect():
# print "RTM connected on BOT"
#else:
# print "RTM Connection Failed"
# sys.exit(1)

print "API TOKEN",slack_api_token
sc = SlackClient(admin_api_token)
res = sc1.api_call(
"chat.postMessage",
channel="U03126YLY",
text="Admin Test Message"
)
res = sc.api_call(
"chat.postMessage",
channel="U03126YLY",
text="Bot Test Message"
)
next_cursor=None
while True:
res = sc.api_call(
"conversations.list",
cursor=next_cursor,
exclude_archived=True
)
if not res['ok']:
print "conversaitons.list failed ",res
sys.exit(1)
for x in res['channels']:
if x['is_channel']:
print x['name'],x['id']
pass
if 'response_metadata' not in res or 'next_cursor' not in res['response_metadata']:
break
next_cursor = res['response_metadata']['next_cursor']
if next_cursor.strip() == "": break
print "NEXT CUROSR IS",next_cursor

# fake-resource-users
res = sc.api_call(
"conversations.join",
channel="CTN7EK3A9"
)
res = sc.api_call(
"conversations.join",
channel="C014U9VPH16"
)
print res

res = sc.api_call(
"conversations.invite",
channel="CTN7EK3A9",
users="U03126YLY"
)

0 comments on commit c9d9cd5

Please sign in to comment.