Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added foursquare mediacontent service #20

Merged
merged 2 commits into from

2 participants

@astagi

No description provided.

@satanas satanas merged commit 18d3f97 into satanas:master
@satanas
Owner

This is becoming great! :D Merge done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 13, 2012
  1. @astagi
  2. @astagi

    Added foursquare module

    astagi authored
This page is out of date. Refresh to see the latest.
View
4 libturpial/api/models/mediacontent.py
@@ -10,6 +10,7 @@
IMAGE_CONTENT = 0
VIDEO_CONTENT = 1
+MAP_CONTENT = 2
class MediaContent(object):
def __init__(self, type_, name, content, path=None, info=None):
@@ -36,3 +37,6 @@ def is_video(self):
def is_image(self):
return self.type_ == IMAGE_CONTENT
+ def is_map(self):
+ return self.type_ == MAP_CONTENT
+
View
4 libturpial/api/services/showmedia/__init__.py
@@ -10,11 +10,13 @@
from libturpial.api.services.showmedia.instagram import InstagramMediaContent
from libturpial.api.services.showmedia.pictwitter import PicTwitterMediaContent
from libturpial.api.services.showmedia.youtube import YouTubeMediaContent
+from libturpial.api.services.showmedia.foursquare import FoursquareMediaContent
SHOWMEDIA_SERVICES = {
'twitpic': TwitpicMediaContent(),
'yfrog': YfrogMediaContent(),
'instagram': InstagramMediaContent(),
'pic.twitter.com': PicTwitterMediaContent(),
- 'youtube' : YouTubeMediaContent()
+ 'youtube' : YouTubeMediaContent(),
+ 'foursquare' : FoursquareMediaContent()
}
View
30 libturpial/api/services/showmedia/foursquare.py
@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+
+"""Foursquare show media content service"""
+#
+# Author: Andrea Stagi (aka 4ndreaSt4gi)
+# 2012-03-12
+
+import traceback
+import urllib
+from libturpial.api.models.mediacontent import *
+from libturpial.api.services.showmedia.base import *
+from libturpial.api.interfaces.service import ServiceResponse
+
+class FoursquareMediaContent(ShowMediaService):
+ def __init__(self):
+ ShowMediaService.__init__(self)
+ self.url_pattern = "(http(s)?://)?4sq.com"
+
+ def do_service(self, url):
+ try:
+ long_url = urllib.urlopen(url).geturl()
+ url_parts = long_url.split("foursquare.com")
+ path = "%s%s%s" % (url_parts[0], "foursquare.com/oembed", url_parts[1])
+ info = {}
+ info['width'] = 436
+ info['height'] = 357
+ return ServiceResponse(MediaContent(MAP_CONTENT, url, long_url, path, info))
+ except Exception, error:
+ self.log.debug("Error: %s\n%s" % (error, traceback.print_exc()))
+ return ServiceResponse(err=True, err_msg=_('Problem showing media content'))
Something went wrong with that request. Please try again.