summaryrefslogtreecommitdiff
path: root/apps/links
diff options
context:
space:
mode:
Diffstat (limited to 'apps/links')
-rw-r--r--apps/links/__init__.py0
-rw-r--r--apps/links/admin.py14
-rw-r--r--apps/links/detail_urls.py13
-rw-r--r--apps/links/models.py76
-rw-r--r--apps/links/retriever.py111
-rw-r--r--apps/links/tumblr.py240
-rw-r--r--apps/links/urls.py15
7 files changed, 0 insertions, 469 deletions
diff --git a/apps/links/__init__.py b/apps/links/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/apps/links/__init__.py
+++ /dev/null
diff --git a/apps/links/admin.py b/apps/links/admin.py
deleted file mode 100644
index 2c73c76..0000000
--- a/apps/links/admin.py
+++ /dev/null
@@ -1,14 +0,0 @@
-from django.contrib import admin
-
-from links.models import Link
-
-class LinkAdmin(admin.ModelAdmin):
- list_display = ('title', 'rating', 'pub_date', 'status')
- search_fields = ['title','description','url']
- list_filter = ['rating', 'status']
- fieldsets = (
- (None, {'fields': ('title','url','description','rating')}),
- ('Details', {'fields': ('screen_url', 'pub_date', 'link_id', 'tags', 'status'), 'classes': 'collapse'}),
- )
-
-admin.site.register(Link, LinkAdmin) \ No newline at end of file
diff --git a/apps/links/detail_urls.py b/apps/links/detail_urls.py
deleted file mode 100644
index 2b6ec5d..0000000
--- a/apps/links/detail_urls.py
+++ /dev/null
@@ -1,13 +0,0 @@
-from django.conf.urls.defaults import *
-from django.views.generic.simple import redirect_to
-from links.models import Link
-
-
-detail_dict = {
- 'queryset': Link.objects.filter(status__exact=1),
-}
-urlpatterns = patterns('django.views.generic.list_detail',
- (r'^$', redirect_to, {'url': '/links/1/'}),
- (r'^(?P<object_id>\d+)/$', 'object_detail', dict(detail_dict, template_name='details/link.html')),
-)
-
diff --git a/apps/links/models.py b/apps/links/models.py
deleted file mode 100644
index 09acc1c..0000000
--- a/apps/links/models.py
+++ /dev/null
@@ -1,76 +0,0 @@
-import datetime
-
-from django.db import models
-from django.contrib.syndication.feeds import Feed
-from django.contrib.sitemaps import Sitemap
-
-from taggit.managers import TaggableManager
-
-RATINGS = (
- ('1', "1 Star"),
- ('2', "2 Stars"),
- ('3', "3 Stars"),
- ('4', "4 Stars"),
- ('5', "5 Stars"),
-)
-
-DEBUG = 1
-
-class Link(models.Model):
- link_id = models.CharField(max_length=60, blank=True, null=True)
- title = models.CharField(max_length=400)
- url = models.CharField(max_length=400)
- description = models.TextField(blank=True, null=True)
- screen_url = models.CharField(max_length=400, blank=True, null=True)
- rating = models.CharField(max_length=1, choices=RATINGS, null=True)
- pub_date = models.DateTimeField()
- PUB_STATUS = (
- (0, 'Private'),
- (1, 'Public'),
- )
- status = models.IntegerField(choices=PUB_STATUS, default=0)
- tags = TaggableManager(blank=True)
-
- class Meta:
- ordering = ['-pub_date']
-
- def __unicode__(self):
- return self.title
-
- def get_absolute_url(self):
- return self.url
-
- def get_model_name(self):
- return 'link'
-
- def get_previous_published(self):
- return self.get_previous_by_pub_date(status__exact=1)
-
- def get_next_published(self):
- return self.get_next_by_pub_date(status__exact=1)
-
-
- def get_thumbnail_url(self):
- return "http://images.luxagraf.net/magnolia_thumbs/%s" %(self.screen_url)
- def comment_period_open(self):
- return self.enable_comments and datetime.datetime.today() - datetime.timedelta(30) <= self.pub_date
-
-
-class LinkSitemap(Sitemap):
- changefreq = "never"
- priority = 0.4
-
- def items(self):
- return Link.objects.filter(status=1)
-
- def lastmod(self, obj):
- return obj.pub_date
-
-class LatestLinks(Feed):
- title = "Luxagraf: Links"
- link = "http://ma.gnolia.com/people/luxagraf/bookmarks"
- description = "Links to interesting stuff"
- description_template = 'feeds/links_description.html'
-
- def items(self):
- return Link.objects.filter(status__exact=1).order_by('-pub_date')[:10]
diff --git a/apps/links/retriever.py b/apps/links/retriever.py
deleted file mode 100644
index f876405..0000000
--- a/apps/links/retriever.py
+++ /dev/null
@@ -1,111 +0,0 @@
-import datetime
-
-from django.core.exceptions import ObjectDoesNotExist
-from django.template.defaultfilters import striptags
-from django.core.mail import EmailMessage
-from django.conf import settings
-
-
-from utils.strutils import safestr,unquotehtml
-from links.models import Link
-from utils import pinboard
-
-def sync_pinboard_links():
- """
- sync bookmarks from my pinboard account
-
- dependancies: python-pinboard https://github.com/mgan59/python-pinboard/
- """
- p = pinboard.open(settings.PIN_USER, settings.PIN_PASS)
- dupe = False
- links = p.posts(count=30)
- for link in links:
- try:
- #check to see if link exists
- row = Link.objects.get(link_id=safestr(link['hash']))
- except ObjectDoesNotExist:
- l, created = Link.objects.get_or_create(
- title = link['description'],
- link_id = safestr(link['hash']),
- url = safestr(link['href']),
- description = safestr(link['extended']),
- rating = "3",
- pub_date = datetime.datetime.strptime(link['time'], "%Y-%m-%dT%H:%M:%SZ"),
- status = 0
- )
- print l.title
- if created:
- print l.title
- for t in link['tags']:
- l.tags.add(t)
- email_link(l)
-
-'''
-def sync_delicious_links(*args, **kwargs):
- b = delicious.get_all(settings.DELICIOUS_USER, settings.DELICIOUS_PASS)
- dupe = False
- for post in b:
- taglist = []
- try:
- row = Link.objects.get(magnolia_id=safestr(post['hash']))
- # If the row exists already, set the dupe flag
- dupe = True
- except ObjectDoesNotExist:
- #f = copy_file(safestr(post.findtext('screenshot')), safestr(info['id']))
- #fake the image since delicious doesn't offer them
- local_image_url = "%s/%s.jpg" %(safestr(datetime.datetime.today().strftime("%b").lower()), safestr(post['hash']))
- tags = str(post['tag']).split(" ")
- for tag in tags:
- taglist.append(tag)
- for tag in taglist:
- if tag == '2lux':
- status = 1
- break
- else:
- status = 0
- descr = markdown.markdown(unquotehtml(safestr(post['extended'])), safe_mode = False)
- l, created = Link.objects.get_or_create(
- title = post['description'],
- magnolia_id = safestr(post['hash']),
- url = safestr(post['href']),
- description = descr,
- screen_url = local_image_url,
- #fake the rating since delicious doesn't offer such things
- rating = "3",
- pub_date = datetime.datetime.strptime(post['time'], "%Y-%m-%dT%H:%M:%SZ"),
- status = status,
- enable_comments = True,
- tags = ", ".join(t for t in taglist if t != "2lux")
- )
-
- email_link(l)
- if l.status == 1:
- pass
- #post_to_tumblr(l)
- #send_to_deliciousfb(l)
- if(dupe):
- break
-
-
-'''
-
-def email_link(link):
- """
- Sends an imported link to Gmail (never hurts to have backups)
- """
- subject = link.title
- body = "%s\n\n%s\n\n\nvisit site:%s\n" %(link.title, link.description, link.url)
- msg = EmailMessage(subject, striptags(body), 'sng@luxagraf.net', ['luxagraf+links@gmail.com'])
- msg.send()
- msg = EmailMessage(subject, striptags(body), 'sng@luxagraf.net', ['sng+links@luxagraf.net'])
- msg.send()
-
-'''
-def send_to_delicious(link):
- del_tags = ''
- tags = link.tags.split(',')
- for tag in tags:
- del_tags += tag.strip().replace(' ','_')+' '
- delicious.add(settings.DELICIOUS_USER, settings.DELICIOUS_PASS, link.url, link.title, tags = del_tags, extended = striptags(link.description), dt =safestr(link.pub_date), replace="no")
-
-''' \ No newline at end of file
diff --git a/apps/links/tumblr.py b/apps/links/tumblr.py
deleted file mode 100644
index 8c0e286..0000000
--- a/apps/links/tumblr.py
+++ /dev/null
@@ -1,240 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-# Copyright 2008 Ryan Cox ( ryan.a.cox@gmail.com ) All Rights Reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-'''A wrapper library for Tumblr's public web API: http://www.tumblr.com/api'''
-
-__author__ = 'ryan.a.cox@gmail.com'
-__version__ = '0.1'
-
-
-from urllib2 import Request, urlopen, URLError, HTTPError
-from urllib import urlencode, quote
-import base64
-import re
-
-try:
- import simplejson
-except ImportError:
- from django.utils import simplejson
-
-GENERATOR = 'python-tumblr'
-PAGESIZE = 50
-
-
-class TumblrError(Exception):
- ''' General Tumblr error '''
- def __init__(self, msg):
- self.msg = msg
-
- def __str__(self):
- return self.msg
-
-class TumblrAuthError(TumblrError):
- ''' Wraps a 403 result '''
- pass
-
-class TumblrRequestError(TumblrError):
- ''' Wraps a 400 result '''
- pass
-
-class TumblrIterator:
- def __init__(self, name, start, max, type):
- self.name = name
- self.start = start
- self.max = max
- self.type = type
- self.results = None
- self.index = 0
-
- def __iter__(self):
- return self
-
- def next(self):
- if not self.results or (self.index == len(self.results['posts'])):
- self.start += self.index
- self.index = 0
- url = "http://%s.tumblr.com/api/read/json?start=%s&num=%s" % (self.name,self.start, PAGESIZE)
- if self.type:
- url += "&type=" + self.type
- response = urlopen(url)
- page = response.read()
- m = re.match("^.*?({.*}).*$", page,re.DOTALL | re.MULTILINE | re.UNICODE)
- self.results = simplejson.loads(m.group(1))
-
- if (self.index >= self.max) or len(self.results['posts']) == 0:
- raise StopIteration
-
- self.index += 1
- return self.results['posts'][self.index-1]
-
-class Api:
- def __init__(self, name, email=None, password=None ):
- self.name = name
- self.is_authenticated = False
- self.email = email
- self.password = password
-
- def auth_check(self):
- if self.is_authenticated:
- return
- url = 'http://www.tumblr.com/api/write'
- values = {
- 'action': 'authenticate',
- 'generator' : GENERATOR,
- 'email': self.email,
- 'password' : self.password }
-
- data = urlencode(values)
- req = Request(url, data)
- try:
- response = urlopen(req)
- page = response.read()
- self.url = page
- self.is_authenticated = True
- return
- except HTTPError, e:
- if 403 == e.code:
- raise TumblrAuthError(str(e))
- if 400 == e.code:
- raise TumblrRequestError(str(e))
- except Exception, e:
- raise TumblrError(str(e))
-
-
- def write_regular(self, title=None, body=None, **args):
- if title:
- args['title'] = title
- if body:
- args['body'] = body
- args = self._fixnames(args)
- if not 'title' in args and not 'body' in args:
- raise TumblrError("Must supply either body or title argument")
-
- self.auth_check()
- args['type'] = 'regular'
- return self._write(args)
-
- def write_photo(self, source=None, **args):
- if source:
- args['source'] = source
-
- args = self._fixnames(args)
- if 'source' in args and 'data' in args:
- raise TumblrError("Must NOT supply both source and data arguments")
-
- if not 'source' in args and not 'data' in args:
- raise TumblrError("Must supply source or data argument")
-
- self.auth_check()
- args['type'] = 'photo'
- return self._write(args)
-
- def write_quote(self, quote=None, **args):
- if quote:
- args['quote'] = quote
- args = self._fixnames(args)
- if not 'quote' in args:
- raise TumblrError("Must supply quote arguments")
-
- self.auth_check()
- args['type'] = 'quote'
- return self._write(args)
-
- def write_link(self, url=None, **args):
- if url:
- args['url'] = url
- args = self._fixnames(args)
- if not 'url' in args:
- raise TumblrError("Must supply url argument")
-
- self.auth_check()
- args['type'] = 'link'
- return self._write(args)
-
- def write_conversation(self, conversation=None, **args):
- if conversation:
- args['conversation'] = conversation
- args = self._fixnames(args)
- if not 'conversation' in args:
- raise TumblrError("Must supply conversation argument")
-
- self.auth_check()
- args['type'] = 'conversation'
- return self._write(args)
-
- def write_video(self, embed=None, **args):
- if embed:
- args['embed'] = embed
- args = self._fixnames(args)
- if 'embed' in args and 'data' in args:
- raise TumblrError("Must NOT supply both embed and data arguments")
-
- if not 'embed' in args and not 'data' in args:
- raise TumblrError("Must supply embed or data argument")
-
- self.auth_check()
- args['type'] = 'video'
- return self._write(args)
-
- def _fixnames(self, args):
- for key in args:
- if '_' in key:
- value = args[key]
- del args[key]
- args[key.replace('_', '-')] = value
- return args
-
- def _write(self, params, headers=None):
- self.auth_check()
- url = 'http://www.tumblr.com/api/write'
- params['email'] = self.email
- params['password'] = self.password
- params['generator'] = GENERATOR
- data = urlencode(params)
- if headers:
- req = Request(url, data, headers)
- else:
- req = Request(url, data)
- newid = None
- try:
- urlopen(req)
- raise TumblrError("Error writing post")
-
- except HTTPError, e:
- if 201 == e.code:
- newid = e.read()
- return self.read(id=newid)
- raise TumblrError(e.read())
-
- def read(self, id=None, start=0,max=2**31-1,type=None):
- if id:
- url = "http://%s.tumblr.com/api/read/json?id=%s" % (self.name,id)
- print url
- response = urlopen(url)
- page = response.read()
- m = re.match("^.*?({.*}).*$", page,re.DOTALL | re.MULTILINE | re.UNICODE)
- results = simplejson.loads(m.group(1))
- if len(results['posts']) == 0:
- return None
-
- return results['posts'][0]
- else:
- return TumblrIterator(self.name,start,max,type)
-
-if __name__ == "__main__":
- pass
diff --git a/apps/links/urls.py b/apps/links/urls.py
deleted file mode 100644
index 5a16d6e..0000000
--- a/apps/links/urls.py
+++ /dev/null
@@ -1,15 +0,0 @@
-from django.conf.urls.defaults import *
-from django.views.generic import list_detail
-from django.views.generic.simple import redirect_to
-from links.models import Link
-
-photos_paged = {
- 'queryset': Link.objects.filter(status__exact=1).order_by('-pub_date'),
- 'paginate': True,
- 'page_url': '/links/%d/',
-}
-
-urlpatterns = patterns('',
- (r'^(?P<page>\d+)/$', list_detail.object_list, dict(photos_paged, template_name='archives/links.html')),
- (r'^$', redirect_to, {'url': '/links/1/'}),
-)