# -*- coding: utf-8 -*-
__author__ = 'Christian Berg'

import urllib

from datetime import datetime
from django.core.management.base import BaseCommand
from django.conf import settings
import json


class Command(BaseCommand):
    help = "Synchornisiert den Facenbook Feed für die Anzeige auf der Homepage"


    def handle(self, *args, **options):
        #graph_api = facebook.GraphAPI(settings.FACEBOOK_ACCESS_TOKEN)
        #facebook_page = graph_api.get_object(settings.FACEBOOK_APP_ID+'/feed/')
        #print facebook_page
        #print graph_api.get_connections(facebook_page['id'], )
        self.login()

    def login(self):
        args = {'access_token': settings.FACEBOOK_ACCESS_TOKEN}
        query = "https://graph.facebook.com/{object}/feed?{args}".format(
            object=settings.FACEBOOK_APP_ID,
            args=urllib.urlencode(args),
        )
        print query
        request = urllib.urlopen(query)
        print request
        response = request.read()
        print response
        print json.loads(response)