Well, it depends on the person, but if you force a home worker etc. to POST every day, you can judge whether you are doing it at home or not. Use it systematically.
First, write a script that sends location information to HTML.
index.html
<script type="text/javascript">
if (navigator.geolocation) {
//Acquire current location information
navigator.geolocation.getCurrentPosition(
//When location information acquisition is successful
function (pos) {
var location = pos.coords.latitude;
location += "," + pos.coords.longitude;
document.getElementById("location").innerHTML = location;
},
//When location information acquisition fails
function (pos) {
var location ="Location information could not be obtained<br />Try reloading and try again";
document.getElementById("infotext").innerHTML = location;
});
} else {
window.alert("Geolocation cannot be used with this browser.");
}
</script>
It is like this. The rest is to make a form. I will take UA, so don't forget to add it.
index.html
<script type="text/javascript">
window.onload = function(){
var UA = navigator.userAgent;
document.getElementById("result").innerHTML = UA;
}
</script>
<form method="POST" action="cgi-bin/index.py">
<textarea class="hidden" id="location" name="send_geo" readonly></textarea>
<textarea class="hidden" id="result" name="user" readonly></textarea>
<select class="form-message validate-required" name="word">
<option value="in">IN</option>
</select><br>
<p><input type="submit" value="Send"></p>
</form>
The rest is written assuming that Python runs on CGI. That way, you can get on Sakura Internet's Ren Saba as it is.
useraccess.cgi
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
import sys, codecs
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
from datetime import datetime
import cgi
import csv
print "Content-Type: text/html\n"
print """
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
<meta name="format-detection" content="telephone=no">
<link media="only screen and (max-device-width:1080px)" href="static/css/smart.css" type="text/css" rel="stylesheet" />
<link media="screen and (min-device-width:1081px)" href="static/css/style.css" type="text/css" rel="stylesheet" />
"""
print """
</head>
<body>
<div id="content">
<div id="topmain">
"""
try:
form = cgi.FieldStorage()
words = form["word"].value
send_geotag = form["send_geo"].value
usera = form["user"].value
today = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
f = open("date.txt", "ab")
writer = csv.writer(f, quoting=csv.QUOTE_ALL)
writer.writerow([words,today,send_geotag,usera])
f.close()
print "<p>"+ words + ": " + today + "</p>"
except (RuntimeError, TypeError, KeyError):
print "<p>"+u"Please allow location information and try again"+"</p>"
print """
</div>
</div>
</body>
</html>
"""
"in","2015/12/03 09:50:33",",","Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13B143 Safari Line/5.7.0"
Data.txt will be created like this.
I haven't done any small error branching, so please do something about it.
Recommended Posts