comparison src/plugins/plugin_xep_0277.py @ 1935:1128feb54180

core: removed pyfeed and xe dependencies: pyfeed and xe where still used only for date format handling, and there is already dateutil which is a dependency of Wokkel. Furthermore pyfeed and xe are still not on pypi, causing troubles for installation with pip
author Goffi <goffi@goffi.org>
date Sun, 17 Apr 2016 17:08:12 +0200
parents 2daf7b4c6756
children 627cc6120c0e
comparison
equal deleted inserted replaced
1934:2daf7b4c6756 1935:1128feb54180
26 from twisted.internet import defer 26 from twisted.internet import defer
27 from twisted.python import failure 27 from twisted.python import failure
28 from sat.core import exceptions 28 from sat.core import exceptions
29 from sat.tools import xml_tools 29 from sat.tools import xml_tools
30 from sat.tools import sat_defer 30 from sat.tools import sat_defer
31 from sat.tools import utils
31 from sat.tools.common import data_format 32 from sat.tools.common import data_format
32 33
33 # XXX: tmp.pubsub is actually use instead of wokkel version 34 # XXX: tmp.pubsub is actually use instead of wokkel version
34 from wokkel import pubsub 35 from wokkel import pubsub
35 try:
36 from feed.date import rfc3339
37 except ImportError:
38 raise exceptions.MissingModule(u"Missing module pyfeed, please download/install it from http://home.avvanta.com/~steveha/pyfeed.html")
39 import uuid 36 import uuid
40 import time 37 import time
38 import dateutil
39 import calendar
41 import urlparse 40 import urlparse
42 41
43 NS_MICROBLOG = 'urn:xmpp:microblog:0' 42 NS_MICROBLOG = 'urn:xmpp:microblog:0'
44 NS_ATOM = 'http://www.w3.org/2005/Atom' 43 NS_ATOM = 'http://www.w3.org/2005/Atom'
45 NS_PUBSUB_EVENT = "{}{}".format(pubsub.NS_PUBSUB, "#event") 44 NS_PUBSUB_EVENT = "{}{}".format(pubsub.NS_PUBSUB, "#event")
250 try: 249 try:
251 updated_elt = entry_elt.elements(NS_ATOM, 'updated').next() 250 updated_elt = entry_elt.elements(NS_ATOM, 'updated').next()
252 except StopIteration: 251 except StopIteration:
253 msg = u'No atom updated element found in the pubsub item {}'.format(id_) 252 msg = u'No atom updated element found in the pubsub item {}'.format(id_)
254 raise failure.Failure(exceptions.DataError(msg)) 253 raise failure.Failure(exceptions.DataError(msg))
255 microblog_data[u'updated'] = unicode(rfc3339.tf_from_timestamp(unicode(updated_elt))) 254 microblog_data[u'updated'] = unicode(calendar.timegm(dateutil.parser.parse(unicode(updated_elt)).utctimetuple()))
256 try: 255 try:
257 published_elt = entry_elt.elements(NS_ATOM, 'published').next() 256 published_elt = entry_elt.elements(NS_ATOM, 'published').next()
258 except StopIteration: 257 except StopIteration:
259 microblog_data[u'published'] = microblog_data[u'updated'] 258 microblog_data[u'published'] = microblog_data[u'updated']
260 else: 259 else:
261 microblog_data[u'published'] = unicode(rfc3339.tf_from_timestamp(unicode(published_elt))) 260 microblog_data[u'published'] = unicode(calendar.timegm(dateutil.parser.parse(unicode(published_elt)).utctimetuple()))
262 261
263 # links 262 # links
264 for link_elt in entry_elt.elements(NS_ATOM, 'link'): 263 for link_elt in entry_elt.elements(NS_ATOM, 'link'):
265 if link_elt.getAttribute('rel') == 'replies' and link_elt.getAttribute('title') == 'comments': 264 if link_elt.getAttribute('rel') == 'replies' and link_elt.getAttribute('title') == 'comments':
266 key = check_conflict('comments', True) 265 key = check_conflict('comments', True)
419 pass 418 pass
420 419
421 ## published/updated time ## 420 ## published/updated time ##
422 current_time = time.time() 421 current_time = time.time()
423 entry_elt.addElement('updated', 422 entry_elt.addElement('updated',
424 content=rfc3339.timestamp_from_tf(float(data.get('updated', current_time)))) 423 content = utils.xmpp_date(float(data.get('updated', current_time))))
425 entry_elt.addElement('published', 424 entry_elt.addElement('published',
426 content=rfc3339.timestamp_from_tf(float(data.get('published', current_time)))) 425 content = utils.xmpp_date(float(data.get('published', current_time))))
427 426
428 ## categories ## 427 ## categories ##
429 for tag in data_format.dict2iter("tag", data): 428 for tag in data_format.dict2iter("tag", data):
430 category_elt = entry_elt.addElement("category") 429 category_elt = entry_elt.addElement("category")
431 category_elt['term'] = tag 430 category_elt['term'] = tag