I’m trying to make an notification system that will send a system notification when there’s a new topic on the most recent section of the forum. I’m trying to use the objc_util to schedule the function to the background threads. The function itself works, and sending the update to the background works, but the scheduler doesn’t repeat the function after the interval time. In: https://developer.apple.com/documentation/foundation/nsbackgroundactivityscheduler?language=objc
, it says that the scheduler won’t repeat if you don’t invoke the completion handler and send it the “all good flag” (integer 1).
I have no idea how to send this flag to the completion handler. I’ve been through plenty of crashes to no avail lol. Here’s the code:
import requests as r
from bs4 import BeautifulSoup as soup
import notification
from objc_util import *
def update(_cmd,completion_handler):#not sure on number of args or types
with open('most_recent.txt','rb') as f:
most_recent=f.read()
print('checking') #debug
page=r.get('https://forum.omz-software.com/recent')
page=soup(page.content,'html.parser')
newest=page.select('meta')[8]
content_name=newest.attrs.get('content')
if bytes(content_name,'utf8') != most_recent:
print(content_name)#debug
with open('most_recent.txt','wb') as f:
f.write(bytes(content_name,'utf8'))
notification.schedule(message=f'Newest on the Pythonista Forum: {content_name}',action_url='https://forum.omz-software.com/recent',title='Pythonsita Forum')
else:#debug
notification.schedule(message='Nothing new...',title='Pythonista Forum')#debug
#ObjCInstance(completion_handler).completion=1#doesnt work
return
scheduler=ObjCClass("NSBackgroundActivityScheduler").alloc().initWithIdentifier_('com.omz-software.Pythonista3.update_forums')
scheduler.setInterval_(10)#more time when working
scheduler.setTolerance_(5)
scheduler.setRepeats_(True)
scheduler.setQualityOfService_(25)#may change when working
#not sure on restype or argtypes either
block=ObjCBlock(update,restype=None,argtypes=[c_void_p,c_void_p])
scheduler.scheduleWithBlock_(block)