-
Notifications
You must be signed in to change notification settings - Fork 2
/
fbonline.py~
35 lines (32 loc) · 1.21 KB
/
fbonline.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
import requests
import json
import subprocess
import time
ACCESS_TOKEN = "CAADbJ2R6rpEBAKUP0NUVO5TrSQWk6B1pth9wxRQRZArTcvYvTAFHvw1AFh02qSAN8HZBGtVauDvQZAg61BpGzC3zcvYAkZAxOlyKsY4evM8t5LQ0ZAoYMfJpDSLMZBy4Qig9cP5JYeqQeLvMnhZAzgW4cccnZBr84KPMjrvaBOgPO90Gs0SkNYg1EIMdXnQDnQoZD"
friends_online = []
friends_online_old = []
counter = 0
def get_friends_online():
'''Returns friends who are online'''
query = ("SELECT uid, name FROM user WHERE online_presence IN ('active', 'idle') AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())")
payload = {'q' : query, 'access_token' : ACCESS_TOKEN }
r = requests.get('https://graph.facebook.com/fql', params=payload)
result = json.loads(r.text)
for name in result['data']:
friends_online.append(name['name'])
return friends_online
while 1:
counter = counter + 1
if counter == 30:
friends_online_old = []
if len(get_friends_online()) <= 0:
pass
elif len(get_friends_online()) > 0:
for friend in friends_online:
if friend in friends_online_old:
pass
else:
message = "%s is online" % friend
subprocess.Popen(['notify-send', message])
friends_online_old.append(friend)
time.sleep(60)