def new_bm(d, feedk): feed = feedk.get() bm = Bookmarks() bm.feed = feed.key bm.user = feed.user bm.original = d['link'] bm.title = d['title'] try: bm.comment = d['description'] except KeyError: bm.comment = 'no comment' bm.tags = feed.tags bm.put() deferred.defer(main_parser, bm.key, _target="worker", _queue="parser")
def get(self): old = Bookmarks.get_by_id(int(self.request.get('bm'))) deferred.defer(submit_bm, feed=None, user=users.get_current_user(), title=old.title, url=old.url, comment=old.comment)
def get(self): bm = Bookmarks.get_by_id(int(self.request.get('bm'))) if users.get_current_user() == bm.user: if bm.trashed == False: bm.trashed = True bm.archived = False bm.put() else: bm.key.delete()
def get(self): delete_url = self.get_query_argument('delete', None) if delete_url: d = Bookmarks.delete().where(Bookmarks.url == delete_url) d.execute() offset = self.get_query_argument('offset', 1) if offset: offset = int(offset) self.render('bookmarks.html', offset=offset)
def get(self): bm = Bookmarks.get_by_id(int(self.request.get('bm'))) if users.get_current_user() == bm.user: def txn(): bm.url = self.request.get('url').encode('utf8') bm.title = self.request.get('title').encode('utf8') bm.comment = self.request.get('comment').encode('utf8') bm.put() ndb.transaction(txn) self.redirect('/')
def get(self): bm = Bookmarks.get_by_id(int(self.request.get('bm'))) tag = Tags.get_by_id(int(self.request.get('tag'))) # if users.get_current_user() == bm.user: bm.tags.remove(tag.key) bm.put() template = jinja_environment.get_template('tags.html') values = {'bm': bm} tags = template.render(values) self.response.write(tags)
def get(self): bm = Bookmarks.get_by_id(int(self.request.get('bm'))) if users.get_current_user() == bm.user: if bm.shared == False: bm.shared = True html = '<i class="icon-eye-open"></i> shared' else: bm.shared = False html = '<i class="icon-eye-close"></i>' bm.put() self.response.write(html)
def get(self): bm = Bookmarks.get_by_id(int(self.request.get('bm'))) if users.get_current_user() == bm.user: if bm.starred == False: bm.starred = True html = '<i class="icon-star">' else: bm.starred = False html = '<i class="icon-star-empty">' bm.put() self.response.write(html)
def delicious(tag, comment, user): link = tag.a bm = Bookmarks() def txn(): bm.original = link['href'] bm.title = link.text bm.comment = comment bm.user = user bm.put() ndb.transaction(txn) deferred.defer(main_parser, bm.key, _target="worker", _queue="parser")
def daily_digest(uik): ui = uik.get() delta = datetime.timedelta(days=1) now = datetime.datetime.now() period = now - delta bmq = Bookmarks.query(Bookmarks.user == ui.user, Bookmarks.trashed == False, Bookmarks.data > period).order(-Bookmarks.data) title = '[%s] Daily digest for your activity: %s' % (app_identity.get_application_id(), dtf(now)) template = jinja_environment.get_template('digest.html') values = {'bmq': bmq, 'title': title} html = template.render(values) if bmq.get() != None: deferred.defer(send_digest, ui.email, html, title)
def feed_digest(feedk): import datetime, time timestamp = time.time() - 87000 period = datetime.datetime.fromtimestamp(timestamp) feed = feedk.get() bmq = Bookmarks.query(Bookmarks.user == feed.user) bmq = bmq.filter(Bookmarks.feed == feed.key) bmq = bmq.filter(Bookmarks.trashed == False) bmq = bmq.filter(Bookmarks.create > period) bmq = bmq.order(-Bookmarks.create) title = '(%s) Daily digest for %s' % (app_identity.get_application_id(), feed.blog) template = jinja_environment.get_template('digest.html') values = {'bmq': bmq, 'title': title} html = template.render(values) if bmq.get(): deferred.defer(send_digest, feed.user.email(), html, title, _target="worker", _queue="emails")
def feed_digest(feedk): delta = datetime.timedelta(days=1) now = datetime.datetime.now() period = now - delta feed = feedk.get() bmq = Bookmarks.query(Bookmarks.user == feed.user, Bookmarks.feed == feed.key, Bookmarks.trashed == False, Bookmarks.data > period).order(-Bookmarks.data) title = '[%s] Daily digest for %s' % (app_identity.get_application_id(), feed.title) template = jinja_environment.get_template('digest.html') values = {'bmq': bmq, 'title': title} html = template.render(values) if bmq.get() != None: deferred.defer(send_digest, feed.user.email(), html, title) queue = [] for bm in bmq: bm.trashed = True queue.append(bm) ndb.put_multi(queue)
def main_parser(bmk): import urlparse bm = bmk.get() try: result = urlfetch.fetch(url=bm.original, follow_redirects=True, allow_truncated=True, deadline=600) if result.status_code == 200 and result.final_url: a = result.final_url else: a = bm.original except: a = bm.original b = a.split('?utm_source')[0] c = b.split('&feature')[0] bm.url = c.encode('utf8') # TAGS q = Bookmarks.query(Bookmarks.user == bm.user, Bookmarks.original == bm.original) if q.count() > 1: tag_list = [] for e in q: for t in e.tags: if t not in tag_list: tag_list.append(t) bm.tags = tag_list ekeys = [e.key for e in q] ekeys.remove(bm.key) for ekey in ekeys: e = ekey.get() e.tags = [] e.trashed = True e.put() # COMMENTS url_parsed = urlparse.urlparse(bm.url) query = urlparse.parse_qs(url_parsed.query) if url_parsed.netloc == 'www.youtube.com': video = query["v"][0] bm.url = 'http://www.youtube.com/watch?v=%s' % video bm.comment = '''<iframe width="640" height="360" src="http://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>''' % video if url_parsed.netloc == 'vimeo.com': video = url_parsed.path.split('/')[-1] bm.url = 'http://vimeo.com/%s' % video bm.comment = '''<iframe src="http://player.vimeo.com/video/%s?color=ffffff" width="640" height="360" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>''' % video ext = bm.url.split('.')[-1] if ext == 'jpg' or ext == 'png' or ext == 'jpeg': bm.comment = '<img src="%s" />' % bm.url if bm.title == '': bm.title = url_parsed.path bm.domain = url_parsed.netloc bm.put() try: if bm.feed.get().notify == 'email': deferred.defer(utils.send_bm, bm.key, _target="worker", _queue="emails") except: if bm.ha_mys: deferred.defer(utils.send_bm, bm.key, _target="worker", _queue="emails")
def get(self): bm = Bookmarks.get_by_id(int(self.request.get('bm'))) template = jinja_environment.get_template('other_tags.html') values = {'bm': bm} other_tags = template.render(values) self.response.write(other_tags)
def get(self): bm = Bookmarks.get_by_id(int(self.request.get('bm'))) template = jinja_environment.get_template('edit.html') values = {'bm': bm} html_page = template.render(values) self.response.write(html_page)
def get(self): bm = Bookmarks.get_by_id(int(self.request.get('bm'))) self.response.write(bm.comment)
def submit_bm(feed, user, title, url, comment): bm = Bookmarks() result = urlfetch.fetch(url=url, follow_redirects=True, allow_truncated=True, deadline=60) if result.status_code == 200 and result.final_url: a = result.final_url elif result.status_code == 500: pass else: a = url url_candidate = a.lstrip().rstrip().split('?utm_source')[0].split('&feature')[0] copie = Bookmarks.query(Bookmarks.url == url_candidate, Bookmarks.user == user, Bookmarks.trashed == False) if copie.get(): for cp in copie: cp.archived = False cp.put() url_parsed = urlparse(url_candidate) query = parse_qs(url_parsed.query) name = url_parsed.path.split('/')[-1] ext = name.split('.')[-1].lower() bm.title = url_candidate if title == '' or None else title if url_parsed.netloc == 'www.youtube.com': bm.url = 'http://www.youtube.com/watch?v=%s' % query["v"][0] bm.comment = """<embed width="640" height="360" src="http://www.youtube.com/v/%s" type="application/x-shockwave-flash"> </embed>""" % query["v"][0] elif url_parsed.netloc == 'vimeo.com': bm.url = 'http://vimeo.com/%s' % name bm.comment = '''<iframe src="http://player.vimeo.com/video/%s?color=ffffff" width="640" height="360" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>''' % name elif ext in ['jpg', 'png', 'jpeg', 'gif']: bm.url = url_candidate blob_key = upload_to_blobstore(url_candidate, ext) bm.comment = '<img src="%s" />' % images.get_serving_url(blob_key, size=1600) else: bm.comment = comment bm.url = url_candidate bm.domain = url_parsed.netloc bm.user = user bm.feed = feed bm.put() Bookmarks.index_bm(bm.key) ui = UserInfo.get_or_insert(str(user.user_id()), user=user) if feed == None and ui.mys == True: deferred.defer(util.send_bm, bm.key, _queue="user") elif feed != None and feed.get().notify == 'email': deferred.defer(util.send_bm, bm.key)
def index(): # for bookmark in Bookmarks.all(): # print(bookmark.name) bookmarks = Bookmarks.all() print(len(bookmarks)) return render_template('index.html', bookmarks=bookmarks)
def get(self): bmq = Bookmarks.query(Bookmarks.user == users.get_current_user()) bmq = bmq.filter(Bookmarks.trashed == True) bmq = bmq.order(-Bookmarks.data).fetch() ndb.delete_multi([bmk.key for bmk in bmq]) self.redirect(self.request.referer)
def get(self): for bm in Bookmarks.query(): deferred.defer(add_domain, bm.key, _target="worker", _queue="admin")