Jag försöker få ett script som jag byggt skicka notify till mig när det händer nåt på en remote sida som jag hämtar med curl.
Allting fungerar som det ska utom 1 sak pynotify.init()
Jag har försökt alla möjliga olika lösningar men den vägrar att skicka till min notify deamon. vad göra?
ps. cronen ligger som user mig själv ds.
Kod: Markera allt
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import pygtk
pygtk.require('2.0')
import pynotify
import sys
import pycurl
import json
class Data:
def __init__(self):
self.contents = ''
def body_callback(self, buf):
self.contents = self.contents + buf
if __name__ == '__main__':
print 'Starting process \n'
if not pynotify.init("Work notify"):
print 'exits'
sys.exit(1)
t = Data()
c = pycurl.Curl()
c.setopt(c.URL, 'some nice url')
c.setopt(c.WRITEFUNCTION, t.body_callback)
c.perform()
c.close()
data = json.loads(t.contents)
# print data
write = '';
for key in data:
print key['user'] +'|'+ key['project']+'\n'
write += key['user'] +'|'+ key['project']+'\n'
infile = FILE = open('time.cache', 'r')
dont = False
for line in infile:
print line + "2"+ key['user'] +'|'+ key['project']+'\n'
if line == key['user'] +'|'+ key['project']+'\n':
dont = True
break
infile.close()
if dont == False:
n = pynotify.Notification('Instämplad \n'+key['user'], key['project'])
print 'sent Instämplad '+key['user'], key['project']+'\n'
if not n.show():
print "Failed to send notification"
sys.exit(1)
# print write
cache = FILE = open('time.cache',"w")
cache.writelines(write)
cache.close()

