-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocation.py
51 lines (43 loc) · 1.21 KB
/
location.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
49
50
51
# -*- coding: utf-8 -*-
import android
import tweepy
from sys import exit
from time import sleep, strftime
# Twitter autorizaija
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
try:
api = tweepy.API(auth)
print "Autorizovan kao: ", api.me().name
except tweepy.TweepError, e:
print "Autorizacija nije uspela."
exit(e)
# Pribavlja GPS lokaciju
droid = android.Android()
print "Započinjem lociranje..."
droid.startLocating()
sleep(20)
loc = droid.readLocation()
droid.stopLocating()
if 'gps' in loc.result:
lat = str(loc.result['gps']['latitude'])
lon = str(loc.result['gps']['longitude'])
else:
lat = str(loc.result['network']['latitude'])
lon = str(loc.result['network']['longitude'])
# Postavlja trenutno vreme
time = strftime("%a, %d %b %Y %H:%M:%S")
# Tvit poruka
msg = "%s: https://maps.google.com/?ll=%s,%s" % (time, lat, lon)
# Azurira status i ispisuje 3 zadnja tvita.
try:
api.update_status(msg)
tweets = api.home_timeline(count=3)
for tweet in tweets:
print tweet.text, "\n"
except tweepy.TweepError, e:
exit(e)