mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
New share by facebook.
This commit is contained in:
parent
ff0a44137b
commit
419013ca0e
6 changed files with 89 additions and 6 deletions
28
apps/social/migrations/0006_guid_hash.py
Normal file
28
apps/social/migrations/0006_guid_hash.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from south.db import db
|
||||
from south.v2 import DataMigration
|
||||
from django.db import models
|
||||
from apps.social.models import MSharedStory
|
||||
|
||||
class Migration(DataMigration):
|
||||
|
||||
def forwards(self, orm):
|
||||
shared_stories = MSharedStory.objects.filter(story_guid_hash__exists=False)
|
||||
count = shared_stories.count()
|
||||
|
||||
print "%s shared stories..." % count
|
||||
for s, story in enumerate(shared_stories):
|
||||
if s % 100 == 0:
|
||||
print "%s/%s" % (s+1, count)
|
||||
story.story_guid
|
||||
|
||||
def backwards(self, orm):
|
||||
"Write your backwards methods here."
|
||||
|
||||
models = {
|
||||
|
||||
}
|
||||
|
||||
complete_apps = ['social']
|
||||
symmetrical = True
|
|
@ -1057,6 +1057,7 @@ class MSharedStory(mongo.Document):
|
|||
story_author_name = mongo.StringField()
|
||||
story_permalink = mongo.StringField()
|
||||
story_guid = mongo.StringField(unique_with=('user_id',))
|
||||
story_guid_hash = mongo.StringField()
|
||||
story_tags = mongo.ListField(mongo.StringField(max_length=250))
|
||||
posted_to_services = mongo.ListField(mongo.StringField(max_length=20))
|
||||
mute_email_users = mongo.ListField(mongo.IntField())
|
||||
|
@ -1086,7 +1087,13 @@ class MSharedStory(mongo.Document):
|
|||
|
||||
@property
|
||||
def guid_hash(self):
|
||||
return hashlib.sha1(self.story_guid).hexdigest()
|
||||
if self.story_guid_hash:
|
||||
return self.story_guid_hash
|
||||
|
||||
self.story_guid_hash = hashlib.sha1(self.story_guid).hexdigest()
|
||||
self.save()
|
||||
|
||||
return self.story_guid_hash
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
|
@ -1107,7 +1114,8 @@ class MSharedStory(mongo.Document):
|
|||
if self.story_original_content:
|
||||
self.story_original_content_z = zlib.compress(self.story_original_content)
|
||||
self.story_original_content = None
|
||||
|
||||
|
||||
self.story_guid_hash = hashlib.sha1(self.story_guid).hexdigest()
|
||||
self.story_title = strip_tags(self.story_title)
|
||||
|
||||
self.comments = linkify(strip_tags(self.comments))
|
||||
|
@ -2022,9 +2030,20 @@ class MSocialServices(mongo.Document):
|
|||
return True
|
||||
|
||||
def post_to_facebook(self, message):
|
||||
self.calculate_image_sizes()
|
||||
content = zlib.decompress(self.story_content_z)[:1024]
|
||||
|
||||
try:
|
||||
api = self.facebook_api()
|
||||
api.put_wall_post(message=message)
|
||||
# api.put_wall_post(message=message)
|
||||
api.put_object('me', '%s:share' % settings.FACEBOOK_NAMESPACE,
|
||||
link=self.blurblog_permalink(),
|
||||
type="link",
|
||||
name=self.story_title,
|
||||
description=content,
|
||||
article=self.story_permalink,
|
||||
# message=message,
|
||||
)
|
||||
except facebook.GraphAPIError, e:
|
||||
print e
|
||||
return
|
||||
|
|
|
@ -386,7 +386,25 @@ def load_social_page(request, user_id, username=None, **kwargs):
|
|||
story['user_comments'] = shared_story.comments
|
||||
|
||||
stories = MSharedStory.attach_users_to_stories(stories, profiles)
|
||||
|
||||
|
||||
active_story = None
|
||||
path = request.META['PATH_INFO']
|
||||
if '/story/' in path and format != 'html':
|
||||
story_id = path.replace('/story/', '')
|
||||
active_story_db = MSharedStory.objects.filter(user_id=social_user.pk,
|
||||
story_guid_hash__startswith=story_id).limit(1)
|
||||
if active_story_db:
|
||||
active_story_db = active_story_db[0]
|
||||
active_story = Feed.format_story(active_story_db)
|
||||
if active_story_db.image_count:
|
||||
active_story['image_url'] = active_story_db.image_sizes[0]['url']
|
||||
active_story['tags'] = ', '.join(active_story_db.story_tags)
|
||||
if active_story['story_feed_id']:
|
||||
feed = Feed.get_by_id(active_story['story_feed_id'])
|
||||
if feed:
|
||||
active_story['feed'] = feed.canonical()
|
||||
print active_story
|
||||
|
||||
params = {
|
||||
'social_user' : social_user,
|
||||
'stories' : stories,
|
||||
|
@ -399,7 +417,9 @@ def load_social_page(request, user_id, username=None, **kwargs):
|
|||
'feeds' : feeds,
|
||||
'user_profile' : hasattr(user, 'profile') and user.profile,
|
||||
'has_next_page' : has_next_page,
|
||||
'holzer_truism' : random.choice(jennyholzer.TRUISMS) #if not has_next_page else None
|
||||
'holzer_truism' : random.choice(jennyholzer.TRUISMS), #if not has_next_page else None
|
||||
'facebook_app_id': settings.FACEBOOK_APP_ID,
|
||||
'active_story' : active_story,
|
||||
}
|
||||
|
||||
diff1 = checkpoint1-start
|
||||
|
|
|
@ -412,6 +412,7 @@ REDIS = {
|
|||
|
||||
FACEBOOK_APP_ID = '111111111111111'
|
||||
FACEBOOK_SECRET = '99999999999999999999999999999999'
|
||||
FACEBOOK_NAMESPACE = 'newsblur'
|
||||
TWITTER_CONSUMER_KEY = 'ooooooooooooooooooooo'
|
||||
TWITTER_CONSUMER_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
|
||||
|
||||
|
|
|
@ -10,6 +10,21 @@
|
|||
<link rel="icon" href="{{ social_profile.photo_url }}">
|
||||
<meta name="viewport" content="initial-scale=1, maximum-scale=1.5">
|
||||
|
||||
{% if active_story %}
|
||||
<meta property="fb:app_id" content="{{ facebook_app_id }}">
|
||||
<meta property="og:type" content="article">
|
||||
<meta property="og:url" content="{{ active_story.story_permalink }}">
|
||||
{% if active_story.feed %}
|
||||
<meta property="og:site_name" content="{{ active_story.feed.feed_title }}">
|
||||
{% endif %}
|
||||
<meta property="og:image" content="{{ active_story.image_url }}">
|
||||
<meta property="og:title" content="{{ active_story.story_title }}">
|
||||
<meta property="og:description" content="{{ active_story.story_content }}">
|
||||
<meta property="article:published_time" content="{{ active_story.story_date }}">
|
||||
<meta property="article:author" content="{{ active_story.story_authors }}">
|
||||
<meta property="article:tag" content="{{ active_story.tags }}">
|
||||
{% endif %}
|
||||
|
||||
{% include_stylesheets "blurblog" %}
|
||||
|
||||
{% if social_profile.custom_css %}
|
||||
|
|
|
@ -11,7 +11,7 @@ import time
|
|||
import s3
|
||||
from django.conf import settings
|
||||
|
||||
COLLECTIONS = "classifier_tag classifier_author classifier_feed classifier_title userstories starred_stories"
|
||||
COLLECTIONS = "classifier_tag classifier_author classifier_feed classifier_title userstories starred_stories shared_stories category category_site sent_emails social_profile social_subscription social_services statistics feedback"
|
||||
|
||||
date = time.strftime('%Y-%m-%d-%H-%M')
|
||||
collections = COLLECTIONS.split(' ')
|
||||
|
|
Loading…
Add table
Reference in a new issue