summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/blog/models.py2
-rw-r--r--apps/links/tumblr.py379
-rw-r--r--apps/links/utils.py7
-rw-r--r--templates/details/fck_digg.html21
4 files changed, 217 insertions, 192 deletions
diff --git a/apps/blog/models.py b/apps/blog/models.py
index e598f14..f354bab 100644
--- a/apps/blog/models.py
+++ b/apps/blog/models.py
@@ -15,7 +15,7 @@ from locations.models import Location,Region
#from locations.signals import create_location_item
def get_upload_path(self, filename):
- return "%s/post-thumbs/%s/%s" %(settings.IMAGES_ROOT, datetime.datetime.today().strftime("%Y"), filename)
+ return "images/post-thumbs/heloo/%s/%s" %(datetime.datetime.today().strftime("%Y"), filename)
def markdown_processor(md):
processed = markdown.markdown(md, safe_mode = False).split('<break>')
diff --git a/apps/links/tumblr.py b/apps/links/tumblr.py
index 09c3394..8c0e286 100644
--- a/apps/links/tumblr.py
+++ b/apps/links/tumblr.py
@@ -37,203 +37,204 @@ PAGESIZE = 50
class TumblrError(Exception):
- ''' General Tumblr error '''
- def __init__(self, msg):
- self.msg = msg
+ ''' General Tumblr error '''
+ def __init__(self, msg):
+ self.msg = msg
- def __str__(self):
- return self.msg
+ def __str__(self):
+ return self.msg
class TumblrAuthError(TumblrError):
- ''' Wraps a 403 result '''
- pass
+ ''' Wraps a 403 result '''
+ pass
class TumblrRequestError(TumblrError):
- ''' Wraps a 400 result '''
- pass
+ ''' 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]
+ 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)
- 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)
+ 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
+ pass
diff --git a/apps/links/utils.py b/apps/links/utils.py
index d8463e0..b94f196 100644
--- a/apps/links/utils.py
+++ b/apps/links/utils.py
@@ -108,11 +108,14 @@ def sync_delicious_links(*args, **kwargs):
email_link(l)
if l.status == 1:
+ pass
post_to_tumblr(l)
- send_to_deliciousfb(l)
+ #send_to_deliciousfb(l)
if(dupe):
break
-
+
+
+
"""
b, created = Link.objects.get_or_create(
url = info['href'],
diff --git a/templates/details/fck_digg.html b/templates/details/fck_digg.html
new file mode 100644
index 0000000..4a4be88
--- /dev/null
+++ b/templates/details/fck_digg.html
@@ -0,0 +1,21 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
+ "http://www.w3.org/TR/html4/strict.dtd">
+<html lang="en">
+<head>
+ <title>{% block pagetitle %}Luxagraf - Topografical Writings{% endblock %}</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <style>
+ body { text-align: center; }
+ </style>
+</head>
+<body>
+
+<p>Dear Digg,</p>
+
+<p><b>PISS OFF</b></p>
+
+<p>&mdash;your friend, luxagraf</p>
+
+<p style="font-size: 80%; width: 100px;">Framing breaks bookmarking, it breaks copy-and-paste from the location field, it breaks your browser history, it breaks bookmarklets. There&#8217;s nothing OK about it.</p>
+</body>
+</html> \ No newline at end of file