Skip to content
Snippets Groups Projects
Commit 812811cf authored by murych's avatar murych
Browse files

избавляемся от facebook'a окончательно

parent c14298a0
No related branches found
No related tags found
No related merge requests found
import facebook
from slacker import Slacker
from vk import Session, API
 
Loading
Loading
Loading
Loading
@@ -5,7 +5,5 @@ try:
bot_secret_ = os.environ.get('SLACK_BOT_SECRET')
channel_ = os.environ.get('CHANNEL')
text_ = os.environ.get('TEXT')
page_id_ = os.environ.get('PAGE_ID')
access_token_ = os.environ.get('ACCESS_TOKEN')
except KeyError:
print('no eniromental variables detected\nmake sure to set them')
Loading
Loading
@@ -25,11 +25,6 @@ def callback():
slack_message = Slack(post=post).create_message()
Slack.send_message(auth=slack, channel=channel_, text=text_, attachments=slack_message)
 
facebook_post = Facebook(post=post)
facebook_attachment = facebook_post.create_message()
facebook_text = facebook_post.get_text(post=post)
Facebook.send_message(auth=facebook, text=facebook_text, attachment=facebook_attachment)
return 'ok', 200
 
 
Loading
Loading
Loading
Loading
@@ -100,42 +100,6 @@ class Slack(object):
as_user=as_user)
 
 
class Facebook(object):
def __init__(self, post):
try:
if post['attachments']:
for attachment in post['attachments']:
if attachment['type'] == 'photo':
image = post['attachments'][0]['photo']
image_url, _ = get_image(image)
elif attachment['type'] == 'link':
link = attachment['link']
self.picture = image_url
self.name = link['title']
self.link = link['url']
self.caption = link['title']
self.description = link['description']
except KeyError:
self.name, self.link, self.caption, self.description, self.picture = \
None, None, None, None, None
def create_message(self):
return {
'name' : self.name,
'link' : self.link,
'caption' : self.caption,
'description': self.description,
'picture' : self.picture,
}
@staticmethod
def get_text(post):
return post['text']
@staticmethod
def send_message(auth, text, attachment):
auth.put_wall_post(message=text, attachment=attachment)
 
def get_image(photo):
try:
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment