/
locate.py
executable file
·48 lines (41 loc) · 1.19 KB
/
locate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python
import sys,os
import cgi, cgitb, json
import anydbm
import traceback
from findmyiphone import findMyiPhone
from encoder import encoder
print "Content-type: application/json"
print
sys.stderr=sys.stdout
try:
credentials=cgi.FieldStorage()
username=credentials.getvalue('u')
password=credentials.getvalue('p')
action=credentials.getvalue('action');
enc=encoder(password)
db=anydbm.open("./loc.db","c")
result=[]
if action == "getHistory":
for k, v in db.iteritems():
entry=enc.decode(v)
if( "timeStamp" in entry ):
result.append(json.loads(entry))
if action == "clearHistory":
for k in db.keys():
del db[k]
if action == "getLocation":
#Check new location
fmi=findMyiPhone(username, password)
fmi.login()
result=fmi.getLocation()
#store location to local DB
for device in result:
if device['location']:
timestamp=device['location']['timeStamp']
db[str(timestamp)]=enc.encode(json.dumps(result))
db.close();
print json.dumps(result)
except:
print "<PRE>"
traceback.print_exc()