source: feed2telegram/trunk/example/example.py

Last change on this file was 12, checked in by cheese, 16 months ago

#1 change feedparser.parse to requests for timeout

File size: 859 bytes
Line 
1#-*- coding: utf-8 -*-
2from feed2telegram import Feed2Telegram
3
4url = '<url>'
5token = '<telegram-bot-token>'
6
7f2t = None
8
9def getIterator(feed):
10 return reversed(feed.entries)
11
12def getMessage(entry):
13 return entry['link']
14
15def createInstance(threaded):
16 global f2t
17
18 f2t = Feed2Telegram(url,
19 token,
20 getMessage,
21 callback_get_entries=getIterator,
22 check_interval=60*60,
23 new_entries_only=True,
24 send_error=True,
25 continue_on_error=True,
26 threaded=threaded)
27
28# only for example ...
29def interrupt(signum, frame):
30 f2t.stop()
31
32def runWithThreading():
33 import signal
34 signal.signal(signal.SIGINT, interrupt)
35
36 createInstance(True)
37
38 f2t.start() # returned
39 f2t.join() # blocked
40
41def withoutThreading():
42 createInstance(False)
43
44 f2t.start() # blocked
45
46def main():
47 withoutThreading()
48
49if __name__ == '__main__':
50 main()
51
Note: See TracBrowser for help on using the repository browser.