Skip to content
Newer
Older
100644 107 lines (83 sloc) 3.09 KB
5cdb981 @natfriedman Initial import
authored
1 <?php
2
3 //
4 // A little script to scrape your iPhone's location from MobileMe
5 // and update Google Latitude with your iPhone's current position.
6 //
7 // Uses sosumi from http://github.com/tylerhall/sosumi/tree/master and
8 // some google scraping code from Jack Catchpoole <jack@catchpoole.com>.
9 //
10 // Nat Friedman <nat@nat.org>
11 //
12 // August 22nd, 2009
13 //
14 // MIT license.
15 //
16
17 include 'class.google.php';
18 include 'class.sosumi.php';
19
20 $mobileMePasswordFile = "./mobile-me-password.txt";
21
22 $google = new iGoogle();
23
24 function promptForLogin($serviceName)
25 {
26 echo "$serviceName username: ";
27 $username = trim(fgets(STDIN));
28
29 if (empty($username)) {
30 die("Error: No username specified.\n");
31 }
32
33 echo "$serviceName password: ";
34 system ('stty -echo');
35 $password = trim(fgets(STDIN));
36 system ('stty echo');
37 // add a new line since the users CR didn't echo
38 echo "\n";
39
40 if (empty ($password)) {
41 die ("Error: No password specified.\n");
42 }
43
44 return array ($username, $password);
45 }
46
47 if (! file_exists ($mobileMePasswordFile)) {
2096a67 @natfriedman Better MobileMe password prompt
authored
48 echo "You will need to type your MobileMe username/password. They will be\n";
49 echo "saved in $mobileMePasswordFile so you don't have to type them again.\n";
50 echo "If you're not cool with this, you probably want to delete that file\n";
51 echo "at some point (they are stored in plaintext).\n\n";
52 echo "You do need a working MobileMe account for playnice to work, and you\n";
53 echo "need to have enabled the Find My iPhone feature on your phone.\n\n";
54
5cdb981 @natfriedman Initial import
authored
55
56 list($mobileMeUsername, $mobileMePassword) = promptForLogin("MobileMe");
57
58 $f = fopen ($mobileMePasswordFile, "w");
59 fwrite ($f, "<?php\n\$mobileMeUsername=\"$mobileMeUsername\";\n\$mobileMePassword=\"$mobileMePassword\";\n?>\n");
60 fclose ($f);
d07a4e6 @natfriedman Detect google login failures earlier; add ?gl=us to the iGoogle URL; …
authored
61 chmod($mobileMePasswordFile, 0600);
5cdb981 @natfriedman Initial import
authored
62
63 echo "\n";
64
65 } else {
66 @include($mobileMePasswordFile);
67 }
68
69 if (! $google->haveCookie()) {
70 echo "No Google cookie found. You will need to authenticate with your\n";
71 echo "Google username/password. You should only need to do this once;\n";
72 echo "we will save the session cookie for the future.\n\n";
02f3a9d @natfriedman Helpful message.
authored
73 echo "Please note that you need to have the Latitude widget on your main\n";
74 echo "iGoogle page for this to work.\n\n";
5cdb981 @natfriedman Initial import
authored
75
76 list($username, $password) = promptForLogin("Google");
77
78 echo "Acquiring Google session cookie...";
79 $google->login($username, $password);
80 echo "got it.\n";
81 }
82
83 // Get the iPhone location from MobileMe
84 echo "Fetching iPhone location...";
85 $mobileMe = new Sosumi ($mobileMeUsername, $mobileMePassword);
3d7ad1a @natfriedman Included patch from Andy Blyler to make sosumi work again after the M…
authored
86 if (! $mobileMe->authenticated) {
87 echo "Unable to authenticate to MobileMe. Is your password correct?\n";
88 exit;
89 }
90
91 if (count ($mobileMe->devices) == 0) {
92 echo "No iPhones found in your MobileMe account.\n";
93 exit;
94 }
5cdb981 @natfriedman Initial import
authored
95 $iphoneLocation = $mobileMe->locate();
96 echo "got it.\n";
97
98 echo "iPhone location: $iphoneLocation->latitude, $iphoneLocation->longitude\n";
99
100 // Now update Google Latitude
101 echo "Updating Google Latitude...";
102 $google->updateLatitude($iphoneLocation->latitude, $iphoneLocation->longitude,
103 $iphoneLocation->accuracy);
104
105 // All done.
106 echo "Done!\n";
Something went wrong with that request. Please try again.