Last change
on this file was 12, checked in by cheese, 6 years ago |
#1 change feedparser.parse to requests for timeout
|
File size:
859 bytes
|
Rev | Line | |
---|
[12] | 1 | #-*- coding: utf-8 -*-
|
---|
| 2 | from feed2telegram import Feed2Telegram
|
---|
| 3 |
|
---|
| 4 | url = '<url>'
|
---|
| 5 | token = '<telegram-bot-token>'
|
---|
| 6 |
|
---|
| 7 | f2t = None
|
---|
| 8 |
|
---|
| 9 | def getIterator(feed):
|
---|
| 10 | return reversed(feed.entries)
|
---|
| 11 |
|
---|
| 12 | def getMessage(entry):
|
---|
| 13 | return entry['link']
|
---|
| 14 |
|
---|
| 15 | def 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 ...
|
---|
| 29 | def interrupt(signum, frame):
|
---|
| 30 | f2t.stop()
|
---|
| 31 |
|
---|
| 32 | def runWithThreading():
|
---|
| 33 | import signal
|
---|
| 34 | signal.signal(signal.SIGINT, interrupt)
|
---|
| 35 |
|
---|
| 36 | createInstance(True)
|
---|
| 37 |
|
---|
| 38 | f2t.start() # returned
|
---|
| 39 | f2t.join() # blocked
|
---|
| 40 |
|
---|
| 41 | def withoutThreading():
|
---|
| 42 | createInstance(False)
|
---|
| 43 |
|
---|
| 44 | f2t.start() # blocked
|
---|
| 45 |
|
---|
| 46 | def main():
|
---|
| 47 | withoutThreading()
|
---|
| 48 |
|
---|
| 49 | if __name__ == '__main__':
|
---|
| 50 | main()
|
---|
| 51 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.