Пример #1
0
def writeResult(field, key, val):
    with open('/home/' + getUser() + '/wifi_monitor/output.json', 'r') as f:
        j = eval("".join(f.readlines()))
        if not field in j:
            j[field] = {}
        j[field][key] = val
    with open('/home/' + getUser() + '/wifi_monitor/output.json', 'w') as f:
        f.truncate()
        f.write(json.dumps(j))
Пример #2
0
def setup():
    global accountSid, authToken, client, myPhoneNumber, toPhoneNumbers

    with open('/home/' + getUser() + '/wifi_monitor/.twilio.tokens', 'r') as f:
        accountSid = f.readline().strip()
        authToken = f.readline().strip()
        myPhoneNumber = f.readline().strip()

    with open('/home/' + getUser() + '/wifi_monitor/.phone.numbers', 'r') as f:
        toPhoneNumbers = [i.split() for i in f.readlines()]

    client = Client(accountSid, authToken)
Пример #3
0
def home():
    udict = {'uname':False}
    if 'username' in session:
        username = escape(session['username'])
        udict = util.getUser(username)
        return redirect('/events')
    return render_template('home.html', udict = udict)
Пример #4
0
def getCurrentDownloadSpeed():
    os.chdir('/home/' + getUser() + '/wifi_monitor/')
    result = subprocess.run([
        'bash', '-c', 'time wget ' + fileLink,
        '-U "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-GB; rv:1.9.0.1) Gecko/2008070206 Firefox/3.0.1"',
        '--no-check-certificate'
    ],
                            stderr=subprocess.PIPE)
    try:

        stderr = str(result.stderr.decode('utf-8'))
        outputGarbage = stderr.split(' ')[-1]
        splitGarbage = outputGarbage.split('\n')

        time = [i for i in splitGarbage if 'real' in i][0].split('\t')[1]

        seconds = parseTimeToSeconds(time)
        downloadSpeed = (fileSize / seconds) * 8 * magicRatio

        if (downloadSpeed > 150): return  # this is clearly an error

        cleanup()
        writeSpeedResult(downloadSpeed)
        checkForAlert(downloadSpeed)

        return downloadSpeed
    except:
        pass  # we'll get it later
Пример #5
0
def pull():
    try:
        os.chdir('/home/' + getUser() + '/wifi_monitor')
        subprocess.run(['git', 'fetch'])
        subprocess.run(['git', 'rebase', 'origin/master'])
    except:
        # well rip
        pass
Пример #6
0
def user_page(uname = None):

    #if util. ---this will check if the uname exists
    if util.getUser(uname) == None:
        flash("That's not a user")
        return redirect('/events')
    else:
        username = escape(session['username'])
        udict = util.getUser(username)
        pdict = util.getUser(uname)
        pic = util.getPicture (udict['uname'])

    if request.method=="POST":
            print(request.form["rating"])


    return render_template('user.html', udict = udict, pdict=pdict, profile = pic)
Пример #7
0
def your_event():
    username = escape(session['username'])
    udict = util.getUser(username)
    all_lists =[]
    all_lists.append(util.getHostedEvents(username))
    all_lists.append(util.getApprovedEvents(username))
    all_lists.append(util.getRequestedEvents(username))

    return render_template('your_events.html', udict = udict, alist = all_lists)
Пример #8
0
def upload():
    try:
        os.chdir('/home/' + getUser() + '/wifi_monitor')
        subprocess.run(['git', 'add', 'output.json'], stdout=subprocess.DEVNULL)
        subprocess.run(['git', 'commit', '-m', '"Another speed test"'], stdout=subprocess.DEVNULL)
        subprocess.run(['git', 'push', 'origin', 'master'], stdout=subprocess.DEVNULL)
    except Exception as e:
        # oh well, we can try again next time
        pass
Пример #9
0
def addreview(uname = None):
    username = escape(session['username'])
    udict = util.getUser(username)
    review = {}
    review['user'] = username
    review['rating'] = int(request.form["rating"])
    review['comment'] = request.form["comment"]
    util.updateReview(uname, review)
    return redirect('/user/'+ uname)
Пример #10
0
def newmsg(eventid = None):
    username = escape(session['username'])
    udict = util.getUser(username)
    msg = {}
    msg['user'] = username
    msg['msg'] = request.form["msg"]
    msg['time'] = datetime.today()
    util.updateEField(eventid, 'msgs', msg)

    return redirect('/event_page/'+ eventid )
Пример #11
0
def joinevent():
    username = escape(session['username'])
    udict = util.getUser(username)
    elist = util.validEvents(username)
    if request.method=="POST":
        event = request.form["submit"] # objectid
        util.updateEField(event, 'requests', username)
        util.addEventUserList(username, 'revents', event)
        return render_template('events.html', udict=udict, elist=elist,
                               name = util.getEventAttribute(event, "ename"))
Пример #12
0
def event_page(id = None):
    if request.method=="POST":
        value = request.form["submit"]
        if (value == "close"):
            util.updateEventField(id, "open", False)
        elif (value == "start"):
            util.startEvent(id);
    username = escape(session['username'])
    udict = util.getUser(username)
    event = util.getEvent(id)
    return render_template('event_page.html', udict = udict, event = event)
Пример #13
0
def joinevent():
    username = escape(session['username'])
    udict = util.getUser(username)
    #elist = util.listEvents(); # do we need this?
    elist = util.validEvents(username)
    if request.method=="POST":
        event = request.form["submit"] # objectid
        #print event
        util.updateEField(event, 'requests', username)
        #util.updateUField(username, 'requests', event) #event doesn't include objectid
        util.addEventUserList(username, 'revents', event)
        #util.addEventPerson(event, username)
        return render_template('events.html', udict=udict, elist=elist,
                               name = util.getEventAttribute(event, "ename"))
Пример #14
0
def events():
    username = escape(session['username'])
    udict = util.getUser(username)
    #elist = util.listEvents();
    elist = util.validEvents(username)
    return render_template('events.html', udict=udict, elist=elist)
Пример #15
0
def event_create():
    username = escape(session['username'])

    return render_template('eventCreate.html', udict=util.getUser(username))
Пример #16
0
def personal(thing = None):
    username = escape(session['username'])
    udict = util.getUser(username)
    pic = util.getPicture (udict['uname'])
    print pic
    return render_template('personal.html', udict=udict, change=thing, profile = pic)
Пример #17
0
def ajax():
    udict = {'uname':False}
    if 'username' in session:
        username = escape(session['username'])
        udict = util.getUser(username)
    return render_template('ajaxTest.html', udict=udict)
Пример #18
0
def releaseLock():
    os.chdir('/home/' + getUser() + '/wifi_monitor')
    subprocess.run(['rm', 'alert.lock'])
Пример #19
0
def getUserInfo():
    username = session["user"]
    print util.getUser(username)
    return json.dumps(util.getUser(username))
Пример #20
0
def acquireLock():
    os.chdir('/home/' + getUser() + '/wifi_monitor')
    subprocess.run(['touch', 'alert.lock'])
Пример #21
0
def cleanup():
    os.chdir('/home/' + getUser() + '/wifi_monitor/')
    filename = fileLink.split('/')[-1]
    subprocess.run(['rm', filename])
Пример #22
0
def isLocked():
    os.chdir('/home/' + getUser() + '/wifi_monitor')
    run = subprocess.run(['test', '-f', 'alert.lock'])
    if run.returncode == 1:
        return False
    return True
Пример #23
0
def getOtherInfo():
    otherUser = request.args.get("otherUser", "").strip()
    print otherUser #to make sure we're looking for the right other user
    return json.dumps(util.getUser(otherUser))
Пример #24
0
def p():
    username = escape(session['username'])
    picture = util.getPicture (session['username'])
    return render_template('personal.html', udict=util.getUser(username), change = "Null", profile = picture)