Initial (late) commit

master
Davide Bongiovanni 8 years ago
commit d7a0c99984

@ -0,0 +1,27 @@
import time
import json
if __name__ == '__main__':
while True:
cardID = raw_input("Enter card ID: ")
event = {}
event["time"] = time.time()
event["cardID"] = cardID
event["name"] = ''
try:
with open('cards/' + cardID + '.json') as card_data:
data = json.load(card_data)
event["name"] = data['name']
except:
print "Card not registered."
history = []
try:
with open('history.json', 'r') as json_data:
history = json.load(json_data)
except:
print 'Initializing new history file.'
finally:
history.append(event)
with open('history.json', 'w') as outfile:
json.dump(history, outfile)

@ -0,0 +1 @@
{"name": "Davide Bon", "secretTools": true, "fridge": false}

@ -0,0 +1,8 @@
{
"folders":
[
{
"path": "."
}
]
}

@ -0,0 +1,520 @@
{
"auto_complete":
{
"selected_items":
[
[
"ROS",
"ROS_INFO"
],
[
"uar",
"uarmClient"
],
[
"y",
"y"
],
[
"uarm",
"uarmClient"
],
[
"obj",
"objectPose"
],
[
"gra",
"grabObjectCallback"
],
[
"x",
"x_mean"
],
[
"upp",
"UpperV"
],
[
"v",
"V"
],
[
"lo",
"LowerV"
],
[
"up",
"UpperH"
],
[
"lower",
"LowerH"
],
[
"Cm",
"Cmax"
],
[
"dep",
"depth_registered"
],
[
"pcl",
"pclDepthRegistered"
],
[
"z",
"z_mean"
],
[
"dept",
"depthImage"
],
[
"CvIma",
"CvImagePtr"
],
[
"wh",
"white_pixels"
],
[
"mea",
"y_mean"
],
[
"cv",
"cv_ptr"
],
[
"dpe",
"depth_data"
],
[
"Image",
"ImageConstPtr"
],
[
"depth",
"depthDataCallback"
],
[
"sub",
"subscribe"
],
[
"image",
"image_transport"
],
[
"hi",
"history_out"
],
[
"histor",
"history_in"
],
[
"histo",
"history_in"
],
[
"w",
"w1_int_error"
],
[
"es",
"estimated_w2"
],
[
"des",
"desired_w2"
],
[
"time",
"timeString"
],
[
"card",
"cardID"
],
[
"ove",
"overlay_out"
],
[
"pos",
"position"
],
[
"pad",
"padding-left"
],
[
"font",
"font-size"
],
[
"ca",
"card-id"
],
[
"fun",
"function"
],
[
"se",
"send_from_directory"
],
[
"fn",
"function"
],
[
"fu",
"function"
],
[
"bak",
"background-color"
],
[
"poi",
"position"
],
[
"di",
"display"
],
[
"p",
"position"
],
[
"ta",
"ta-c\ttext-align: center;"
],
[
"fon",
"font-size"
],
[
"inl",
"inline-block"
],
[
"back",
"background-color"
],
[
"wid",
"width"
],
[
"tran",
"transition"
],
[
"in",
"inline-block"
],
[
"json",
"json_data"
],
[
"en",
"event"
],
[
"if",
"ifmain\tif __name__ == '__main__'"
],
[
"d",
"d_theta_left"
],
[
"a",
"angular"
],
[
"d_",
"d_theta_right"
],
[
"coun",
"count_change_right"
],
[
"cou",
"count_change"
],
[
"cot",
"count_change_right"
],
[
"count",
"count_change_left"
],
[
"left",
"leftEncoderCallback"
],
[
"ar",
"argv"
],
[
"arg",
"argc"
]
]
},
"buffers":
[
],
"build_system": "",
"build_system_choices":
[
],
"build_varint": "",
"command_palette":
{
"height": 368.0,
"last_filter": "",
"selected_items":
[
[
"prv",
"PackageResourceViewer: Open Resource"
],
[
"syntak",
"Set Syntax: CMake"
],
[
"pcip",
"Package Control: Install Package"
],
[
"rei",
"Indentation: Reindent Lines"
],
[
"rein",
"Indentation: Reindent Lines"
]
],
"width": 453.0
},
"console":
{
"height": 188.0,
"history":
[
"import urllib.request,os,hashlib; h = '261dd1222b4693ce6d4f85f9c827ac06' + '6d5ab8ebdd020086947172a8a1356bb6'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)"
]
},
"distraction_free":
{
"menu_visible": true,
"show_minimap": false,
"show_open_files": false,
"show_tabs": false,
"side_bar_visible": false,
"status_bar_visible": false
},
"expanded_folders":
[
"/home/davide/fridge_lock"
],
"file_history":
[
"/home/davide/catkin_ws/src/sftp-config.json",
"/home/davide/catkin_ws/src/ras_uarm_controller/src/uarm_controller.cpp",
"/home/davide/catkin_ws/src/ras_uarm_controller/CMakeLists.txt",
"/home/davide/catkin_ws/src/ras_color_detection/CMakeLists.txt",
"/home/davide/.config/sublime-text-3/Packages/CMake/CMake.tmLanguage",
"/home/davide/.config/sublime-text-3/Packages/C++/C++.sublime-syntax",
"/home/davide/.config/sublime-text-3/Packages/C++/C++.sublime-settings",
"/home/davide/.config/sublime-text-3/Packages/C++/Comments (C++).tmPreferences",
"/tmp/fz3temp-1/uarm_controller.cpp",
"/home/davide/catkin_ws/src/ras_color_detection/src/color_detection_node.cpp",
"/tmp/fz3temp-1/color_detection_node.cpp",
"/home/davide/fridge_lock/static/style.css",
"/home/davide/fridge_lock/static/script.js",
"/home/davide/fridge_lock/server.py",
"/home/davide/fridge_lock/history.json",
"/home/davide/fridge_lock/cards/2924385363.json",
"/home/davide/fridge_lock/cards/0967437296.json",
"/home/davide/.config/sublime-text-3/Packages/User/Preferences.sublime-settings",
"/tmp/fz3temp-1/milestone1.launch",
"/tmp/fz3temp-1/motor_controller.cpp",
"/tmp/fz3temp-1/ras_odometry_node.cpp",
"/home/davide/fridge_lock/templates/status.html",
"/home/davide/fridge_lock/static/colors",
"/home/davide/fridge_lock/cards/1993135003.json",
"/home/davide/fridge_lock/cards/13245678.json",
"/home/davide/fridge_lock/cardlistener.py",
"/home/davide/fridge_lock/templates/some.html",
"/home/davide/catkin_ws/src/ras_odometry/package.xml",
"/home/davide/catkin_ws/src/ras_odometry/CMakeLists.txt",
"/home/davide/catkin_ws/src/ras_odometry/src/odometry.cpp",
"/home/davide/solar_music/main.c",
"/home/davide/solar_music/makefile",
"/home/davide/crap.json",
"/home/davide/script.py"
],
"find":
{
"height": 41.0
},
"find_in_files":
{
"height": 0.0,
"where_history":
[
]
},
"find_state":
{
"case_sensitive": false,
"find_history":
[
"toPos",
"moveTo",
"cv_ptr",
"Image",
"cv_ptr",
"tm_hour",
"odometry",
"talker",
"angular"
],
"highlight": true,
"in_selection": false,
"preserve_case": false,
"regex": false,
"replace_history":
[
],
"reverse": false,
"show_context": true,
"use_buffer2": true,
"whole_word": false,
"wrap": true
},
"groups":
[
{
"sheets":
[
]
}
],
"incremental_find":
{
"height": 25.0
},
"input":
{
"height": 37.0
},
"layout":
{
"cells":
[
[
0,
0,
1,
1
]
],
"cols":
[
0.0,
1.0
],
"rows":
[
0.0,
1.0
]
},
"menu_visible": true,
"output.find_results":
{
"height": 0.0
},
"output.sftp":
{
"height": 0.0
},
"pinned_build_system": "",
"project": "fridge_lock.sublime-project",
"replace":
{
"height": 46.0
},
"save_all_on_build": true,
"select_file":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
[
"uarm",
"ras_uarm_controller/src/uarm_controller.cpp"
],
[
"ua",
"ras_uarm_controller/CMakeLists.txt"
],
[
"color",
"ras_color_detection/CMakeLists.txt"
]
],
"width": 0.0
},
"select_project":
{
"height": 500.0,
"last_filter": "",
"selected_items":
[
[
"",
"~/catkin_ws/src/harold.sublime-project"
]
],
"width": 380.0
},
"select_symbol":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"selected_group": 0,
"settings":
{
},
"show_minimap": true,
"show_open_files": false,
"show_tabs": true,
"side_bar_visible": true,
"side_bar_width": 218.0,
"status_bar_visible": true,
"template_settings":
{
}
}

@ -0,0 +1,31 @@
[
{
"time": 1475424208.055737,
"name": "Davide Bon",
"cardID": "2924385363"
},
{
"cardID": "0861643457",
"name": "",
"time": 1475424209.151567},
{
"time": 1475424209.758858,
"name": "Davide Bon",
"cardID": "2924385363"
},
{
"cardID": "2924385363",
"name": "Davide Bon",
"time": 1475424211.022202
},
{
"time": 1475424212.244935,
"name": "",
"cardID": "0861643457"
},
{
"cardID": "0861643457",
"name": "",
"time": 1475424213.343284
}
]

@ -0,0 +1,72 @@
from flask import Flask
from flask import render_template, send_from_directory
import json, time
app = Flask(__name__)
@app.route('/')
def index():
return '{"onFire": false}'
@app.route('/status')
def somehtml():
history = []
with open('history.json', 'r') as json_data:
history = json.load(json_data)
history = history[-15:]
for event in history:
event['time'] = epochFormat(event['time'])
return render_template('status.html', events = history[::-1])
@app.route('/getcardinfo/<cardID>')
def getCardInfo(cardID):
return send_from_directory('cards', cardID + '.json')
@app.route('/addcard/<cardID>/<name>/<authCode>')
def addCard(cardID, name, authCode):
authCode = int(authCode)
data = {}
data["name"] = name
if authCode == 0:
data["fridge"] = False
data["secretTools"] = False
elif authCode == 1:
data["fridge"] = True
data["secretTools"] = False
elif authCode == 2:
data["fridge"] = False
data["secretTools"] = True
elif authCode == 3:
data["fridge"] = True
data["secretTools"] = True
else:
return '{"status" : "error_unknownAuthCode"}'
with open('cards/' + cardID + '.json', 'w') as outfile:
json.dump(data, outfile)
history = []
with open('history.json', 'r') as history_in:
history = json.load(history_in)
for event in history:
if event["cardID"] == cardID:
event["name"] = name
with open('history.json', 'w') as history_out:
json.dump(history, history_out)
return '{"status": "ok"}'
def epochFormat(timestamp):
timeObject = time.localtime(timestamp)
timeString = str(timeObject.tm_year) + '/' + str(timeObject.tm_mon) + '/' + str(timeObject.tm_mday) + ' - '
if timeObject.tm_hour < 10:
timeString = timeString + '0'
timeString = timeString + str(timeObject.tm_hour) + ":"
if timeObject.tm_min < 10:
timeString = timeString + '0'
timeString = timeString + str(timeObject.tm_min) + ":"
if timeObject.tm_sec < 10:
timeString = timeString + '0'
timeString = timeString + str(timeObject.tm_sec)
return timeString

Binary file not shown.

@ -0,0 +1,24 @@
#!/bin/sh
export FLASK_APP=server.py
loc=false
noh=false
while getopts "ln" opt; do
case $opt in
l) loc=true ;;
n) noh=true ;;
\?) echo "Invalid argument" ;;
esac
done
if $aflag; then
if $noh; then
nohup flask run&
else
flask run
fi
else
if $noh; then
nohup flask run --host=0.0.0.0&
else
flask run -host=0.0.0.0
fi
fi

@ -0,0 +1,5 @@
lightest D7E2E2
light 5E9292
middle 226666
dark 013A3A
darkest 000F0F

@ -0,0 +1,53 @@
function overlay_in() {
$('.shadow').css({'display' : 'block'});
$('.overlay').css({'display' : 'block'});
$('.shadow').animate({'opacity' : 0.7});
$('.overlay').animate({'top' : '10%'});
}
function overlay_out() {
$('.shadow').animate({'opacity' : 0.0}, function () {
$('.overlay').css({'display' : 'none'});
});
$('.overlay').animate({'top' : '-70%'}, function () {
$('.shadow').css({'display' : 'none'});
});
}
function save() {
var name = $('#name').val();
var cardID = $('.card-id').text();
var authCode = 0;
if ($('#fridge').is(':checked'))
authCode += 1;
if ($('#tools').is(':checked'))
authCode += 2;
$.getJSON('http://127.0.0.1:5000/addcard/' + cardID + '/' + name + '/' + authCode, function(data) {
});
overlay_out();
}
$(document).ready(function() {
$('.event').click(function() {
var cardID = $(this).attr('card-id')
$('.card-id').text(cardID);
$.getJSON('http://127.0.0.1:5000/getcardinfo/' + cardID, function(data) {
$('#name').val(data.name);
if (data.fridge)
$('#fridge').prop('checked', true);
else
$('#fridge').prop('checked', false);
if (data.secretTools)
$('#tools').prop('checked', true);
else
$('#tools').prop('checked', false);
})
.fail(function() {
$('#name').val('');
$('#fridge').prop('checked', false);
$('#tools').prop('checked', false);
});
overlay_in();
})
})

@ -0,0 +1,138 @@
html {
background: #D7E2E2;
font-family: 'Roboto';
color: #000F0F;
}
.recent {
display: inline-block;
left: 0;
position: absolute;
top: 0;
width: 30%;
}
.event {
font-size: 12pt;
padding: 0 6pt 0 6pt;
transition: 0.4s;
width: 100%;
}
.event:hover {
background: #226666;
width: 105%;
}
.time {
padding: 6pt 0 6pt 0;
display: inline-block;
width: 49%;
text-align: left;
}
.name {
padding: 6pt 0 6pt 0;
display: inline-block;
width: 49%;
text-align: right;
}
.unknown_card {
color: #E26B08;
}
.everything-else {
display: inline-block;
width: 69%;
left: 30%;
top: 0;
position: absolute;
}
h1 {
text-align: center;
font-weight: 300;
}
.button {
width: 50%;
background-color: #013A3A;
color: #5E9292;
padding: 6pt;
text-align: center;
font-size: 16pt;
margin: 16pt 0 16pt 0;
}
.separator {
height: 10%;
}
.vertical-separator {
height: 100%;
width: 1px;
background-color: #5E9292;
position: absolute;
top: 0;
left: 35%;
z-index: 100;
}
.shadow {
background-color: black;
display: none;
height: 100%;
left: 0;
opacity: 0.0;
position: absolute;
top: 0;
width: 100%;
z-index: 200;
}
.overlay {
background-color: #226666;
color: #D7E2E2;
display: none;
height: 60%;
left: 35%;
padding: 8pt;
position: absolute;
top: -70%;
width: 30%;
z-index: 201;
}
.card-id {
font-weight: 300;
text-align: center;
padding: 8pt;
font-size: 24pt;
}
input[type=text] {
font-size: 16pt;
margin: 12pt 6pt 12pt 6pt;
padding: 5pt 8pt 5pt 8pt;
}
.button {
background-color: #013A3A;
color: #5E9292;
border: none;
text-align: center;
font-size: 10pt;
width: 45%;
margin: 8pt;
position: absolute;
bottom: 0;
}
#save {
right: 0;
}
#cancel {
left: 0;
}

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Card access manager</title>
<link rel="stylesheet" type="text/css" href="static/style.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet">
<script
src="http://code.jquery.com/jquery-3.1.1.js"
integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA="
crossorigin="anonymous"></script>
<script type="text/javascript" src="static/script.js"></script>
</head>
<body>
<div class="recent">
{% for event in events %}
<div class="event" card-id="{{event.cardID}}">
<div class="time">{{event.time}}</div>
<div class="name">
{% if event.name == "" %}
<span class="unknown_card">{{event.cardID}}</span>
{% else %}
{{event.name}}
{% endif %}
</div>
</div>
{% endfor %}
</div>
<div class="vertical-separator"></div>
<div class="everything-else">
<h1 id="myBtn">Card access manager</h1>
</div>
<div class="shadow" onclick="overlay_out()"></div>
<div class="overlay">
<h2 class="card-id"></h2>
<input type="text" name="name" placeholder="Name" id="name"><br><br>
&emsp;<input type="checkbox" name="fridge" value="Fridge" id="fridge"> Fridge <br>
&emsp;<input type="checkbox" name="tools" value="Tools" id="tools"> Secret tools
<input type="button" class="button" value="Cancel" id="cancel" onclick="overlay_out()">
<input type="button" class="button" value="Save" id="save" onclick="save()">
</div>
</body>
</html>
Loading…
Cancel
Save