# -*- coding: utf-8 # Copyright 2006 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import FileField from Products.Archetypes.public import FileWidget from Products.Archetypes.public import OrderedBaseFolder, BaseContent, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME, TASK_TYPES, BLOG_TYPES from Common import CommonMix from urllib2 import URLError, HTTPError import time, urllib2, urllib schema = BaseSchema class GroupReferenceFolder(OrderedBaseFolder, CommonMix): """ GroupReferenceFolder""" meta_type = "GroupReferenceFolder" archetype_name = "Group Reference Folder" global_allow = 0 exclude_from_nav = True filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/base_view', 'permissions': ('View',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/base_edit', 'permissions': ('Access Denied',), }, { 'id':'metadata', 'name':'Properties', 'action':'string:${object_url}/base_metadata', 'permissions': ('Access Denied',), }, ) def __init__(self, id): self.id = id self.changed = 0 def changedornot(self): """ """ if not hasattr(self, 'changed'): self.changed = 0 return self.changed def setKeywords(self, keywords): REQUEST = self.REQUEST tags = [] alltags = [] self.changed = 1 self.keywords = keywords author = str(REQUEST.get('AUTHENTICATED_USER')) import datetime time = datetime.datetime.today() time = time.strftime("%Y-%m-%d %H:%M:%S") print 'Time:', time allreferences = self.getAllReferences() tags = keywords.split(',') for tag in tags: key = {} tag = tag.strip() alltags.append(tag) key['keyword'] = tag key['author'] = author key['time'] = time allreferences.append([time, key]) self.setAllReferences(allreferences) self.setTags(alltags) self._updateUpdated(0) tags = self.getTags() res = [] res_codes = [] for tag in tags: rresult_code, tagres = self.getBookmarksFromDelisious(tag) res_codes.append(rresult_code) res.append(tagres) #for x in res_codes: # if x: # return res self._setCachedResults(res) return self.REQUEST.RESPONSE.redirect(self.aq_parent.absolute_url()) def getKeywords(self): """ """ if not hasattr(self, 'keywords'): self.keywords = '' return self.keywords def setTags(self, val): self.alltags = val def getTags(self): """ """ if not hasattr(self, 'alltags'): self.alltags = 'kala' return self.alltags def getBookmarks(self): """ get bookmarks from del.icio.us """ lastu = self.getLastUpdate() print time.localtime(lastu), ">", time.localtime(time.time()-300) if lastu>time.time()-900: return self._getCachedResults() tags = self.getTags() res = [] res_codes = [] for tag in tags: rresult_code, tagres = self.getBookmarksFromDelisious(tag) res_codes.append(rresult_code) res.append(tagres) for x in res_codes: if x: return res self._setCachedResults(res) self._updateUpdated() return res def getBookmarksFromDelisious(self, keyword): """get bookmarks from del.icio.us""" if keyword == '': return 0, '' url = "http://del.icio.us/rss/tag/"+urllib.quote_plus(keyword) from socket import timeout items = [] print url try: f = urllib2.urlopen(url) except timeout: print 'timeout' return 1, [{'title': ' ' ,'link':'', 'keyword': keyword, 'len': 0}] except URLError: print 'url' return 1, [{'title': ' ' ,'link':'', 'keyword': keyword, 'len': 0}] except HTTPError: print 'http' return 1, [{'title': ' ' ,'link':'', 'keyword': keyword, 'len': 0}] html = f.read() import xml.dom.minidom dom = xml.dom.minidom.parseString(html) items = dom.getElementsByTagName("item") ItemsLength = len(items) self.setItemsLength(ItemsLength) res = [] counter = 0 if ItemsLength>3: ItemsLength = 3 while counter