Commit fa7135c3527462dba6d92d692dfa603b6513f60a

Authored by System Administrator ago
0 parents
Exists in master

first commit

Showing 12 changed files with 209 additions and 0 deletions Side-by-side Diff

insight/__init__.pyc View file @ fa7135c

No preview for this file type

insight/context.py View file @ fa7135c
... ... @@ -0,0 +1,96 @@
  1 +#!/usr/bin/env python
  2 +# -*- coding: utf-8 -*-
  3 +import requests
  4 +import json
  5 +import time
  6 +
  7 +
  8 +class Context() :
  9 +
  10 + token = ""
  11 +
  12 + orderlist = [529491587137957,858096217617804,1670879929842831,1406069429705944,1531526667169602,
  13 + 504207933048979,1531526667169602,270103526524526,1702892339935231,886456498082470,
  14 + 167968880220563,526019510826052,327293184069664 ,467342726674321,497899983625735,
  15 + 415438118555115,147088008818887,502626173152828,117352678358122,171144389693855,
  16 + 813554295420159,153258784853075]
  17 +
  18 + pagelist = {'529491587137957':'피키캐스트','858096217617804':'피키픽처스','1670879929842831':'피키예능촌',
  19 + '1406069429705944':'피키툰','1531526667169602':'피키키키키','504207933048979':'피키생활백서',
  20 + '1531526667169602':'피키키키키','270103526524526':'곰들의반란','1702892339935231':'궁금청년',
  21 + '886456498082470':'우주인','167968880220563':'끔켬','526019510826052':'언어유희왕',
  22 + '327293184069664':'연애의모든것','467342726674321':'너눈지','497899983625735':'베스트비디오',
  23 + '415438118555115':'남자기때문에','147088008818887':'도기도기','502626173152828':'여자라면',
  24 + '117352678358122':'영화는 방울방울','171144389693855':'영화공장','813554295420159':'피키무비',
  25 + '153258784853075':'플레이'}
  26 +
  27 +
  28 + def __init__(self, token):
  29 + print "context"
  30 + self.token = token
  31 +
  32 +
  33 + def getContextsFeed(self):
  34 +
  35 + return_val = []
  36 + for list in self.orderlist:
  37 + time.sleep(1)
  38 + url = 'https://graph.facebook.com/v2.5/%d/feed?'%list
  39 + txt = requests.get(url + self.token).text
  40 + data = json.loads(txt)
  41 + return_val.append(data)
  42 + return return_val
  43 +
  44 + def getContextsFeedAll(self):
  45 +
  46 + return_val = []
  47 + for list in self.orderlist:
  48 + time.sleep(1)
  49 + url = 'https://graph.facebook.com/v2.5/%d/feed?'%list
  50 + txt = requests.get(url + self.token).text
  51 + data = json.loads(txt)
  52 + return_val.append(data)
  53 +
  54 + while (self.isNext(data) != False):
  55 + nextUrl = self.isNext(data)
  56 + txt = requests.get(nextUrl).text
  57 + data = json.loads(txt)
  58 + return_val.append(data)
  59 +
  60 + return return_val
  61 +
  62 +
  63 + def getContextsFeedAndTimestemp(self,ts):
  64 +
  65 + time_now = int(time.time())
  66 +
  67 + return_val = []
  68 + for list in self.orderlist[0:1]:
  69 + time.sleep(1)
  70 + url = 'https://graph.facebook.com/v2.5/%d/feed?'%list
  71 + txt = requests.get(url + self.token).text
  72 + data = json.loads(txt)
  73 + return_val.append(data)
  74 + #print data
  75 +
  76 + while (self.isNext(data) != False):
  77 + nextUrl = self.isNext(data)
  78 + feed_ts = int(nextUrl.split("until=")[1].split("&")[0])
  79 + if (time_now - ts) > feed_ts :
  80 + break
  81 + txt = requests.get(nextUrl).text
  82 + data = json.loads(txt)
  83 + return_val.append(data)
  84 + #print data
  85 +
  86 + return return_val
  87 +
  88 + def isNext(self,data):
  89 +
  90 + try:
  91 + return data['paging']['next']
  92 + except:
  93 + return False
  94 +
  95 +
  96 +
insight/context.pyc View file @ fa7135c

No preview for this file type

insight/insight.py View file @ fa7135c
... ... @@ -0,0 +1,38 @@
  1 +#!/usr/bin/env python
  2 +# -*- coding: utf-8 -*-
  3 +import requests
  4 +import json
  5 +
  6 +class Insight() :
  7 +
  8 + token = ""
  9 + type = ""
  10 + data = {}
  11 +
  12 + def __init__(self,token):
  13 + self.token = token
  14 + print "Insight"
  15 +
  16 + def setContentInsight(self,content_id):
  17 +
  18 + url ='https://graph.facebook.com/v2.5/%s?fields=type,insights{values}'%content_id
  19 + txt = requests.get(url + self.token).text
  20 + self.data = json.loads(txt)
  21 + self.setContentType(self.data)
  22 +
  23 + def getContentInsight(self):
  24 + return self.data['insights']['data']
  25 +
  26 + def setContentType(self, data):
  27 + self.type = data['type']
  28 + print self.type
  29 +
  30 + def getContentType(self, data):
  31 + return self.type
  32 +
  33 +
  34 +
  35 +
  36 +
  37 +
  38 +
insight/insight.pyc View file @ fa7135c

No preview for this file type

insight/page.py View file @ fa7135c
... ... @@ -0,0 +1,18 @@
  1 +#!/usr/bin/env python
  2 +# -*- coding: utf-8 -*-
  3 +class Page() :
  4 +
  5 + Contents_list = []
  6 +
  7 + def __init__(self, list):
  8 + self.setContentsList(list)
  9 +
  10 + def setContentsList(self, list):
  11 + for i in list:
  12 + print i
  13 + for j in i['data']:
  14 + self.Contents_list.append(j)
  15 +
  16 + def getContentsList(self):
  17 +
  18 + return self.Contents_list
0 19 \ No newline at end of file
insight/page.pyc View file @ fa7135c

No preview for this file type

insight/token.py View file @ fa7135c
... ... @@ -0,0 +1,24 @@
  1 +#!/usr/bin/env python
  2 +# -*- coding: utf-8 -*-
  3 +class Token() :
  4 + prefix = "&access_token="
  5 + token = ""
  6 + token_sub = ""
  7 + def __init__(self,input):
  8 + self.setToken(input)
  9 +
  10 + def setToken(self,input):
  11 + self.token = input
  12 +
  13 + def getToken(self):
  14 + return self.prefix + self.token
  15 +
  16 + def setTokens(self):
  17 + pass
  18 +
  19 + def autoSetToken(self):
  20 + pass
  21 +
  22 + def printAll(self):
  23 + print self.token
  24 + print self.token_sub
0 25 \ No newline at end of file
insight/token.pyc View file @ fa7135c

No preview for this file type

... ... @@ -0,0 +1,33 @@
  1 +#!/usr/bin/env python
  2 +# -*- coding: utf-8 -*-
  3 +
  4 +from insight.context import Context
  5 +from insight.token import Token
  6 +from insight.page import Page
  7 +from insight.insight import Insight
  8 +import time
  9 +
  10 +
  11 +if __name__=='__main__':
  12 +
  13 + main_token = "CAAUTLd5JgaoBABnBUUgOjgaUkuviOZCC1otVIJYwYapCRTZBU8ZAbTOd1uo1SBiqHr1eBhVdzoYDoBjPzqO0ImpxGZAXtlXeVtp4r2muUDt3O53NLYqFgrJqKAowcU7fWMsmMTZAAtKT8MXeF4Lb0rHQ2I1gHmbr6nlJWBHzk6dsNPmYHguMp"
  14 +
  15 + token = Token(main_token)
  16 +
  17 + contexts = Context(token.getToken())
  18 + contexts_list = contexts.getContextsFeedAndTimestemp(3600 * 24 * 10)
  19 +
  20 + page = Page(contexts_list)
  21 + contents_list = page.getContentsList()
  22 +
  23 + for content in contents_list:
  24 + print content['id']
  25 + print content['created_time'].replace('T'," ").replace('+0000',"")
  26 + print content['message'].replace('\n',"").replace('\r',"").replace('\'',"")
  27 +
  28 + insight = Insight(token.getToken())
  29 + insight.setContentInsight(content['id'])
  30 +
  31 + for i in insight.getContentInsight():
  32 + print i['id'] , i['values']
  33 +