Skip to content

Commit

Permalink
Moar doc.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasofthings committed Oct 18, 2015
1 parent 26a9534 commit e09e70b
Showing 1 changed file with 38 additions and 22 deletions.
60 changes: 38 additions & 22 deletions social/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,26 @@
logger = logging.getLogger(__name__)


def tweets(url):
def facebook(url):
"""
.. py:function:: tweets(url)
.. py:function:: facebook(url)
Get the number of tweets containing the provided URL.
Get the number of shares, likes and comments on facebook
for the provided URL.
..
"""
twitter_count = "http://urls.api.twitter.com/1/urls/count.json?url=%s"
query = twitter_count % (url)
facebook_count = \
'http://graph.facebook.com/%s'
query = facebook_count % (url)
resp = requests.get(query)

if resp.status_code == 200:
js = json.loads(resp.text)
return (
json.loads(resp.text)['count'],
js.get('shares', 0),
js.get('likes', 0),
js.get('comments', 0),
)
else:
raise Exception
Expand All @@ -56,24 +61,14 @@ def linkedin(url):
raise Exception


def facebook(url):
facebook_count = \
'http://graph.facebook.com/%s'
query = facebook_count % (url)
resp = requests.get(query)

if resp.status_code == 200:
js = json.loads(resp.text)
return (
js.get('shares', 0),
js.get('likes', 0),
js.get('comments', 0),
)
else:
raise Exception
def plusone(url):
"""
.. py:function:: plusone(url)
Get the number of plusones for the provided URL from Google+.
def plusone(url):
.. ToDo:: broken.
"""
queryurl = "https://clients6.google.com/rpc"
params = {
"method": "pos.plusones.get",
Expand Down Expand Up @@ -117,3 +112,24 @@ def plusone(url):
raise KeyError(e)

return (result, )


def tweets(url):
"""
.. py:function:: tweets(url : string)
Get the number of tweets containing the provided URL.
:return: the number of tweets
:rtype: Tuple
"""
twitter_count = "http://urls.api.twitter.com/1/urls/count.json?url=%s"
query = twitter_count % (url)
resp = requests.get(query)

if resp.status_code == 200:
return (
json.loads(resp.text)['count'],
)
else:
raise Exception

0 comments on commit e09e70b

Please sign in to comment.